Skip to content
DocsTry Aspire
DocsTry

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)Section titled WithScript(IResourceBuilder<K6Resource>, string, int, string)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 = 10,
string duration = "30s")
{
// ...
}
}
builderIResourceBuilder<K6Resource>The resource builder.
scriptPathstringThe path to the JS script to run.
virtualUsersintoptionalThe number of virtual users for the test. Defaults to `10`.
durationstringoptionalThe duration of the test. Defaults to `30s`.
IResourceBuilder<K6Resource>The ApplicationModel.IResourceBuilder`1.
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();