Skip to content

support community extensions #4922

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

Conversation

pablochacin
Copy link
Contributor

@pablochacin pablochacin commented Jul 11, 2025

What?

Allow users to opt for using community extensions (defined in the oss catalog) with the K6_ENABLE_COMMUNITY_EXTENSIONS environment variable. If not enabled, the default cloud catalog will be used.

Why?

By default, binary provisioning only supports extensions defined in the cloud catalog.

We want to offer users the possibility of opting in for the complete catalog of extensions when running tests locally.

Note: if the user enables the community extensions and sends a test to the cloud using cloud run, the test will fail at execution time, as the cloud runners do not support these extensions.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (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.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Closes #4884

@pablochacin pablochacin force-pushed the binary-provisioning/support-community-extensions branch 3 times, most recently from 5456052 to 6eb7e09 Compare July 17, 2025 19:06
@pablochacin pablochacin force-pushed the binary-provisioning/support-community-extensions branch from 6eb7e09 to 18cb212 Compare July 22, 2025 13:14
@pablochacin pablochacin marked this pull request as ready for review July 22, 2025 16:17
@pablochacin pablochacin requested a review from a team as a code owner July 22, 2025 16:17
@pablochacin pablochacin requested review from ankur22 and AgnesToulet and removed request for a team July 22, 2025 16:17
@codebien codebien self-requested a review July 25, 2025 08:34
@pablochacin pablochacin added this to the v1.2.0 milestone Jul 25, 2025
@pablochacin pablochacin force-pushed the binary-provisioning/enable-to-all-users branch from 00af9c1 to 337ddaf Compare July 25, 2025 15:33
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin force-pushed the binary-provisioning/support-community-extensions branch from 5a17ece to 8afaff8 Compare July 25, 2025 15:41
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

@pablochacin unit tests are missing here

Comment on lines 30 to 35
// DefaultBuildServiceURL defines the URL to the default (grafana hosted) build service
DefaultBuildServiceURL = "https://ingest.k6.io/builder/api/v1"
// CloudExtensionsCatalog defines the extensions catalog for cloud supported extensions
CloudExtensionsCatalog = "cloud"
// CommunityExtensionsCatalog defines the extensions catalog for community extensions
CommunityExtensionsCatalog = "oss"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it required to have them exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are referenced in internal/cmd/launcher.go

Copy link
Contributor

Choose a reason for hiding this comment

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

But they aren't used here, no?

Do we need to define and export them here? Just out of curiosity.

@pablochacin
Copy link
Contributor Author

@codebien

@pablochacin unit tests are missing here

What kind of tests are you thinking? The main impact of this changes are internal to the provision function (selecting the catalog to use), and this change is only visible to the k6provider library. I'm open to suggestions.

@codebien
Copy link
Contributor

codebien commented Jul 29, 2025

What kind of tests are you thinking?

We should assert the URL generated if the community extensions are enabled. So the new logic added.

Comment on lines 220 to 230
buildSrv := p.gs.Flags.BuildServiceURL
buildSrvURL, err := url.Parse(buildSrv)
if err != nil {
return nil, fmt.Errorf("invalid URL to binary provisioning build service: %w", err)
}

catalog := state.CloudExtensionsCatalog
if p.gs.Flags.EnableCommunityExtensions {
catalog = state.CommunityExtensionsCatalog
}
buildSrv = buildSrvURL.JoinPath(catalog).String()
Copy link
Contributor

Choose a reason for hiding this comment

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

We might consider moving this logic into a dedicated function that accepts as input a flagset and it returns the URL or an error.

In this way, it's easier to test.

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

LGTM, just one missing improvement

buildSrvURL: state.DefaultBuildServiceURL,
enableCommunityExtensions: false,
expectErr: false,
expected: fmt.Sprintf("%s/%s", state.DefaultBuildServiceURL, state.CloudExtensionsCatalog),
Copy link
Contributor

@codebien codebien Jul 29, 2025

Choose a reason for hiding this comment

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

Let's use a static string here. For example, if we wrote a bad value in state.CloudExtensionsCatalog then we wouldn't be able to catch it. Because the assertion is depending on the past value.

Suggested change
expected: fmt.Sprintf("%s/%s", state.DefaultBuildServiceURL, state.CloudExtensionsCatalog),
expected: "http://my-fake-exected-url/path-of-the-community,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm generally in favor of the practice @codebien is suggesting here, so if anytime we change that value, it will be more explicit, and likely easier to catch potential breaking changes, etc 👍🏻

Comment on lines 400 to 410
if !tc.expectErr && err != nil {
t.Fatalf("unexpected error %v", err)
}

if tc.expectErr && err == nil {
t.Fatalf("expected error got none")
}

if !tc.expectErr && buildSrvURL != tc.expected {
t.Fatalf("expected buildSrvURL %q got %q", tc.expected, buildSrvURL)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit; I think we generally use assert or require from testify 🤔

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
buildSrvURL string
enableCommunityExtensions bool
expectErr bool
expected string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expected string
expectURL string

To be consistent with the error field

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
@pablochacin pablochacin merged commit 76dd822 into binary-provisioning/enable-to-all-users Jul 30, 2025
37 of 39 checks passed
@pablochacin pablochacin deleted the binary-provisioning/support-community-extensions branch July 30, 2025 08:24
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.

4 participants