MCPcopy
hub / github.com/open-policy-agent/gatekeeper / Run

Function Run

pkg/gator/bench/bench.go:44–128  ·  view source on GitHub ↗

Run executes the benchmark with the given options and returns results for each engine tested.

(opts *Opts)

Source from the content-addressed store, hash-verified

42// Run executes the benchmark with the given options and returns results
43// for each engine tested.
44func 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 {

Callers 13

runFunction · 0.92
TestRun_MissingInputsFunction · 0.85
TestRun_NoTemplatesFunction · 0.85
TestRun_IntegrationFunction · 0.85
TestRun_AllEnginesFunction · 0.85
TestRun_NoConstraintsFunction · 0.85
TestRun_NoObjectsFunction · 0.85
TestRun_WithGatherStatsFunction · 0.85
TestRun_CELOnlyFunction · 0.85
TestRun_SetupBreakdownFunction · 0.85
TestRun_SkippedTemplatesFunction · 0.85
TestRun_ConcurrentFunction · 0.85

Calls 5

ReadSourcesFunction · 0.92
IsTemplateFunction · 0.92
IsConstraintFunction · 0.92
runBenchmarkFunction · 0.85
ErrorMethod · 0.45

Tested by 12

TestRun_MissingInputsFunction · 0.68
TestRun_NoTemplatesFunction · 0.68
TestRun_IntegrationFunction · 0.68
TestRun_AllEnginesFunction · 0.68
TestRun_NoConstraintsFunction · 0.68
TestRun_NoObjectsFunction · 0.68
TestRun_WithGatherStatsFunction · 0.68
TestRun_CELOnlyFunction · 0.68
TestRun_SetupBreakdownFunction · 0.68
TestRun_SkippedTemplatesFunction · 0.68
TestRun_ConcurrentFunction · 0.68