Skip to content

Commit

Permalink
Merge pull request kubernetes#94386 from JornShen/cleanup_testutil_me…
Browse files Browse the repository at this point in the history
…trics

clean up testutil/metrics.go
  • Loading branch information
k8s-ci-robot committed Sep 7, 2020
2 parents 35e235b + 9c8867f commit 2a8640b
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions staging/src/k8s.io/component-base/metrics/testutil/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 2a8640b

Please sign in to comment.