-
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
Local templates support in k6 new
#4618
base: master
Are you sure you want to change the base?
Conversation
eda5a34
to
b3bf79c
Compare
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.
Nice feature! LGTM 👍
I have some suggestions.
The --template
option specifies the template type for the output. The current implementation of the --template
option also reads the file name. Could this be confusing for users? What do you think about adding a --template-file
option to explicitly specify the file name? Doing so can also simplify the implementation of this 🤔
$ ... --template=file --template-file=templateFile
# Or, just:
$ ... --template-file=templateFile
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.
Happy to see this feature land 🚀 👏🏻 Great job getting it through! 🙇🏻
No specific comments on the implementation, but I do share some of @inanc's sentiment on the UX. Passing a file directly to the option feels somewhat out of place, as, like he mentioned the existing values for the option are essentially "modes".
A pattern we currently use in k6 is to parse the value as a =
separated key value pair: k6 new --template file=template.js
, maybe that would make sense in this case? Otherwise, we could indeed go for --template-file
, but the concern I have there is that we might want to support more than files down the road (folders?) in which case the "file" terminology might turn out confusing.
Two other small things I've noticed while playing around with it:
- In its current state, it looks like the ability to pass a template file is undocumented on the flag description:
- The error message when providing a path to a file that does not exist looks somewhat incorrect "invalid template type", whereas it's really that the file was not found. Further, it could be more explicit? Something along the lines of "it appears you are trying to initialize a k6 project using a template file, but the template file you provided was not found".
This makes sense to be consistent with the rest of the
We could call it |
ce7349b
to
1d2338d
Compare
@oleiade, good catch on unclear error and missing changes to the help message. Both should be fixed now. @inancgumus, introducing a separate command-line flag for template files would allow users to do something like this |
Thanks for the clarification, @andrewslotin 🙇 I now see that it was discussed and decided before. I wasn't aware of the conversation. However, this suggestion avoids introducing a new flag and remains consistent with the rest of the |
@inancgumus, what's the benefit of requiring users to type |
@andrewslotin Totally get your point—tab completion and drag-and-drop are super convenient. Nice points. My main concern is that string-based checks can be fragile; for instance, |
@inancgumus, that would simplify the implementation for sure. Can you write down the full proposal you have in mind? Let's say we aim to support a small number of built-in templates, local files and remote ones. How would the arguments to |
Given the constraints we discussed:
So, I propose the following approaches. Approach 1# Built-in templates
k6 new --template builtin:minimal # Explicit directive
k6 new --template builtin:protocol
k6 new --template builtin:browser
# HTTP etc.
k6 new --template https://foo.com
# Files and directories
k6 new --template ~/foo How it works:
Downsides
Using the Approach 2: if multiple flags were allowed# Built-in templates
k6 new --builtin-template minimal # Explicit directive
k6 new --builtin-template protocol
k6 new --builtin-template browser
# HTTP etc.
k6 new --remote-template foo.com # Explicit directive
# Files and directories
k6 new --local-template ~/foo # Explicit directive For unexpected cases, we can clearly print out errors because everything is explicit: k6 new --remote-template foo.com --local-template ~/foo
ERROR: Ambiguous template target. Use one of ... at the same time. This would eliminate ambiguity, but it conflicts with the "one template flag" constraint. Approach 3: A slightly less explicit and minimal approachk6 new --template minimal
k6 new --external-template http://foo.com
k6 new --external-template ~/foo It's still being arguably more explicit than a single |
3fd4607
to
ab7f175
Compare
@inancgumus, I believe we're reconsidering the previously discussed and agreed design now. Instead, I'd suggest that we focus on the implementation. I see your point that requiring users to prepend the file name with The point about edge cases like using |
ab7f175
to
6ec040e
Compare
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.
🚀 👏🏻 🍾 Looks good to me!
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.
🤝 🚀
Co-authored-by: İnanç Gümüş <[email protected]>
2d95197
to
4ef4be4
Compare
4ef4be4
to
6f99b50
Compare
What?
This PR adds support for local templates and addresses a bug when an empty script file is created even if the template name is invalid.
Why?
The current script templating feature is limited to three pre-defined templates that are bundled with
k6
: minimal, protocol and browser. While this already reduces the amount of boilerplate code to write when starting a new project, being able to use custom user-defined templates would help to simplify the first steps even further, by allowing users to extract common parts, such as authentication, custom sets of options, into a template file that can be used to initialize tests.Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
k6 new
k6-docs#1889Related PR(s)/Issue(s)
Relevant issue #4154