runSequentialBenchmark runs the benchmark sequentially (single-threaded).
( ctx context.Context, client *constraintclient.Client, reviewObjs []*unstructured.Unstructured, opts *Opts, )
| 350 | |
| 351 | // runSequentialBenchmark runs the benchmark sequentially (single-threaded). |
| 352 | func runSequentialBenchmark( |
| 353 | ctx context.Context, |
| 354 | client *constraintclient.Client, |
| 355 | reviewObjs []*unstructured.Unstructured, |
| 356 | opts *Opts, |
| 357 | ) ([]time.Duration, int64, []*instrumentation.StatsEntry, error) { |
| 358 | var durations []time.Duration |
| 359 | var totalViolations int64 |
| 360 | var statsEntries []*instrumentation.StatsEntry |
| 361 | |
| 362 | for i := 0; i < opts.Iterations; i++ { |
| 363 | for _, obj := range reviewObjs { |
| 364 | au := target.AugmentedUnstructured{ |
| 365 | Object: *obj, |
| 366 | Source: mutationtypes.SourceTypeOriginal, |
| 367 | } |
| 368 | |
| 369 | reviewStart := time.Now() |
| 370 | resp, err := client.Review(ctx, au, reviews.EnforcementPoint(util.GatorEnforcementPoint)) |
| 371 | reviewDuration := time.Since(reviewStart) |
| 372 | |
| 373 | if err != nil { |
| 374 | return nil, 0, nil, fmt.Errorf("review failed for %s/%s: %w", |
| 375 | obj.GetNamespace(), obj.GetName(), err) |
| 376 | } |
| 377 | |
| 378 | durations = append(durations, reviewDuration) |
| 379 | |
| 380 | // Count violations |
| 381 | for _, r := range resp.ByTarget { |
| 382 | totalViolations += int64(len(r.Results)) |
| 383 | } |
| 384 | |
| 385 | // Collect stats only from first iteration to avoid excessive data |
| 386 | if opts.GatherStats && i == 0 { |
| 387 | statsEntries = append(statsEntries, resp.StatsEntries...) |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | return durations, totalViolations, statsEntries, nil |
| 393 | } |
| 394 | |
| 395 | // reviewResult holds the result of a single review for concurrent execution. |
| 396 | type reviewResult struct { |
no test coverage detected
searching dependent graphs…