Something went wrong. Try again.
xburner is an experimental HTTP and gRPC load generator written in Zig.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100const std = @import("std");
const config = @import("../config.zig");const config_validate = @import("validate.zig");
pub fn validateScenarioConfig(scenario_config: config.ScenarioConfig) config.SchemaError!void { if (scenario_config.http.requests.len == 0) return error.MissingHttpRequest; if (scenario_config.http.defaults.max_steps_per_iteration == 0) return error.MaxStepsMustBePositive; if (scenario_config.execution.warmup.nanos > scenario_config.execution.duration.nanos) return error.WarmupExceedsDuration;
if (scenario_config.execution.pre_allocated_vus != null and scenario_config.execution.max_vus != null) { if (scenario_config.execution.pre_allocated_vus.? > scenario_config.execution.max_vus.?) { return error.PreAllocatedVusExceedsMaxVus; } }
if (scenario_config.scenario.mode() == .simple and scenario_config.http.requests.len != 1) { return error.SimpleModeRequiresSingleRequest; } if (scenario_config.http.version == .http2 and !scenario_config.http.defaults.use_tls and !std.mem.startsWith(u8, scenario_config.scenario.target, "https://")) { return error.Http2RequiresTls; } if ((scenario_config.http.transport_plugin != null or scenario_config.exporters.plugins.len != 0) and scenario_config.plugins.dir == null) { return error.PluginDirectoryRequired; } if (scenario_config.scenario.protocol == .grpc) { if (scenario_config.http.defaults.cookie_jar) return error.GrpcCookieJarUnsupported; }
for (scenario_config.http.requests) |request| { if (request.path.len == 0 or request.path[0] != '/') return error.InvalidRequestPath; if (scenario_config.scenario.protocol == .grpc and request.method != .POST) { return error.GrpcRequiresPostMethod; } try config_validate.validateTemplateValue(request.path, .path); if (request.body) |body| try config_validate.validateTemplateValue(body, .body); if (request.check_body_contains) |body_check| try config_validate.validateTemplateValue(body_check, .body); for (request.headers) |header| try config_validate.validateTemplateValue(header.value, .header); if (request.check_response_header) |header_name| { if (header_name.len == 0) return error.InvalidHeaderValue; } } for (scenario_config.http.defaults.headers) |header| { try config_validate.validateTemplateValue(header.value, .header); }
for (scenario_config.setup.requests) |request| { if (request.path.len == 0 or request.path[0] != '/') return error.InvalidRequestPath; try config_validate.validateTemplateValue(request.path, .path); if (request.body) |body| try config_validate.validateTemplateValue(body, .body); for (request.headers) |header| try config_validate.validateTemplateValue(header.value, .header); if (request.store_body_as) |store_key| { if (!std.mem.startsWith(u8, store_key, "setup.")) return error.InvalidSetupStoreKey; } }
for (scenario_config.thresholds) |threshold| { if (threshold.scope.request) |request_name| { if (!hasRequestNamed(scenario_config, request_name)) return error.UnknownThresholdRequest; } if (threshold.scope.scenario) |scenario_name| { if (!std.mem.eql(u8, scenario_name, scenario_config.scenario.name)) return error.UnknownThresholdScenario; } if (threshold.scope.protocol) |protocol| { if (protocol != scenario_config.scenario.protocol) return error.UnknownThresholdProtocol; }
if (threshold.expression_clauses.len != 0) { for (threshold.expression_clauses) |clause| { try validateThresholdMetricScope(threshold.scope, clause.metric); } } else { try validateThresholdMetricScope(threshold.scope, threshold.metric); } }}
fn hasRequestNamed(scenario_config: config.ScenarioConfig, name: []const u8) bool { for (scenario_config.http.requests) |request| { if (std.mem.eql(u8, request.name, name)) return true; } return false;}
fn validateThresholdMetricScope(scope: config.ThresholdScope, metric: config.ThresholdMetric) config.SchemaError!void { if (scope.request != null) { switch (metric) { .iteration_dropped, .iteration_success_rate, => return error.InvalidThresholdScope, else => {}, } }}