-
Notifications
You must be signed in to change notification settings - Fork 114
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
populist
wants to merge
6
commits into
pantheon-systems:master
Choose a base branch
from
populist:loadimpact-performance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29af39e
Initial Commit of Load Impact Integration
populist f3b4445
Adding Pantheon Environmental Conditional Logic
populist f35dded
Providing an URL for the Results
populist 5442bcc
Updating the Results URL for Load Impact
populist 5a63dab
Updating the Results URL for Load Impact: Part Two
populist 7a31766
Updating Loadimpact Test to Provide a Public URL Using V3 of their API
populist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
$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"; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 viaterminus 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.
There was a problem hiding this comment.
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). Withterminus 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.