@@ -24,11 +24,12 @@ import (
2424)
2525
2626const (
27+ DURATION_FORMATTER = "%DURATION"
2728 controlPlaneContainerMemQL = `process_resident_memory_bytes{namespace="envoy-gateway-system", control_plane="envoy-gateway"}/1024/1024`
2829 controlPlaneProcessMemQL = `go_memstats_heap_inuse_bytes{namespace="envoy-gateway-system", control_plane="envoy-gateway"}/1024/1024`
29- controlPlaneCPUQL = `rate(process_cpu_seconds_total{namespace="envoy-gateway-system", control_plane="envoy-gateway"}[30s ])*100`
30+ controlPlaneCPUQL = `rate(process_cpu_seconds_total{namespace="envoy-gateway-system", control_plane="envoy-gateway"}[%DURATIONs ])*100`
3031 dataPlaneMemQL = `container_memory_working_set_bytes{namespace="envoy-gateway-system", container="envoy"}/1024/1024`
31- dataPlaneCPUQL = `rate(container_cpu_usage_seconds_total{namespace="envoy-gateway-system", container="envoy"}[30s ])*100`
32+ dataPlaneCPUQL = `rate(container_cpu_usage_seconds_total{namespace="envoy-gateway-system", container="envoy"}[%DURATIONs ])*100`
3233)
3334
3435// BenchmarkMetricSample contains sampled metrics and profiles data.
@@ -63,10 +64,10 @@ func NewBenchmarkReport(name, profilesOutputDir string, kubeClient kube.CLIClien
6364 }
6465}
6566
66- func (r * BenchmarkReport ) Sample (ctx context.Context ) (err error ) {
67+ func (r * BenchmarkReport ) Sample (ctx context.Context , startTime time. Time ) (err error ) {
6768 sample := BenchmarkMetricSample {}
6869
69- if mErr := r .sampleMetrics (ctx , & sample ); mErr != nil {
70+ if mErr := r .sampleMetrics (ctx , & sample , startTime ); mErr != nil {
7071 err = errors .Join (mErr )
7172 }
7273
@@ -122,11 +123,18 @@ func (r *BenchmarkReport) sampleMetrics(ctx context.Context, sample *BenchmarkMe
122123 err = errors .Join (err , fmt .Errorf ("failed to query data plane memory: %w" , qErr ))
123124 }
124125 // Sample cpu
125- cpCPU , qErr := r .promClient .QuerySum (ctx , controlPlaneCPUQL )
126+
127+ // Get duration
128+ durationSeconds := int (time .Now .Sub (startTime ))
129+ cpCPUQL := strings .ReplaceAll (controlPlaneCPUQL , DURATION_FORMATTER , durationSeconds )
130+
131+ cpCPUQL , qErr := r .promClient .QuerySum (ctx , cpCPUQL )
126132 if qErr != nil {
127133 err = errors .Join (err , fmt .Errorf ("failed to query control plane cpu: %w" , qErr ))
128134 }
129- dpCPU , qErr := r .promClient .QueryAvg (ctx , dataPlaneCPUQL )
135+
136+ dpCPUQL := strings .ReplaceAll (dataPlaneCPUQL , DURATION_FORMATTER , durationSeconds )
137+ dpCPUQL , qErr := r .promClient .QueryAvg (ctx , dpCPUQL )
130138 if qErr != nil {
131139 err = errors .Join (err , fmt .Errorf ("failed to query data plane cpu: %w" , qErr ))
132140 }
0 commit comments