-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor new
command
#4153
Open
dgzlopes
wants to merge
10
commits into
grafana:master
Choose a base branch
from
dgzlopes:refactor-new-command
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
Refactor new
command
#4153
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d254f00
Refactor new command and templates
dgzlopes e7e95f1
Move Cloud to another command
dgzlopes c3f84ba
Fix tests
dgzlopes fea3e7f
Small changes to the templates
dgzlopes b1af40f
Move everything to one command based on feedback
dgzlopes b3e99b8
Fix help text
dgzlopes 6423d09
Simplify cloud logic
dgzlopes 1d8d321
Make linter happy
dgzlopes 5cf5916
Fix package name and description
dgzlopes beda4b1
Use Authorization header instead of User-ID
dgzlopes 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
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,53 @@ | ||
import { browser } from "k6/browser"; | ||
import http from "k6/http"; | ||
import { sleep, check } from 'k6'; | ||
|
||
const BASE_URL = __ENV.BASE_URL || "https://quickpizza.grafana.com"; | ||
|
||
export const options = { | ||
scenarios: { | ||
ui: { | ||
executor: "shared-iterations", | ||
options: { | ||
browser: { | ||
type: "chromium", | ||
}, | ||
}, | ||
}, | ||
},{{ if .ProjectID }} | ||
cloud: { | ||
projectID: {{ .ProjectID }}, | ||
name: "{{ .ScriptName }}", | ||
},{{ end }} | ||
}; | ||
|
||
export function setup() { | ||
let res = http.get(BASE_URL); | ||
if (res.status !== 200) { | ||
throw new Error( | ||
`Got unexpected status code ${res.status} when trying to setup. Exiting.` | ||
); | ||
} | ||
} | ||
|
||
export default async function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really a nitpick, and a personal preference, but I would find the code more readable with actual newlines 😄 |
||
let checkData; | ||
const page = await browser.newPage(); | ||
try { | ||
await page.goto(BASE_URL); | ||
checkData = await page.locator("h1").textContent(); | ||
check(page, { | ||
header: checkData === "Looking to break out of your pizza routine?", | ||
}); | ||
await page.locator('//button[. = "Pizza, Please!"]').click(); | ||
await page.waitForTimeout(500); | ||
await page.screenshot({ path: "screenshot.png" }); | ||
checkData = await page.locator("div#recommendations").textContent(); | ||
check(page, { | ||
recommendation: checkData !== "", | ||
}); | ||
} finally { | ||
await page.close(); | ||
} | ||
sleep(1); | ||
} |
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,17 @@ | ||
import http from 'k6/http'; | ||
import { sleep, check } from 'k6'; | ||
|
||
export const options = { | ||
vus: 10, | ||
duration: '30s',{{ if .ProjectID }} | ||
cloud: { | ||
projectID: {{ .ProjectID }}, | ||
name: "{{ .ScriptName }}", | ||
},{{ end }} | ||
}; | ||
|
||
export default function() { | ||
let res = http.get('https://quickpizza.grafana.com'); | ||
check(res, { "status is 200": (res) => res.status === 200 }); | ||
sleep(1); | ||
} |
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 @@ | ||
import http from "k6/http"; | ||
import { check, sleep } from "k6"; | ||
|
||
const BASE_URL = __ENV.BASE_URL || 'https://quickpizza.grafana.com'; | ||
|
||
export const options = { | ||
vus: 10, | ||
stages: [ | ||
{ duration: "10s", target: 5 }, | ||
{ duration: "20s", target: 10 }, | ||
{ duration: "1s", target: 0 }, | ||
], | ||
thresholds: { | ||
http_req_failed: ["rate<0.01"], | ||
http_req_duration: ["p(95)<500", "p(99)<1000"], | ||
},{{ if .ProjectID }} | ||
cloud: { | ||
projectID: {{ .ProjectID }}, | ||
name: "{{ .ScriptName }}", | ||
},{{ end }} | ||
}; | ||
|
||
export function setup() { | ||
let res = http.get(BASE_URL); | ||
if (res.status !== 200) { | ||
throw new Error( | ||
`Got unexpected status code ${res.status} when trying to setup. Exiting.` | ||
); | ||
} | ||
} | ||
|
||
export default function() { | ||
let restrictions = { | ||
maxCaloriesPerSlice: 500, | ||
mustBeVegetarian: false, | ||
excludedIngredients: ["pepperoni"], | ||
excludedTools: ["knife"], | ||
maxNumberOfToppings: 6, | ||
minNumberOfToppings: 2 | ||
}; | ||
|
||
let res = http.post(BASE_URL + "/api/pizza", JSON.stringify(restrictions), { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'token abcdef0123456789', | ||
}, | ||
}); | ||
|
||
check(res, { "status is 200": (res) => res.status === 200 }); | ||
console.log(res.json().pizza.name + " (" + res.json().pizza.ingredients.length + " ingredients)"); | ||
sleep(1); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
I've noticed that both
k6 new
andk6 new --template minimal
work, and it looks like it generates the same script file. As a result I would keep documenting an example of the default behavior ofk6 new
here 🙇🏻Also as we're at it, it wasn't immediatly obvious to me that the
k6 new
command supports a file argument (not flag) from the examples, we might want to also add one demonstrating that?