Remove prometheus references from etcd version monitor

This commit is contained in:
zhouya0 2020-03-24 14:23:26 +08:00
parent de877ec26e
commit 04d06d2f23
3 changed files with 12 additions and 5 deletions

View File

@ -17,9 +17,9 @@ go_library(
importpath = "k8s.io/kubernetes/cluster/images/etcd-version-monitor", importpath = "k8s.io/kubernetes/cluster/images/etcd-version-monitor",
deps = [ deps = [
"//staging/src/k8s.io/component-base/metrics:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/testutil:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library", "//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/prometheus/client_model/go:go_default_library", "//vendor/github.com/prometheus/client_model/go:go_default_library",
"//vendor/github.com/prometheus/common/expfmt:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library", "//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
], ],

View File

@ -27,10 +27,10 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"k8s.io/component-base/metrics" "k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/testutil"
"k8s.io/klog" "k8s.io/klog"
) )
@ -271,9 +271,7 @@ func scrapeMetrics() (map[string]*dto.MetricFamily, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
// Parse the metrics in text format to a MetricFamily struct. return testutil.TextToMetricFamilies(resp.Body)
var textParser expfmt.TextParser
return textParser.TextToMetricFamilies(resp.Body)
} }
func renameMetric(mf *dto.MetricFamily, name string) { func renameMetric(mf *dto.MetricFamily, name string) {

View File

@ -92,6 +92,15 @@ func ParseMetrics(data string, output *Metrics) error {
} }
} }
// TextToMetricFamilies reads 'in' as the simple and flat text-based exchange
// format and creates MetricFamily proto messages. It returns the MetricFamily
// proto messages in a map where the metric names are the keys, along with any
// error encountered.
func TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) {
var textParser expfmt.TextParser
return textParser.TextToMetricFamilies(in)
}
// ExtractMetricSamples parses the prometheus metric samples from the input string. // ExtractMetricSamples parses the prometheus metric samples from the input string.
func ExtractMetricSamples(metricsBlob string) ([]*model.Sample, error) { func ExtractMetricSamples(metricsBlob string) ([]*model.Sample, error) {
dec := expfmt.NewDecoder(strings.NewReader(metricsBlob), expfmt.FmtText) dec := expfmt.NewDecoder(strings.NewReader(metricsBlob), expfmt.FmtText)