K6BuilderExtensions Methods

ClassMethods3 members
Provides extension methods for adding Grafana k6 resources to the application model.
AddK6(IDistributedApplicationBuilder, string, bool, int?)Section titled AddK6(IDistributedApplicationBuilder, string, bool, int?)extensionIResourceBuilder<K6Resource>
Adds a Grafana k6 container resource to the application model. The default image is and the tag is .
public static class K6BuilderExtensions
{
public static IResourceBuilder<K6Resource> AddK6(
this IDistributedApplicationBuilder builder,
string name,
bool enableBrowserExtensions = false,
int? port = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
enableBrowserExtensionsbooloptionalEnables browser automation and end-to-end web testing to k6. https://grafana.com/docs/k6/latest/using-k6-browser/
portint?optionalThe host port to bind the underlying container to.
IResourceBuilder<K6Resource>A reference to the ApplicationModel.IResourceBuilder`1.
Add an Grafana k6 container to the application model and reference it in a .NET project.
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.Api>("api")
var k6 = builder.AddK6("k6");
.WithReference(api);
builder.Build().Run();
WithK6OtlpEnvironment(IResourceBuilder<K6Resource>)Section titled WithK6OtlpEnvironment(IResourceBuilder<K6Resource>)extensionIResourceBuilder<K6Resource>
Set K6 environment variables from the existing OTEL environment set for this resource. See https://grafana.com/docs/k6/latest/results-output/real-time/opentelemetry/#configuration.
public static class K6BuilderExtensions
{
public static IResourceBuilder<K6Resource> WithK6OtlpEnvironment(
this IResourceBuilder<K6Resource> builder)
{
// ...
}
}
builderIResourceBuilder<K6Resource>The resource builder.
IResourceBuilder<K6Resource>The ApplicationModel.IResourceBuilder`1.
WithScript(IResourceBuilder<K6Resource>, string, int?, string?, K6SummaryMode?)Section titled WithScript(IResourceBuilder<K6Resource>, string, int?, string?, K6SummaryMode?)extensionIResourceBuilder<K6Resource>
Runs a k6 JS script when starting the Grafana k6 container resource.
public static class K6BuilderExtensions
{
public static IResourceBuilder<K6Resource> WithScript(
this IResourceBuilder<K6Resource> builder,
string scriptPath,
int? virtualUsers = null,
string? duration = null,
K6SummaryMode? summaryMode = null)
{
// ...
}
}
builderIResourceBuilder<K6Resource>The resource builder.
scriptPathstringThe path to the JS script to run.
virtualUsersint?optionalThe number of virtual users for the test..
durationstring?optionalThe duration of the test, e.g. 30s.
summaryModeK6SummaryMode?optionalThe summary mode of the test execution.
IResourceBuilder<K6Resource>The ApplicationModel.IResourceBuilder`1.
--vus and --duration are the k6 CLI shorthand for a single constant-VU scenario and take precedence over the script's options.scenarios. Leave them null when the script defines its own scenarios or executors. Add a Grafana k6 container to the application model and reference it in a .NET project. Additionally, in this example a script runs when the container starts.
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.Api>("api");
var k6 = builder.AddK6("k6")
.WithBindMount("scripts", "/scripts", true)
.WithScript("/scripts/main.js")
.WithReference(api)
.WaitFor(api);
builder.Build().Run();