From 9c8867f7a832ad71e73686824bce42d96c6c5def Mon Sep 17 00:00:00 2001 From: jornshen Date: Mon, 31 Aug 2020 21:21:54 +0800 Subject: [PATCH] clean up testutil/metrics content including: 1. use constant var MetricNameLabel to replace model.MetricNameLabel in ParseMetrics 2. remove function ExtractMetricSamples --- .../metrics/testutil/metrics.go | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go index 79b7e7db0a8..38965501221 100644 --- a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go +++ b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go @@ -86,7 +86,7 @@ func ParseMetrics(data string, output *Metrics) error { continue } for _, metric := range v { - name := string(metric.Metric[model.MetricNameLabel]) + name := string(metric.Metric[MetricNameLabel]) (*output)[name] = append((*output)[name], metric) } } @@ -101,28 +101,6 @@ func TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) { return textParser.TextToMetricFamilies(in) } -// ExtractMetricSamples parses the prometheus metric samples from the input string. -func ExtractMetricSamples(metricsBlob string) ([]*model.Sample, error) { - dec := expfmt.NewDecoder(strings.NewReader(metricsBlob), expfmt.FmtText) - decoder := expfmt.SampleDecoder{ - Dec: dec, - Opts: &expfmt.DecodeOptions{}, - } - - var samples []*model.Sample - for { - var v model.Vector - if err := decoder.Decode(&v); err != nil { - if err == io.EOF { - // Expected loop termination condition. - return samples, nil - } - return nil, err - } - samples = append(samples, v...) - } -} - // PrintSample returns formatted representation of metric Sample func PrintSample(sample *model.Sample) string { buf := make([]string, 0)