Skip to content

Commit 69cdd54

Browse files
committed
feat(test): add LatencyHarness for histogram / counter deltas
Introduce common.LatencyHarness alongside KarpenterMetricsPoller. The harness scrapes /metrics at phase start and stop, then reduces per-series histogram bucket deltas into percentile stats (P50/P90/P95/P99, plus bucket truncation rate) and counter deltas over the observation window. The scrape helper is shared with KarpenterMetricsPoller (previously the poller inlined the API-server pod-proxy fetch + parse). Both callers now funnel through scrapeKarpenterMetricFamilies. Includes common.LatencySidecar (JSON schema for the artifact written alongside PerformanceReport when OUTPUT_DIR is set) and common.WriteLatencySidecar so performance-suite specs share one on-disk shape rather than each declaring its own.
1 parent d1aacae commit 69cdd54

4 files changed

Lines changed: 745 additions & 13 deletions

File tree

test/pkg/environment/common/karpenter_metrics_poller.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package common
1818

1919
import (
20-
"bytes"
2120
"context"
2221
"errors"
2322
"fmt"
@@ -27,8 +26,6 @@ import (
2726
"github.com/montanaflynn/stats"
2827
. "github.com/onsi/ginkgo/v2"
2928
dto "github.com/prometheus/client_model/go"
30-
"github.com/prometheus/common/expfmt"
31-
"github.com/prometheus/common/model"
3229
)
3330

3431
type ResourceSample struct {
@@ -211,20 +208,12 @@ func (mp *KarpenterMetricsPoller) recordSample(state *pollerState, now time.Time
211208

212209
// scrapeMetrics uses the API server pod proxy to fetch /metrics from the Karpenter pod.
213210
func (mp *KarpenterMetricsPoller) scrapeMetrics(ctx context.Context, podName string) (memBytes float64, cpuSeconds float64, err error) {
214-
data, err := mp.env.KubeClient.CoreV1().Pods("kube-system").ProxyGet("http", podName, "8080", "/metrics", nil).DoRaw(ctx)
211+
families, err := scrapeKarpenterMetricFamilies(ctx, mp.env, podName)
215212
if err != nil {
216-
return 0, 0, fmt.Errorf("proxy GET /metrics: %w", err)
213+
return 0, 0, err
217214
}
218-
219-
parser := expfmt.NewTextParser(model.UTF8Validation)
220-
families, err := parser.TextToMetricFamilies(bytes.NewReader(data))
221-
if err != nil {
222-
return 0, 0, fmt.Errorf("parsing metrics: %w", err)
223-
}
224-
225215
memBytes = getGaugeValue(families, "process_resident_memory_bytes")
226216
cpuSeconds = getCounterValue(families, "process_cpu_seconds_total")
227-
228217
if memBytes == 0 && cpuSeconds == 0 {
229218
return 0, 0, &metricsNotFoundError{foundMem: false, foundCPU: false}
230219
}

0 commit comments

Comments
 (0)