From 29af39e390da32ecf9daebd14188cfc1747debd5 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 20 Apr 2016 13:18:35 -0700 Subject: [PATCH 1/6] Initial Commit of Load Impact Integration --- example.pantheon.yml | 5 ++++- loadimpact/README.md | 37 +++++++++++++++++++++++++++++++ loadimpact/loadimpact.php | 46 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 loadimpact/README.md create mode 100644 loadimpact/loadimpact.php diff --git a/example.pantheon.yml b/example.pantheon.yml index 6430992..ec980c0 100644 --- a/example.pantheon.yml +++ b/example.pantheon.yml @@ -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 @@ -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 diff --git a/loadimpact/README.md b/loadimpact/README.md new file mode 100644 index 0000000..e4c0285 --- /dev/null +++ b/loadimpact/README.md @@ -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 +``` diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php new file mode 100644 index 0000000..1238297 --- /dev/null +++ b/loadimpact/loadimpact.php @@ -0,0 +1,46 @@ + '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)) { + echo 'You have kicked off test #' . $curl_response->id . "\n"; + $curl_two = curl_init(); + $curl_two_options = array( + CURLOPT_URL => 'https://api.loadimpact.com/v2/tests/' . $test_id, + CURLOPT_USERPWD => $api_key . ':', + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, + CURLOPT_RETURNTRANSFER => 1, + ); + curl_setopt_array($curl_two, $curl_two_options); + $curl_two_response = json_decode(curl_exec($curl_two)); + curl_close($curl_two); + echo "Check out the result here: " . $curl_two_response->public_url . "\n"; + } + else { + echo 'There has been an error: ' . ucwords($curl_response->message) . "\n"; + } \ No newline at end of file From f3b44454789ade0601105350d1ce8a39bbe38324 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 20 Apr 2016 13:52:00 -0700 Subject: [PATCH 2/6] Adding Pantheon Environmental Conditional Logic --- loadimpact/loadimpact.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php index 1238297..2361027 100644 --- a/loadimpact/loadimpact.php +++ b/loadimpact/loadimpact.php @@ -14,6 +14,7 @@ // 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( @@ -43,4 +44,5 @@ } else { echo 'There has been an error: ' . ucwords($curl_response->message) . "\n"; - } \ No newline at end of file + } +} From f35dded76c561c6a22624dff2f837740eae7b676 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 20 Apr 2016 15:20:18 -0700 Subject: [PATCH 3/6] Providing an URL for the Results --- loadimpact/loadimpact.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php index 2361027..7b46820 100644 --- a/loadimpact/loadimpact.php +++ b/loadimpact/loadimpact.php @@ -27,22 +27,12 @@ curl_setopt_array($curl, $curl_options); $curl_response = json_decode(curl_exec($curl)); curl_close($curl); - + if (isset($curl_response->id)) { echo 'You have kicked off test #' . $curl_response->id . "\n"; - $curl_two = curl_init(); - $curl_two_options = array( - CURLOPT_URL => 'https://api.loadimpact.com/v2/tests/' . $test_id, - CURLOPT_USERPWD => $api_key . ':', - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_RETURNTRANSFER => 1, - ); - curl_setopt_array($curl_two, $curl_two_options); - $curl_two_response = json_decode(curl_exec($curl_two)); - curl_close($curl_two); - echo "Check out the result here: " . $curl_two_response->public_url . "\n"; + echo 'Check our your results here: https://app.loadimpact.com/tests/3366431' . "\n"; } else { echo 'There has been an error: ' . ucwords($curl_response->message) . "\n"; - } + } } From 5442bccc87691e5ddc8b6e2cdde4f59ec033c844 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 20 Apr 2016 15:26:59 -0700 Subject: [PATCH 4/6] Updating the Results URL for Load Impact --- loadimpact/loadimpact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php index 7b46820..280a432 100644 --- a/loadimpact/loadimpact.php +++ b/loadimpact/loadimpact.php @@ -30,7 +30,7 @@ if (isset($curl_response->id)) { echo 'You have kicked off test #' . $curl_response->id . "\n"; - echo 'Check our your results here: https://app.loadimpact.com/tests/3366431' . "\n"; + echo 'Check our your results here: https://app.loadimpact.com/tests/' . $curl_response->id . "\n"; } else { echo 'There has been an error: ' . ucwords($curl_response->message) . "\n"; From 5a63dab28106e0ded24192d356d169e1e084af27 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 20 Apr 2016 15:41:56 -0700 Subject: [PATCH 5/6] Updating the Results URL for Load Impact: Part Two --- loadimpact/loadimpact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php index 280a432..9dd8b59 100644 --- a/loadimpact/loadimpact.php +++ b/loadimpact/loadimpact.php @@ -30,7 +30,7 @@ if (isset($curl_response->id)) { echo 'You have kicked off test #' . $curl_response->id . "\n"; - echo 'Check our your results here: https://app.loadimpact.com/tests/' . $curl_response->id . "\n"; + echo 'Check our your results here: https://app.loadimpact.com/tests/' . $test_id . "\n"; } else { echo 'There has been an error: ' . ucwords($curl_response->message) . "\n"; From 7a31766ec210b7583457ea03c787c3675a41bbc2 Mon Sep 17 00:00:00 2001 From: Matt Cheney Date: Wed, 25 May 2016 11:20:31 -0700 Subject: [PATCH 6/6] Updating Loadimpact Test to Provide a Public URL Using V3 of their API --- loadimpact/loadimpact.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/loadimpact/loadimpact.php b/loadimpact/loadimpact.php index 9dd8b59..b05570a 100644 --- a/loadimpact/loadimpact.php +++ b/loadimpact/loadimpact.php @@ -8,6 +8,8 @@ // the private area of the files directory as documented // at https://github.com/pantheon-systems/quicksilver-examples. $api_key = 'add-api-key-here'; +$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'; @@ -29,10 +31,22 @@ curl_close($curl); if (isset($curl_response->id)) { - echo 'You have kicked off test #' . $curl_response->id . "\n"; - echo 'Check our your results here: https://app.loadimpact.com/tests/' . $test_id . "\n"; + // 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"; - } + } }