mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Migrate etcd version monitor to metrics stability framework
This commit is contained in:
parent
29f23e6647
commit
fe6c700146
@ -26,11 +26,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
"k8s.io/component-base/metrics"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,15 +59,16 @@ const (
|
|||||||
// Initialize prometheus metrics to be exported.
|
// Initialize prometheus metrics to be exported.
|
||||||
var (
|
var (
|
||||||
// Register all custom metrics with a dedicated registry to keep them separate.
|
// Register all custom metrics with a dedicated registry to keep them separate.
|
||||||
customMetricRegistry = prometheus.NewRegistry()
|
customMetricRegistry = metrics.NewKubeRegistry()
|
||||||
|
|
||||||
// Custom etcd version metric since etcd 3.2- does not export one.
|
// Custom etcd version metric since etcd 3.2- does not export one.
|
||||||
// This will be replaced by https://github.com/coreos/etcd/pull/8960 in etcd 3.3.
|
// This will be replaced by https://github.com/coreos/etcd/pull/8960 in etcd 3.3.
|
||||||
etcdVersion = prometheus.NewGaugeVec(
|
etcdVersion = metrics.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
&metrics.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Name: "version_info",
|
Name: "version_info",
|
||||||
Help: "Etcd server's binary version",
|
Help: "Etcd server's binary version",
|
||||||
|
StabilityLevel: metrics.ALPHA,
|
||||||
},
|
},
|
||||||
[]string{"binary_version"})
|
[]string{"binary_version"})
|
||||||
|
|
||||||
@ -227,14 +229,14 @@ func getVersion(lastSeenBinaryVersion *string) error {
|
|||||||
|
|
||||||
// Delete the metric for the previous version.
|
// Delete the metric for the previous version.
|
||||||
if *lastSeenBinaryVersion != "" {
|
if *lastSeenBinaryVersion != "" {
|
||||||
deleted := etcdVersion.Delete(prometheus.Labels{"binary_version": *lastSeenBinaryVersion})
|
deleted := etcdVersion.Delete(metrics.Labels{"binary_version": *lastSeenBinaryVersion})
|
||||||
if !deleted {
|
if !deleted {
|
||||||
return errors.New("failed to delete previous version's metric")
|
return errors.New("failed to delete previous version's metric")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the new version in a metric.
|
// Record the new version in a metric.
|
||||||
etcdVersion.With(prometheus.Labels{
|
etcdVersion.With(metrics.Labels{
|
||||||
"binary_version": version.BinaryVersion,
|
"binary_version": version.BinaryVersion,
|
||||||
}).Set(0)
|
}).Set(0)
|
||||||
*lastSeenBinaryVersion = version.BinaryVersion
|
*lastSeenBinaryVersion = version.BinaryVersion
|
||||||
@ -392,7 +394,6 @@ func main() {
|
|||||||
|
|
||||||
// Register the metrics we defined above with prometheus.
|
// Register the metrics we defined above with prometheus.
|
||||||
customMetricRegistry.MustRegister(etcdVersion)
|
customMetricRegistry.MustRegister(etcdVersion)
|
||||||
customMetricRegistry.Unregister(prometheus.NewGoCollector())
|
|
||||||
|
|
||||||
// Spawn threads for periodically scraping etcd version metrics.
|
// Spawn threads for periodically scraping etcd version metrics.
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
|
Loading…
Reference in New Issue
Block a user