Run executes the benchmark with the given options and returns results for each engine tested.
(opts *Opts)
| 42 | // Run executes the benchmark with the given options and returns results |
| 43 | // for each engine tested. |
| 44 | func Run(opts *Opts) ([]Results, error) { |
| 45 | // Warn if iterations are too low for meaningful P99 statistics |
| 46 | if opts.Iterations < MinIterationsForP99 && opts.Writer != nil { |
| 47 | fmt.Fprintf(opts.Writer, "Warning: %d iterations may not provide statistically meaningful P99 metrics. Consider using at least %d iterations.\n\n", |
| 48 | opts.Iterations, MinIterationsForP99) |
| 49 | } |
| 50 | |
| 51 | // Default concurrency to 1 (sequential) |
| 52 | if opts.Concurrency < 1 { |
| 53 | opts.Concurrency = 1 |
| 54 | } |
| 55 | |
| 56 | // Read all resources from files/images |
| 57 | objs, err := reader.ReadSources(opts.Filenames, opts.Images, opts.TempDir) |
| 58 | if err != nil { |
| 59 | return nil, fmt.Errorf("reading sources: %w", err) |
| 60 | } |
| 61 | if len(objs) == 0 { |
| 62 | return nil, fmt.Errorf("no input data identified") |
| 63 | } |
| 64 | |
| 65 | // Categorize objects |
| 66 | var templates []*unstructured.Unstructured |
| 67 | var constraints []*unstructured.Unstructured |
| 68 | var reviewObjs []*unstructured.Unstructured |
| 69 | |
| 70 | for _, obj := range objs { |
| 71 | switch { |
| 72 | case reader.IsTemplate(obj): |
| 73 | templates = append(templates, obj) |
| 74 | case reader.IsConstraint(obj): |
| 75 | constraints = append(constraints, obj) |
| 76 | default: |
| 77 | // Everything else is a potential review object |
| 78 | reviewObjs = append(reviewObjs, obj) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if len(templates) == 0 { |
| 83 | return nil, fmt.Errorf("no ConstraintTemplates found in input") |
| 84 | } |
| 85 | if len(constraints) == 0 { |
| 86 | return nil, fmt.Errorf("no Constraints found in input") |
| 87 | } |
| 88 | if len(reviewObjs) == 0 { |
| 89 | return nil, fmt.Errorf("no objects to review found in input") |
| 90 | } |
| 91 | |
| 92 | var results []Results |
| 93 | var warnings []string |
| 94 | |
| 95 | // Determine which engines to benchmark |
| 96 | engines := []Engine{opts.Engine} |
| 97 | if opts.Engine == EngineAll { |
| 98 | engines = []Engine{EngineRego, EngineCEL} |
| 99 | } |
| 100 | |
| 101 | for _, engine := range engines { |