clean up testutil/metrics content

including:
1. use constant var MetricNameLabel to replace model.MetricNameLabel in ParseMetrics
2. remove function ExtractMetricSamples
This commit is contained in:
jornshen 2020-08-31 21:21:54 +08:00
parent e23d83eead
commit 9c8867f7a8

View File

@ -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)