const std = @import("std"); const config = @import("../config.zig"); const config_parser = @import("parser.zig"); const config_validate = @import("validate.zig"); pub fn normalizeParsedConfig( arena: *std.heap.ArenaAllocator, parser: *config_parser.Parser, ) config.LoadError!config.ScenarioConfig { const arena_allocator = arena.allocator(); const http_defaults = try parser.http_defaults.build(); const stages = try buildStages(arena_allocator, parser); const requests = try buildRequests(arena_allocator, parser, http_defaults); try config_validate.validateRequestIds(requests); const setup_requests = try buildSetupRequests(arena_allocator, parser); const thresholds = try buildThresholds(arena_allocator, parser); const plugin_exporters = try buildPluginExporters(arena_allocator, parser); return .{ .arena = arena.*, .scenario = try parser.scenario.build(), .recovery = try parser.recovery.build(), .execution = blk: { parser.execution.stages = stages; break :blk try parser.execution.build(); }, .plugins = parser.plugins.build(), .setup = .{ .requests = setup_requests, }, .http = try parser.http.build(http_defaults, requests), .exporters = .{ .otlp = if (parser.otlp_exporter.url != null) try parser.otlp_exporter.build() else null, .plugins = plugin_exporters, }, .thresholds = thresholds, }; } fn buildStages( allocator: std.mem.Allocator, parser: *config_parser.Parser, ) ![]config.RampStage { var stages = try allocator.alloc(config.RampStage, parser.stage_builders.items.len); for (parser.stage_builders.items, 0..) |*builder, index| { stages[index] = try builder.build(); } return stages; } fn buildRequests( allocator: std.mem.Allocator, parser: *config_parser.Parser, http_defaults: config.HttpDefaults, ) ![]config.HttpRequestTemplate { var requests = try allocator.alloc(config.HttpRequestTemplate, parser.request_builders.items.len); for (parser.request_builders.items, 0..) |*builder, index| { requests[index] = try builder.build(allocator, http_defaults); } return requests; } fn buildSetupRequests( allocator: std.mem.Allocator, parser: *config_parser.Parser, ) ![]config.SetupRequest { var setup_requests = try allocator.alloc(config.SetupRequest, parser.setup_request_builders.items.len); for (parser.setup_request_builders.items, 0..) |*builder, index| { setup_requests[index] = try builder.build(); } return setup_requests; } fn buildThresholds( allocator: std.mem.Allocator, parser: *config_parser.Parser, ) ![]config.Threshold { var thresholds = try allocator.alloc(config.Threshold, parser.threshold_builders.items.len); for (parser.threshold_builders.items, 0..) |*builder, index| { thresholds[index] = try builder.build(allocator); } return thresholds; } fn buildPluginExporters( allocator: std.mem.Allocator, parser: *config_parser.Parser, ) ![]config.PluginExporter { var plugin_exporters = try allocator.alloc(config.PluginExporter, parser.plugin_exporter_builders.items.len); for (parser.plugin_exporter_builders.items, 0..) |*builder, index| { plugin_exporters[index] = try builder.build(); } return plugin_exporters; }