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 initial xk6 documentation #346

Merged
merged 14 commits into from
Oct 19, 2021
Merged

Add initial xk6 documentation #346

merged 14 commits into from
Oct 19, 2021

Conversation

imiric
Copy link
Contributor

@imiric imiric commented Jun 30, 2021

Closes #169

Comment on lines 169 to 178
[`context.Context`](https://golang.org/pkg/context/#Context) instance as the first argument.
This context is used throughout the k6 codebase and contains embedded objects
which can be extracted to access the
[`goja.Runtime`](https://pkg.go.dev/github.com/dop251/goja#Runtime) for a
particular VU, and to get more information about the test in progress.
Take a look at
[`common.GetRuntime()`](https://pkg.go.dev/go.k6.io/[email protected]/js/common#GetRuntime),
[`lib.GetState()`](https://pkg.go.dev/go.k6.io/[email protected]/lib#GetState) and
[`lib.GetExecutionState()`](https://pkg.go.dev/go.k6.io/[email protected]/lib#GetExecutionState).
Copy link
Contributor

Choose a reason for hiding this comment

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

This might drastically change depending on the changes around grafana/k6#1802, so maybe we should first decide on whether we will do any of the changes proposed there before we document stuff we might break

Copy link
Contributor Author

@imiric imiric Jun 30, 2021

Choose a reason for hiding this comment

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

Good point, but that will change in v0.34.0, right? Since we have versioned docs now, I think it's fine to mention the current API here.

EDIT: Actually, only JS API docs are versioned, so guess not 😞

@github-actions
Copy link
Contributor

There's a version of the docs published here:

https://mdr-ci.staging.k6.io/docs/refs/pull/346/merge

It will be deleted automatically in 30 days.

---

Traditionally, extending k6 with custom functionality that isn't available in the
Copy link
Collaborator

Choose a reason for hiding this comment

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

In Docs, I'd remove the whole historical intro.

Additionally, I would add a label about version support like in Scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hhmm I think explaining the issues extensions were meant to solve serves as a good introduction for why someone might want to use them. Starting from "What are k6 extensions?" would be too abrupt IMO. Unless you have another suggestion for the intro :)

And sure, I'll add a more prominent version support notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the version support notice in a89ceda.

Let me know about the intro.

Copy link
Collaborator

Choose a reason for hiding this comment

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


k6 extensions are standalone Go projects that call k6 APIs but are otherwise
unrestricted in their functionality. This provides the freedom for extension authors
Copy link
Collaborator

@ppcano ppcano Jul 1, 2021

Choose a reason for hiding this comment

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

In the beginning, we should focus on describing the benefits of this feature.

Having the ability to experiment with extensions that can become part of the feature is a "secondary" benefit, at least for the end user, imho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly a definition paragraph, but what other benefits would you mention?

The historical introduction explains the issues extensions are meant to solve for end users, so I'm not sure what else to mention here.

Copy link
Collaborator

@ppcano ppcano Jul 28, 2021

Choose a reason for hiding this comment

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

Also about https://github.com/grafana/k6-docs/pull/346/files#r661994675

My view here is that the intro and the what is k6 extension and what is xk6 sections are a little verbose. For the Intro sections, I rather going more direct to the point in Docs and extend the historical in the blog post.

I like Extension Types section, but perhaps the Getting Started section could be better connected with the intro.

The article is very good. If you want, I can give it a try in the future for a new proposal of the intro.

that output implementations can use which handles bufferring and periodic
flushing in a thread-safe way.
For usage examples see the [`statsd` output](https://github.com/k6io/k6/blob/v0.33.0/output/statsd/output.go#L55).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add an example of an extension instead of the k6 codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hhmm we already have a lot of external examples and I thought it would be good to link to an internal module for once, to showcase that extensions and internal modules are near identical in implementation.

Besides, I'm not sure there are any extensions that actually use this yet, since it hasn't been documented ;)


A few things to keep in mind when writing a new extension:
<!-- TODO: Better structure this list? -->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree. It is a bit hard to follow.

I wonder if. it could be good to show snippets of relevant extension code to distinguish between the various sections and make the whole section more pleasant to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, could be... In #169 we kind of agreed to not show any Go code here, but we could split this section into "Writing a new JS extension" (linking to the existing article) and "Writing a new Output extension", and do a small walkthrough with some snippets of code instead of a complete extension like in the article.

I'll think about it, and more opinions are welcome. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppcano Take a look at the latest changes. It kind of breaks the no-code rule, but I really don't think we can document writing an extension without showing code... :)

@ppcano
Copy link
Collaborator

ppcano commented Jul 1, 2021

It's a good start @imiric. I have added a few comments about the first impressions, take the feedback as suggestions or to think about.

@simskij
Copy link
Contributor

simskij commented Jul 20, 2021

What's the status here, @imiric and @ppcano? Is this abandoned, finished, or still ongoing?

@imiric
Copy link
Contributor Author

imiric commented Jul 20, 2021

@simskij It's in progress and awaiting more feedback. I actually picked it back up today to address this and this, but new comments are welcome.

imiric pushed a commit that referenced this pull request Jul 23, 2021
Maybe resolves #346 (comment) ?
Still needs a bit of work.
@imiric imiric requested review from mstoykov and ppcano July 23, 2021 15:19
@imiric
Copy link
Contributor Author

imiric commented Jul 23, 2021

I expanded more on the writing extension part, but it will need fact checking from @na-- and @mstoykov 😅

It's still a bit WIP and there are some TODOs and ellipsis that should be addressed, but there shouldn't be much left after that.

imiric pushed a commit that referenced this pull request Jul 27, 2021
@imiric
Copy link
Contributor Author

imiric commented Jul 27, 2021

This is ready for review again. @na-- @mstoykov @ppcano 🙏

@simskij I mentioned the supported modes of execution in 56b3702, but can you clarify what you meant by "considerations and drawbacks"? I'm not sure what else to mention besides whether custom k6 binaries are supported or not. Suggestions welcome :)

is on our roadmap. However, it is possible to run a binary built with xk6 and send
metrics produced by extension code to the Cloud using the
[`cloud` output](https://k6.io/docs/results-visualization/cloud/).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we add some kind of outro here, relevant links, etc.?

imiric pushed a commit that referenced this pull request Sep 29, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
This briefly mentions common.Bind() and shows a more advanced module
example using the new IsModuleV2 approach.

Should resolve #346 (comment)
imiric pushed a commit that referenced this pull request Oct 8, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
imiric pushed a commit that referenced this pull request Oct 8, 2021
@ppcano
Copy link
Collaborator

ppcano commented Oct 14, 2021

@na-- @mstoykov Any blocker here? I suggest merging it and iterating it next. We want to migrate this content to the Extensions section and will require some minor changes later.

@codebien
Copy link
Contributor

@imiric Does xk6 support the vendor folder? If not, should we mention something about it?

@imiric
Copy link
Contributor Author

imiric commented Oct 15, 2021

@codebien It doesn't and good idea. I mentioned it in db1c351.

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

LGTM, we'd just need to update some things when v0.35.0 is released. @ppcano, feel free to merge this :shipit:

@ppcano ppcano merged commit 2fb24f4 into main Oct 19, 2021
@na-- na-- deleted the docs/xk6 branch October 19, 2021 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add xk6 documentation
6 participants