pub struct K6ScriptGenerator { /* private fields */ }Expand description
Generate k6 load test script
Implementations§
Source§impl K6ScriptGenerator
impl K6ScriptGenerator
Sourcepub fn new(config: K6Config, templates: Vec<RequestTemplate>) -> Self
pub fn new(config: K6Config, templates: Vec<RequestTemplate>) -> Self
Create a new k6 script generator.
The abort-on-error safety valve defaults to on at a 0.95 failure rate
(round 60). Use with_abort_valve to opt out
or retune it.
Sourcepub fn with_force_http1(self, force_http1: bool) -> Self
pub fn with_force_http1(self, force_http1: bool) -> Self
Round 63 (#79) — opt the generated script into the HTTP/1.1 comment
(GODEBUG=http2client=0). Also auto-detected when any template or
custom header is named Connection.
Sourcepub fn with_abort_valve(
self,
abort_on_error: bool,
abort_on_error_rate: f64,
) -> Self
pub fn with_abort_valve( self, abort_on_error: bool, abort_on_error_rate: f64, ) -> Self
Configure the k6 abort-on-error memory safety valve (round 62 / #79).
abort_on_error = false drops the abortOnFail threshold entirely so
the run executes its full duration regardless of error rate — required
for stress tests against a WAF/proxy that legitimately rejects most
requests. abort_on_error_rate tunes the failure rate (0.0-1.0) above
which a target aborts after the 60s grace period.
Sourcepub fn should_force_http1(&self) -> bool
pub fn should_force_http1(&self) -> bool
HTTP/2 forbids Connection. Keep the header (it IS the WAF case)
and force HTTP/1.1 instead.
Sourcepub fn sanitize_k6_metric_name(name: &str) -> String
pub fn sanitize_k6_metric_name(name: &str) -> String
Sanitize a name into a valid k6 metric-name base, capped at
K6_METRIC_NAME_BASE_MAX_LEN characters.
k6 rejects metric names longer than 128 chars, and our templates
append suffixes like _latency, _errors, _stepN_latency —
reserve room for the longest suffix and truncate the base name
when needed. Truncation appends an 8-hex-char hash of the original
name so distinct long names produce distinct metric names.
Examples:
- “short_name” -> “short_name”
- 200-char OperationId -> “
_<8-hex-hash>”
Sourcepub fn sanitize_js_identifier(name: &str) -> String
pub fn sanitize_js_identifier(name: &str) -> String
Sanitize a name to be a valid JavaScript identifier
Replaces invalid characters (dots, spaces, special chars) with underscores. Ensures the identifier starts with a letter or underscore (not a number).
Examples:
- “billing.subscriptions.v1” -> “billing_subscriptions_v1”
- “get user” -> “get_user”
- “123invalid” -> “_123invalid”
Sourcepub fn validate_script(script: &str) -> Vec<String>
pub fn validate_script(script: &str) -> Vec<String>
Validate the generated k6 script for common issues
Checks for:
- Invalid metric names (contains dots or special characters)
- Invalid JavaScript variable names
- Missing required k6 imports
Returns a list of validation errors, empty if all checks pass.
Auto Trait Implementations§
impl Freeze for K6ScriptGenerator
impl RefUnwindSafe for K6ScriptGenerator
impl Send for K6ScriptGenerator
impl Sync for K6ScriptGenerator
impl Unpin for K6ScriptGenerator
impl UnsafeUnpin for K6ScriptGenerator
impl UnwindSafe for K6ScriptGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more