Fix metric unregistered

This commit is contained in:
bogo 2023-08-17 20:23:01 +08:00
parent 74ba84b76e
commit 966ef227fe

View file

@ -23,6 +23,8 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"sigs.k8s.io/prometheus-adapter/pkg/client" "sigs.k8s.io/prometheus-adapter/pkg/client"
) )
@ -30,18 +32,18 @@ var (
// queryLatency is the total latency of any query going through the // queryLatency is the total latency of any query going through the
// various endpoints (query, range-query, series). It includes some deserialization // various endpoints (query, range-query, series). It includes some deserialization
// overhead and HTTP overhead. // overhead and HTTP overhead.
queryLatency = prometheus.NewHistogramVec( queryLatency = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Name: "cmgateway_prometheus_query_latency_seconds", Name: "cmgateway_prometheus_query_latency_seconds",
Help: "Prometheus client query latency in seconds. Broken down by target prometheus endpoint and target server", Help: "Prometheus client query latency in seconds. Broken down by target prometheus endpoint and target server",
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 10), Buckets: prometheus.ExponentialBuckets(0.01, 2, 10),
}, },
[]string{"endpoint", "server"}, []string{"endpoint", "server"},
) )
) )
func init() { func init() {
prometheus.MustRegister(queryLatency) legacyregistry.MustRegister(queryLatency)
} }
// instrumentedClient is a client.GenericAPIClient which instruments calls to Do, // instrumentedClient is a client.GenericAPIClient which instruments calls to Do,