Merge pull request #94386 from JornShen/cleanup_testutil_metrics
clean up testutil/metrics.go
This commit is contained in:
@@ -86,7 +86,7 @@ func ParseMetrics(data string, output *Metrics) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, metric := range v {
|
for _, metric := range v {
|
||||||
name := string(metric.Metric[model.MetricNameLabel])
|
name := string(metric.Metric[MetricNameLabel])
|
||||||
(*output)[name] = append((*output)[name], metric)
|
(*output)[name] = append((*output)[name], metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,28 +101,6 @@ func TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) {
|
|||||||
return textParser.TextToMetricFamilies(in)
|
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
|
// PrintSample returns formatted representation of metric Sample
|
||||||
func PrintSample(sample *model.Sample) string {
|
func PrintSample(sample *model.Sample) string {
|
||||||
buf := make([]string, 0)
|
buf := make([]string, 0)
|
||||||
|
Reference in New Issue
Block a user