Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Load Impact Automatic Performance Testing #75

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example.pantheon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ workflows:
description: post to slack after the database clones
script: private/scripts/slack_after_db_clone.php

# Code Deploys: Notify, Sanitize (if on test), post to new relic, update db, and notify completion
# Code Deploys: Notify, Sanitize (if on test), post to new relic, testd, update db, and notify completion
deploy:
before:
- type: webphp
Expand All @@ -49,6 +49,9 @@ workflows:
- type: webphp
description: do a visual regression test with Backtrac.io
script: private/scripts/backtrac_visualregression.php
- type: webphp
description: do a performance test with Load Impact
script: private/scripts/loadimpact.php
- type: webphp
description: post to slack after each deploy
script: private/scripts/slack_after_deploy.php
Expand Down
37 changes: 37 additions & 0 deletions loadimpact/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Performance Testing via Load Impact #

This example will show you how to integrate [Load Impact](https://loadimpact.com/)'s performance testing into your deployment workflow.

This will allow you to do a performance scan of your testing environment after your code deployments.

## Instructions ##

In order to get up and running, you first need to setup a Load Impact project:

1. Either login to your account or register for a new one at [https://loadimpact.com/](https://loadimpact.com/).
2. Generate an API Key on your Load Impact account page: [https://app.loadimpact.com/integrations/api-token](https://app.loadimpact.com/integrations/api-token).
3. Setup a Load Impact test for your site.

Then you need to add the relevant code to your Pantheon project:

1. Add the example `loadimpact.php` script to the 'private/scripts/' directory of your code repository.
2. Modify the `loadimpact.php` script to include your API key and your Project URL.
3. Add a Quicksilver operation to your `pantheon.yml` to fire the script after a deploy to test.
4. Test a deploy out!

Optionally, you may want to use the `terminus workflows watch` command to get immediate debugging feedback.

### Example `pantheon.yml` ###

Here's an example of what your `pantheon.yml` would look like if this were the only Quicksilver operation you wanted to use:

```yaml
api_version: 1

workflows:
deploy:
after:
- type: webphp
description: do a performance test with Load Impact
script: private/scripts/loadimpact.php
```
52 changes: 52 additions & 0 deletions loadimpact/loadimpact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

// An example of usign Pantheon's Quicksilver technology to do
// a performance test using Load Impact

// Provide the API Key provided by Load Impact
// For extra security, you can store this information in
// the private area of the files directory as documented
// at https://github.com/pantheon-systems/quicksilver-examples.
$api_key = 'add-api-key-here';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@populist Should this switch to using secrets.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had left the API key defined in the variable since I think it is simpler to get running and the API key is stored in a way that isn't web accessible.

Obviously using secrets.json is going to be even better and I added a documentation link to show people how to do this if they want.

Do you (or @greg-1-anderson or @joshkoenig) think we should standardize our examples using secrets.json?

Copy link
Member

@greg-1-anderson greg-1-anderson Apr 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of using secrets.json is that you can then install this example via terminus quicksilver install, and set your secrets via terminus secrets set key value, with no need to alter the code.

The code as written has the advantage of being short, and not requiring any duplicated functions to manage secrets. So, right now there is a fair bit of duplicate code in the Quicksilver examples regarding secrets. There is a discussion on that topic in #74.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should standardize on an abstraction layer. Part of my reasoning is for the security benefit. While some of our quicksilver examples involve keys that aren't terribly sensitive I think we should just stick with the best practice of "don't commit keys to any repo" so as limit confusion.

Just as important for me is clearing a path toward treating QS scripts as modules/plugins as opposed to custom code. Right now these scripts are examples meant to be edited by the implementor. There should not be an expectation (right now) that a Slack notification script in one Pantheon site is identical to a Slack notification script on another Pantheon site.

I anticipate that expectation will evolve. Our user base of Drupal and WordPress developers is accustomed to running commands like drush dl modulename and treating community code as not-to-be-edit (hacking core kills kittens and all that). With terminus quicksilver install examplename there is a road to treating QS code like modules to which configuration is passed.

Of course Quicksilver as a whole is still evolving. And maybe for the stage we are at now we should be actively fighting (possibly) premature abstraction. If we want Quicksilver users to think "this is code I need to read, understand and edit to my use case" then let's continue to include pieces like this that require editing the php file. If we want QS users to think "I install an example and it just works" then we need abstractions like key management.

$api_key_v3 = 'add-api-v3-key-here';


// Provide the Test ID for the performance test on Loadimpact.com
$test_id = 'add-test-id-here';

// If we are deploying to test, run a performance test on that environment
// The specifics of the test will be defined on Loadimpact.com
if (defined('PANTHEON_ENVIRONMENT') && (PANTHEON_ENVIRONMENT == 'test')) {
echo 'Starting a performance test on the test environment...' . "\n";
$curl = curl_init();
$curl_options = array(
CURLOPT_URL => 'https://api.loadimpact.com/v2/test-configs/' . $test_id . '/start',
CURLOPT_USERPWD => $api_key . ':',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
);
curl_setopt_array($curl, $curl_options);
$curl_response = json_decode(curl_exec($curl));
curl_close($curl);

if (isset($curl_response->id)) {
// Let's run a V3 Call to Get Public URL
$curl = curl_init();
$curl_options = array(
CURLOPT_URL => 'https://api.loadimpact.com/v3/test-runs/' . $curl_response->id . '/generate_public_url',
CURLOPT_USERPWD => $api_key_v3 . ':',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
);
curl_setopt_array($curl, $curl_options);
$curl_response = json_decode(curl_exec($curl));
curl_close($curl);

echo 'Test results: ' . $curl_response->test_run->public_url . "\n";
}
else {
echo 'There has been an error: ' . ucwords($curl_response->message) . "\n";
}
}