Merge pull request #81534 from logicalhan/kubelet-migration

migrate kubelet's metrics/probes & metrics endpoint to metrics stability framework
This commit is contained in:
Kubernetes Prow Robot 2019-08-28 18:26:45 -07:00 committed by GitHub
commit ca5babc1da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 459 additions and 358 deletions

View File

@ -26,7 +26,8 @@ go_library(
"//staging/src/k8s.io/client-go/rest:go_default_library", "//staging/src/k8s.io/client-go/rest:go_default_library",
"//staging/src/k8s.io/client-go/util/certificate:go_default_library", "//staging/src/k8s.io/client-go/util/certificate:go_default_library",
"//staging/src/k8s.io/client-go/util/connrotation:go_default_library", "//staging/src/k8s.io/client-go/util/connrotation:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
], ],
) )

View File

@ -24,14 +24,14 @@ import (
"net" "net"
"sort" "sort"
"github.com/prometheus/client_golang/prometheus"
certificates "k8s.io/api/certificates/v1beta1" certificates "k8s.io/api/certificates/v1beta1"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1" certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
"k8s.io/client-go/util/certificate" "k8s.io/client-go/util/certificate"
compbasemetrics "k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/metrics"
) )
@ -52,15 +52,16 @@ func NewKubeletServerCertificateManager(kubeClient clientset.Interface, kubeCfg
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to initialize server certificate store: %v", err) return nil, fmt.Errorf("failed to initialize server certificate store: %v", err)
} }
var certificateExpiration = prometheus.NewGauge( var certificateExpiration = compbasemetrics.NewGauge(
prometheus.GaugeOpts{ &compbasemetrics.GaugeOpts{
Namespace: metrics.KubeletSubsystem, Namespace: metrics.KubeletSubsystem,
Subsystem: "certificate_manager", Subsystem: "certificate_manager",
Name: "server_expiration_seconds", Name: "server_expiration_seconds",
Help: "Gauge of the lifetime of a certificate. The value is the date the certificate will expire in seconds since January 1, 1970 UTC.", Help: "Gauge of the lifetime of a certificate. The value is the date the certificate will expire in seconds since January 1, 1970 UTC.",
StabilityLevel: compbasemetrics.ALPHA,
}, },
) )
prometheus.MustRegister(certificateExpiration) legacyregistry.MustRegister(certificateExpiration)
getTemplate := func() *x509.CertificateRequest { getTemplate := func() *x509.CertificateRequest {
hostnames, ips := addressesToHostnamesAndIPs(getAddresses()) hostnames, ips := addressesToHostnamesAndIPs(getAddresses())
@ -166,15 +167,16 @@ func NewKubeletClientCertificateManager(
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to initialize client certificate store: %v", err) return nil, fmt.Errorf("failed to initialize client certificate store: %v", err)
} }
var certificateExpiration = prometheus.NewGauge( var certificateExpiration = compbasemetrics.NewGauge(
prometheus.GaugeOpts{ &compbasemetrics.GaugeOpts{
Namespace: metrics.KubeletSubsystem, Namespace: metrics.KubeletSubsystem,
Subsystem: "certificate_manager", Subsystem: "certificate_manager",
Name: "client_expiration_seconds", Name: "client_expiration_seconds",
Help: "Gauge of the lifetime of a certificate. The value is the date the certificate will expire in seconds since January 1, 1970 UTC.", Help: "Gauge of the lifetime of a certificate. The value is the date the certificate will expire in seconds since January 1, 1970 UTC.",
StabilityLevel: compbasemetrics.ALPHA,
}, },
) )
prometheus.Register(certificateExpiration) legacyregistry.Register(certificateExpiration)
m, err := certificate.NewManager(&certificate.Config{ m, err := certificate.NewManager(&certificate.Config{
ClientFn: clientFn, ClientFn: clientFn,

View File

@ -5,7 +5,11 @@ go_library(
srcs = ["metrics.go"], srcs = ["metrics.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/metrics", importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/metrics",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = ["//vendor/github.com/prometheus/client_golang/prometheus:go_default_library"], deps = [
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
],
) )
filegroup( filegroup(

View File

@ -21,6 +21,9 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
) )
const ( const (
@ -49,79 +52,87 @@ const (
var ( var (
// DockerOperationsLatency collects operation latency numbers by operation // DockerOperationsLatency collects operation latency numbers by operation
// type. // type.
DockerOperationsLatency = prometheus.NewHistogramVec( DockerOperationsLatency = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DockerOperationsLatencyKey, Name: DockerOperationsLatencyKey,
Help: "Latency in seconds of Docker operations. Broken down by operation type.", Help: "Latency in seconds of Docker operations. Broken down by operation type.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DockerOperations collects operation counts by operation type. // DockerOperations collects operation counts by operation type.
DockerOperations = prometheus.NewCounterVec( DockerOperations = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DockerOperationsKey, Name: DockerOperationsKey,
Help: "Cumulative number of Docker operations by operation type.", Help: "Cumulative number of Docker operations by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DockerOperationsErrors collects operation errors by operation // DockerOperationsErrors collects operation errors by operation
// type. // type.
DockerOperationsErrors = prometheus.NewCounterVec( DockerOperationsErrors = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DockerOperationsErrorsKey, Name: DockerOperationsErrorsKey,
Help: "Cumulative number of Docker operation errors by operation type.", Help: "Cumulative number of Docker operation errors by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DockerOperationsTimeout collects operation timeouts by operation type. // DockerOperationsTimeout collects operation timeouts by operation type.
DockerOperationsTimeout = prometheus.NewCounterVec( DockerOperationsTimeout = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DockerOperationsTimeoutKey, Name: DockerOperationsTimeoutKey,
Help: "Cumulative number of Docker operation timeout by operation type.", Help: "Cumulative number of Docker operation timeout by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedDockerOperationsLatency collects operation latency numbers by operation // DeprecatedDockerOperationsLatency collects operation latency numbers by operation
// type. // type.
DeprecatedDockerOperationsLatency = prometheus.NewSummaryVec( DeprecatedDockerOperationsLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DeprecatedDockerOperationsLatencyKey, Name: DeprecatedDockerOperationsLatencyKey,
Help: "(Deprecated) Latency in microseconds of Docker operations. Broken down by operation type.", Help: "(Deprecated) Latency in microseconds of Docker operations. Broken down by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedDockerOperations collects operation counts by operation type. // DeprecatedDockerOperations collects operation counts by operation type.
DeprecatedDockerOperations = prometheus.NewCounterVec( DeprecatedDockerOperations = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DeprecatedDockerOperationsKey, Name: DeprecatedDockerOperationsKey,
Help: "(Deprecated) Cumulative number of Docker operations by operation type.", Help: "(Deprecated) Cumulative number of Docker operations by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedDockerOperationsErrors collects operation errors by operation // DeprecatedDockerOperationsErrors collects operation errors by operation
// type. // type.
DeprecatedDockerOperationsErrors = prometheus.NewCounterVec( DeprecatedDockerOperationsErrors = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DeprecatedDockerOperationsErrorsKey, Name: DeprecatedDockerOperationsErrorsKey,
Help: "(Deprecated) Cumulative number of Docker operation errors by operation type.", Help: "(Deprecated) Cumulative number of Docker operation errors by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedDockerOperationsTimeout collects operation timeouts by operation type. // DeprecatedDockerOperationsTimeout collects operation timeouts by operation type.
DeprecatedDockerOperationsTimeout = prometheus.NewCounterVec( DeprecatedDockerOperationsTimeout = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DeprecatedDockerOperationsTimeoutKey, Name: DeprecatedDockerOperationsTimeoutKey,
Help: "(Deprecated) Cumulative number of Docker operation timeout by operation type.", Help: "(Deprecated) Cumulative number of Docker operation timeout by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
@ -132,14 +143,14 @@ var registerMetrics sync.Once
// Register all metrics. // Register all metrics.
func Register() { func Register() {
registerMetrics.Do(func() { registerMetrics.Do(func() {
prometheus.MustRegister(DockerOperationsLatency) legacyregistry.MustRegister(DockerOperationsLatency)
prometheus.MustRegister(DockerOperations) legacyregistry.MustRegister(DockerOperations)
prometheus.MustRegister(DockerOperationsErrors) legacyregistry.MustRegister(DockerOperationsErrors)
prometheus.MustRegister(DockerOperationsTimeout) legacyregistry.MustRegister(DockerOperationsTimeout)
prometheus.MustRegister(DeprecatedDockerOperationsLatency) legacyregistry.MustRegister(DeprecatedDockerOperationsLatency)
prometheus.MustRegister(DeprecatedDockerOperations) legacyregistry.MustRegister(DeprecatedDockerOperations)
prometheus.MustRegister(DeprecatedDockerOperationsErrors) legacyregistry.MustRegister(DeprecatedDockerOperationsErrors)
prometheus.MustRegister(DeprecatedDockerOperationsTimeout) legacyregistry.MustRegister(DeprecatedDockerOperationsTimeout)
}) })
} }

View File

@ -5,7 +5,11 @@ go_library(
srcs = ["metrics.go"], srcs = ["metrics.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/network/metrics", importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/network/metrics",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = ["//vendor/github.com/prometheus/client_golang/prometheus:go_default_library"], deps = [
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
],
) )
filegroup( filegroup(

View File

@ -21,6 +21,9 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
) )
const ( const (
@ -38,23 +41,25 @@ const (
var ( var (
// NetworkPluginOperationsLatency collects operation latency numbers by operation // NetworkPluginOperationsLatency collects operation latency numbers by operation
// type. // type.
NetworkPluginOperationsLatency = prometheus.NewHistogramVec( NetworkPluginOperationsLatency = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: NetworkPluginOperationsLatencyKey, Name: NetworkPluginOperationsLatencyKey,
Help: "Latency in seconds of network plugin operations. Broken down by operation type.", Help: "Latency in seconds of network plugin operations. Broken down by operation type.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedNetworkPluginOperationsLatency collects operation latency numbers by operation // DeprecatedNetworkPluginOperationsLatency collects operation latency numbers by operation
// type. // type.
DeprecatedNetworkPluginOperationsLatency = prometheus.NewSummaryVec( DeprecatedNetworkPluginOperationsLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: DeprecatedNetworkPluginOperationsLatencyKey, Name: DeprecatedNetworkPluginOperationsLatencyKey,
Help: "(Deprecated) Latency in microseconds of network plugin operations. Broken down by operation type.", Help: "(Deprecated) Latency in microseconds of network plugin operations. Broken down by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
@ -65,8 +70,8 @@ var registerMetrics sync.Once
// Register all metrics. // Register all metrics.
func Register() { func Register() {
registerMetrics.Do(func() { registerMetrics.Do(func() {
prometheus.MustRegister(NetworkPluginOperationsLatency) legacyregistry.MustRegister(NetworkPluginOperationsLatency)
prometheus.MustRegister(DeprecatedNetworkPluginOperationsLatency) legacyregistry.MustRegister(DeprecatedNetworkPluginOperationsLatency)
}) })
} }

View File

@ -117,12 +117,11 @@ go_test(
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library", "//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library", "//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library", "//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
"//staging/src/k8s.io/cri-api/pkg/apis/testing:go_default_library", "//staging/src/k8s.io/cri-api/pkg/apis/testing:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library", "//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/google/cadvisor/info/v1:go_default_library", "//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library", "//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library",

View File

@ -22,17 +22,17 @@ import (
"testing" "testing"
"time" "time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/component-base/metrics/legacyregistry"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/metrics"
) )
func TestRecordOperation(t *testing.T) { func TestRecordOperation(t *testing.T) {
prometheus.MustRegister(metrics.RuntimeOperations) legacyregistry.MustRegister(metrics.RuntimeOperations)
prometheus.MustRegister(metrics.RuntimeOperationsDuration) legacyregistry.MustRegister(metrics.RuntimeOperationsDuration)
prometheus.MustRegister(metrics.RuntimeOperationsErrors) legacyregistry.MustRegister(metrics.RuntimeOperationsErrors)
temporalServer := "127.0.0.1:1234" temporalServer := "127.0.0.1:1234"
l, err := net.Listen("tcp", temporalServer) l, err := net.Listen("tcp", temporalServer)
@ -41,7 +41,8 @@ func TestRecordOperation(t *testing.T) {
prometheusURL := "http://" + temporalServer + "/metrics" prometheusURL := "http://" + temporalServer + "/metrics"
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler()) //lint:ignore SA1019 ignore deprecated warning until we move off of global registries
mux.Handle("/metrics", legacyregistry.Handler())
server := &http.Server{ server := &http.Server{
Addr: temporalServer, Addr: temporalServer,
Handler: mux, Handler: mux,

View File

@ -15,6 +15,8 @@ go_library(
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
], ],

View File

@ -18,6 +18,8 @@ package metrics
import ( import (
"fmt" "fmt"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"sync" "sync"
"time" "time"
@ -88,279 +90,307 @@ const (
var ( var (
// NodeName is a Gauge that tracks the ode's name. The count is always 1. // NodeName is a Gauge that tracks the ode's name. The count is always 1.
NodeName = prometheus.NewGaugeVec( NodeName = metrics.NewGaugeVec(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: NodeNameKey, Name: NodeNameKey,
Help: "The node's name. The count is always 1.", Help: "The node's name. The count is always 1.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{NodeLabelKey}, []string{NodeLabelKey},
) )
// ContainersPerPodCount is a Counter that tracks the number of containers per pod. // ContainersPerPodCount is a Counter that tracks the number of containers per pod.
ContainersPerPodCount = prometheus.NewHistogram( ContainersPerPodCount = metrics.NewHistogram(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: "containers_per_pod_count", Name: "containers_per_pod_count",
Help: "The number of containers per pod.", Help: "The number of containers per pod.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
) )
// PodWorkerDuration is a Histogram that tracks the duration (in seconds) in takes to sync a single pod. // PodWorkerDuration is a Histogram that tracks the duration (in seconds) in takes to sync a single pod.
// Broken down by the operation type. // Broken down by the operation type.
PodWorkerDuration = prometheus.NewHistogramVec( PodWorkerDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PodWorkerDurationKey, Name: PodWorkerDurationKey,
Help: "Duration in seconds to sync a single pod. Broken down by operation type: create, update, or sync", Help: "Duration in seconds to sync a single pod. Broken down by operation type: create, update, or sync",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// PodStartDuration is a Histogram that tracks the duration (in seconds) it takes for a single pod to go from pending to running. // PodStartDuration is a Histogram that tracks the duration (in seconds) it takes for a single pod to go from pending to running.
PodStartDuration = prometheus.NewHistogram( PodStartDuration = metrics.NewHistogram(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PodStartDurationKey, Name: PodStartDurationKey,
Help: "Duration in seconds for a single pod to go from pending to running.", Help: "Duration in seconds for a single pod to go from pending to running.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
) )
// CgroupManagerDuration is a Histogram that tracks the duration (in seconds) it takes for cgroup manager operations to complete. // CgroupManagerDuration is a Histogram that tracks the duration (in seconds) it takes for cgroup manager operations to complete.
// Broken down by method. // Broken down by method.
CgroupManagerDuration = prometheus.NewHistogramVec( CgroupManagerDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: CgroupManagerOperationsKey, Name: CgroupManagerOperationsKey,
Help: "Duration in seconds for cgroup manager operations. Broken down by method.", Help: "Duration in seconds for cgroup manager operations. Broken down by method.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// PodWorkerStartDuration is a Histogram that tracks the duration (in seconds) it takes from seeing a pod to starting a worker. // PodWorkerStartDuration is a Histogram that tracks the duration (in seconds) it takes from seeing a pod to starting a worker.
PodWorkerStartDuration = prometheus.NewHistogram( PodWorkerStartDuration = metrics.NewHistogram(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PodWorkerStartDurationKey, Name: PodWorkerStartDurationKey,
Help: "Duration in seconds from seeing a pod to starting a worker.", Help: "Duration in seconds from seeing a pod to starting a worker.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
) )
// PLEGRelistDuration is a Histogram that tracks the duration (in seconds) it takes for relisting pods in the Kubelet's // PLEGRelistDuration is a Histogram that tracks the duration (in seconds) it takes for relisting pods in the Kubelet's
// Pod Lifecycle Event Generator (PLEG). // Pod Lifecycle Event Generator (PLEG).
PLEGRelistDuration = prometheus.NewHistogram( PLEGRelistDuration = metrics.NewHistogram(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PLEGRelistDurationKey, Name: PLEGRelistDurationKey,
Help: "Duration in seconds for relisting pods in PLEG.", Help: "Duration in seconds for relisting pods in PLEG.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
) )
// PLEGDiscardEvents is a Histogram that tracks the duration (in seconds) it takes for discarding events in the Kubelet's // PLEGDiscardEvents is a Histogram that tracks the duration (in seconds) it takes for discarding events in the Kubelet's
// Pod Lifecycle Event Generator (PLEG). // Pod Lifecycle Event Generator (PLEG).
PLEGDiscardEvents = prometheus.NewCounterVec( PLEGDiscardEvents = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PLEGDiscardEventsKey, Name: PLEGDiscardEventsKey,
Help: "The number of discard events in PLEG.", Help: "The number of discard events in PLEG.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{}, []string{},
) )
// PLEGRelistInterval is a Histogram that tracks the intervals (in seconds) between relisting in the Kubelet's // PLEGRelistInterval is a Histogram that tracks the intervals (in seconds) between relisting in the Kubelet's
// Pod Lifecycle Event Generator (PLEG). // Pod Lifecycle Event Generator (PLEG).
PLEGRelistInterval = prometheus.NewHistogram( PLEGRelistInterval = metrics.NewHistogram(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: PLEGRelistIntervalKey, Name: PLEGRelistIntervalKey,
Help: "Interval in seconds between relisting in PLEG.", Help: "Interval in seconds between relisting in PLEG.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
) )
// RuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations. // RuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations.
// Broken down by operation type. // Broken down by operation type.
RuntimeOperations = prometheus.NewCounterVec( RuntimeOperations = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: RuntimeOperationsKey, Name: RuntimeOperationsKey,
Help: "Cumulative number of runtime operations by operation type.", Help: "Cumulative number of runtime operations by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// RuntimeOperationsDuration is a Histogram that tracks the duration (in seconds) for remote runtime operations to complete. // RuntimeOperationsDuration is a Histogram that tracks the duration (in seconds) for remote runtime operations to complete.
// Broken down by operation type. // Broken down by operation type.
RuntimeOperationsDuration = prometheus.NewHistogramVec( RuntimeOperationsDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: RuntimeOperationsDurationKey, Name: RuntimeOperationsDurationKey,
Help: "Duration in seconds of runtime operations. Broken down by operation type.", Help: "Duration in seconds of runtime operations. Broken down by operation type.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// RuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operations errors. // RuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operations errors.
// Broken down by operation type. // Broken down by operation type.
RuntimeOperationsErrors = prometheus.NewCounterVec( RuntimeOperationsErrors = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: RuntimeOperationsErrorsKey, Name: RuntimeOperationsErrorsKey,
Help: "Cumulative number of runtime operation errors by operation type.", Help: "Cumulative number of runtime operation errors by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// Evictions is a Counter that tracks the cumulative number of pod evictions initiated by the kubelet. // Evictions is a Counter that tracks the cumulative number of pod evictions initiated by the kubelet.
// Broken down by eviction signal. // Broken down by eviction signal.
Evictions = prometheus.NewCounterVec( Evictions = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: EvictionsKey, Name: EvictionsKey,
Help: "Cumulative number of pod evictions by eviction signal", Help: "Cumulative number of pod evictions by eviction signal",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"eviction_signal"}, []string{"eviction_signal"},
) )
// EvictionStatsAge is a Histogram that tracks the time (in seconds) between when stats are collected and when a pod is evicted // EvictionStatsAge is a Histogram that tracks the time (in seconds) between when stats are collected and when a pod is evicted
// based on those stats. Broken down by eviction signal. // based on those stats. Broken down by eviction signal.
EvictionStatsAge = prometheus.NewHistogramVec( EvictionStatsAge = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: EvictionStatsAgeKey, Name: EvictionStatsAgeKey,
Help: "Time between when stats are collected, and when pod is evicted based on those stats by eviction signal", Help: "Time between when stats are collected, and when pod is evicted based on those stats by eviction signal",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"eviction_signal"}, []string{"eviction_signal"},
) )
// DevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations. // DevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations.
// Broken down by resource name. // Broken down by resource name.
DevicePluginRegistrationCount = prometheus.NewCounterVec( DevicePluginRegistrationCount = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DevicePluginRegistrationCountKey, Name: DevicePluginRegistrationCountKey,
Help: "Cumulative number of device plugin registrations. Broken down by resource name.", Help: "Cumulative number of device plugin registrations. Broken down by resource name.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// DevicePluginAllocationDuration is a Histogram that tracks the duration (in seconds) to serve a device plugin allocation request. // DevicePluginAllocationDuration is a Histogram that tracks the duration (in seconds) to serve a device plugin allocation request.
// Broken down by resource name. // Broken down by resource name.
DevicePluginAllocationDuration = prometheus.NewHistogramVec( DevicePluginAllocationDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DevicePluginAllocationDurationKey, Name: DevicePluginAllocationDurationKey,
Help: "Duration in seconds to serve a device plugin Allocation request. Broken down by resource name.", Help: "Duration in seconds to serve a device plugin Allocation request. Broken down by resource name.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// DeprecatedPodWorkerLatency is a Summary that tracks the latency (in microseconds) to sync a single pod. // DeprecatedPodWorkerLatency is a Summary that tracks the latency (in microseconds) to sync a single pod.
// Broken down by operation type. This metric is deprecated. // Broken down by operation type. This metric is deprecated.
DeprecatedPodWorkerLatency = prometheus.NewSummaryVec( DeprecatedPodWorkerLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedPodWorkerLatencyKey, Name: DeprecatedPodWorkerLatencyKey,
Help: "(Deprecated) Latency in microseconds to sync a single pod. Broken down by operation type: create, update, or sync", Help: "(Deprecated) Latency in microseconds to sync a single pod. Broken down by operation type: create, update, or sync",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedPodStartLatency is a Summary that tracks the latency (in microseconds) for a single pod to go from pending to running. // DeprecatedPodStartLatency is a Summary that tracks the latency (in microseconds) for a single pod to go from pending to running.
// This metric is deprecated. // This metric is deprecated.
DeprecatedPodStartLatency = prometheus.NewSummary( DeprecatedPodStartLatency = metrics.NewSummary(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedPodStartLatencyKey, Name: DeprecatedPodStartLatencyKey,
Help: "(Deprecated) Latency in microseconds for a single pod to go from pending to running.", Help: "(Deprecated) Latency in microseconds for a single pod to go from pending to running.",
StabilityLevel: metrics.ALPHA,
}, },
) )
// DeprecatedCgroupManagerLatency is a Summary that tracks the latency (in microseconds) for cgroup manager operations to complete. // DeprecatedCgroupManagerLatency is a Summary that tracks the latency (in microseconds) for cgroup manager operations to complete.
// Broken down by operation type. This metric is deprecated. // Broken down by operation type. This metric is deprecated.
DeprecatedCgroupManagerLatency = prometheus.NewSummaryVec( DeprecatedCgroupManagerLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedCgroupManagerOperationsKey, Name: DeprecatedCgroupManagerOperationsKey,
Help: "(Deprecated) Latency in microseconds for cgroup manager operations. Broken down by method.", Help: "(Deprecated) Latency in microseconds for cgroup manager operations. Broken down by method.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedPodWorkerStartLatency is a Summary that tracks the latency (in microseconds) from seeing a pod to starting a worker. // DeprecatedPodWorkerStartLatency is a Summary that tracks the latency (in microseconds) from seeing a pod to starting a worker.
// This metric is deprecated. // This metric is deprecated.
DeprecatedPodWorkerStartLatency = prometheus.NewSummary( DeprecatedPodWorkerStartLatency = metrics.NewSummary(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedPodWorkerStartLatencyKey, Name: DeprecatedPodWorkerStartLatencyKey,
Help: "(Deprecated) Latency in microseconds from seeing a pod to starting a worker.", Help: "(Deprecated) Latency in microseconds from seeing a pod to starting a worker.",
StabilityLevel: metrics.ALPHA,
}, },
) )
// DeprecatedPLEGRelistLatency is a Summary that tracks the latency (in microseconds) for relisting pods in PLEG. // DeprecatedPLEGRelistLatency is a Summary that tracks the latency (in microseconds) for relisting pods in PLEG.
// This metric is deprecated. // This metric is deprecated.
DeprecatedPLEGRelistLatency = prometheus.NewSummary( DeprecatedPLEGRelistLatency = metrics.NewSummary(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedPLEGRelistLatencyKey, Name: DeprecatedPLEGRelistLatencyKey,
Help: "(Deprecated) Latency in microseconds for relisting pods in PLEG.", Help: "(Deprecated) Latency in microseconds for relisting pods in PLEG.",
StabilityLevel: metrics.ALPHA,
}, },
) )
// DeprecatedPLEGRelistInterval is a Summary that tracks the interval (in microseconds) between relistings in PLEG. // DeprecatedPLEGRelistInterval is a Summary that tracks the interval (in microseconds) between relistings in PLEG.
// This metric is deprecated. // This metric is deprecated.
DeprecatedPLEGRelistInterval = prometheus.NewSummary( DeprecatedPLEGRelistInterval = metrics.NewSummary(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedPLEGRelistIntervalKey, Name: DeprecatedPLEGRelistIntervalKey,
Help: "(Deprecated) Interval in microseconds between relisting in PLEG.", Help: "(Deprecated) Interval in microseconds between relisting in PLEG.",
StabilityLevel: metrics.ALPHA,
}, },
) )
// DeprecatedRuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations. // DeprecatedRuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations.
// Broken down by operation type. This metric is deprecated. // Broken down by operation type. This metric is deprecated.
DeprecatedRuntimeOperations = prometheus.NewCounterVec( DeprecatedRuntimeOperations = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedRuntimeOperationsKey, Name: DeprecatedRuntimeOperationsKey,
Help: "(Deprecated) Cumulative number of runtime operations by operation type.", Help: "(Deprecated) Cumulative number of runtime operations by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedRuntimeOperationsLatency is a Summary that tracks the latency (in microseconds) of remote runtime operations // DeprecatedRuntimeOperationsLatency is a Summary that tracks the latency (in microseconds) of remote runtime operations
// to complete. Broken down by operation type. This metric is deprecated. // to complete. Broken down by operation type. This metric is deprecated.
DeprecatedRuntimeOperationsLatency = prometheus.NewSummaryVec( DeprecatedRuntimeOperationsLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedRuntimeOperationsLatencyKey, Name: DeprecatedRuntimeOperationsLatencyKey,
Help: "(Deprecated) Latency in microseconds of runtime operations. Broken down by operation type.", Help: "(Deprecated) Latency in microseconds of runtime operations. Broken down by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedRuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operation errors. // DeprecatedRuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operation errors.
// Broken down by operation type. This metric is deprecated. // Broken down by operation type. This metric is deprecated.
DeprecatedRuntimeOperationsErrors = prometheus.NewCounterVec( DeprecatedRuntimeOperationsErrors = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedRuntimeOperationsErrorsKey, Name: DeprecatedRuntimeOperationsErrorsKey,
Help: "(Deprecated) Cumulative number of runtime operation errors by operation type.", Help: "(Deprecated) Cumulative number of runtime operation errors by operation type.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedEvictionStatsAge is a Summary that tracks the time (in microseconds) between when stats are collected and when a pod // DeprecatedEvictionStatsAge is a Summary that tracks the time (in microseconds) between when stats are collected and when a pod
// is evicted based on those stats. Broken down by eviction signal. This metric is deprecated. // is evicted based on those stats. Broken down by eviction signal. This metric is deprecated.
DeprecatedEvictionStatsAge = prometheus.NewSummaryVec( DeprecatedEvictionStatsAge = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedEvictionStatsAgeKey, Name: DeprecatedEvictionStatsAgeKey,
Help: "(Deprecated) Time between when stats are collected, and when pod is evicted based on those stats by eviction signal", Help: "(Deprecated) Time between when stats are collected, and when pod is evicted based on those stats by eviction signal",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"eviction_signal"}, []string{"eviction_signal"},
) )
// DeprecatedDevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations. // DeprecatedDevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations.
// Broken down by resource name. This metric is deprecated. // Broken down by resource name. This metric is deprecated.
DeprecatedDevicePluginRegistrationCount = prometheus.NewCounterVec( DeprecatedDevicePluginRegistrationCount = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedDevicePluginRegistrationCountKey, Name: DeprecatedDevicePluginRegistrationCountKey,
Help: "(Deprecated) Cumulative number of device plugin registrations. Broken down by resource name.", Help: "(Deprecated) Cumulative number of device plugin registrations. Broken down by resource name.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// DeprecatedDevicePluginAllocationLatency is a Summary that tracks the latncy (in microseconds) for serving device plugin allocation requests. // DeprecatedDevicePluginAllocationLatency is a Summary that tracks the latncy (in microseconds) for serving device plugin allocation requests.
// Broken down by resource name. This metric is deprecated. // Broken down by resource name. This metric is deprecated.
DeprecatedDevicePluginAllocationLatency = prometheus.NewSummaryVec( DeprecatedDevicePluginAllocationLatency = metrics.NewSummaryVec(
prometheus.SummaryOpts{ &metrics.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: DeprecatedDevicePluginAllocationLatencyKey, Name: DeprecatedDevicePluginAllocationLatencyKey,
Help: "(Deprecated) Latency in microseconds to serve a device plugin Allocation request. Broken down by resource name.", Help: "(Deprecated) Latency in microseconds to serve a device plugin Allocation request. Broken down by resource name.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
@ -368,60 +398,66 @@ var (
// Metrics for node config // Metrics for node config
// AssignedConfig is a Gauge that is set 1 if the Kubelet has a NodeConfig assigned. // AssignedConfig is a Gauge that is set 1 if the Kubelet has a NodeConfig assigned.
AssignedConfig = prometheus.NewGaugeVec( AssignedConfig = metrics.NewGaugeVec(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: AssignedConfigKey, Name: AssignedConfigKey,
Help: "The node's understanding of intended config. The count is always 1.", Help: "The node's understanding of intended config. The count is always 1.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey}, []string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
) )
// ActiveConfig is a Gauge that is set to 1 if the Kubelet has an active NodeConfig. // ActiveConfig is a Gauge that is set to 1 if the Kubelet has an active NodeConfig.
ActiveConfig = prometheus.NewGaugeVec( ActiveConfig = metrics.NewGaugeVec(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: ActiveConfigKey, Name: ActiveConfigKey,
Help: "The config source the node is actively using. The count is always 1.", Help: "The config source the node is actively using. The count is always 1.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey}, []string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
) )
// LastKnownGoodConfig is a Gauge that is set to 1 if the Kubelet has a NodeConfig it can fall back to if there // LastKnownGoodConfig is a Gauge that is set to 1 if the Kubelet has a NodeConfig it can fall back to if there
// are certain errors. // are certain errors.
LastKnownGoodConfig = prometheus.NewGaugeVec( LastKnownGoodConfig = metrics.NewGaugeVec(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: LastKnownGoodConfigKey, Name: LastKnownGoodConfigKey,
Help: "The config source the node will fall back to when it encounters certain errors. The count is always 1.", Help: "The config source the node will fall back to when it encounters certain errors. The count is always 1.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey}, []string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
) )
// ConfigError is a Gauge that is set to 1 if the node is experiencing a configuration-related error. // ConfigError is a Gauge that is set to 1 if the node is experiencing a configuration-related error.
ConfigError = prometheus.NewGauge( ConfigError = metrics.NewGauge(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: ConfigErrorKey, Name: ConfigErrorKey,
Help: "This metric is true (1) if the node is experiencing a configuration-related error, false (0) otherwise.", Help: "This metric is true (1) if the node is experiencing a configuration-related error, false (0) otherwise.",
StabilityLevel: metrics.ALPHA,
}, },
) )
// RunPodSandboxDuration is a Histogram that tracks the duration (in seconds) it takes to run Pod Sandbox operations. // RunPodSandboxDuration is a Histogram that tracks the duration (in seconds) it takes to run Pod Sandbox operations.
// Broken down by RuntimeClass. // Broken down by RuntimeClass.
RunPodSandboxDuration = prometheus.NewHistogramVec( RunPodSandboxDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: RunPodSandboxDurationKey, Name: RunPodSandboxDurationKey,
Help: "Duration in seconds of the run_podsandbox operations. Broken down by RuntimeClass.", Help: "Duration in seconds of the run_podsandbox operations. Broken down by RuntimeClass.",
// Use DefBuckets for now, will customize the buckets if necessary. // Use DefBuckets for now, will customize the buckets if necessary.
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"runtime_handler"}, []string{"runtime_handler"},
) )
// RunPodSandboxErrors is a Counter that tracks the cumulative number of Pod Sandbox operations errors. // RunPodSandboxErrors is a Counter that tracks the cumulative number of Pod Sandbox operations errors.
// Broken down by RuntimeClass. // Broken down by RuntimeClass.
RunPodSandboxErrors = prometheus.NewCounterVec( RunPodSandboxErrors = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
Name: RunPodSandboxErrorsKey, Name: RunPodSandboxErrorsKey,
Help: "Cumulative number of the run_podsandbox operation errors by RuntimeClass.", Help: "Cumulative number of the run_podsandbox operation errors by RuntimeClass.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"runtime_handler"}, []string{"runtime_handler"},
) )
@ -433,43 +469,43 @@ var registerMetrics sync.Once
func Register(containerCache kubecontainer.RuntimeCache, collectors ...prometheus.Collector) { func Register(containerCache kubecontainer.RuntimeCache, collectors ...prometheus.Collector) {
// Register the metrics. // Register the metrics.
registerMetrics.Do(func() { registerMetrics.Do(func() {
prometheus.MustRegister(NodeName) legacyregistry.MustRegister(NodeName)
prometheus.MustRegister(PodWorkerDuration) legacyregistry.MustRegister(PodWorkerDuration)
prometheus.MustRegister(PodStartDuration) legacyregistry.MustRegister(PodStartDuration)
prometheus.MustRegister(CgroupManagerDuration) legacyregistry.MustRegister(CgroupManagerDuration)
prometheus.MustRegister(PodWorkerStartDuration) legacyregistry.MustRegister(PodWorkerStartDuration)
prometheus.MustRegister(ContainersPerPodCount) legacyregistry.MustRegister(ContainersPerPodCount)
prometheus.MustRegister(newPodAndContainerCollector(containerCache)) legacyregistry.RawMustRegister(newPodAndContainerCollector(containerCache))
prometheus.MustRegister(PLEGRelistDuration) legacyregistry.MustRegister(PLEGRelistDuration)
prometheus.MustRegister(PLEGDiscardEvents) legacyregistry.MustRegister(PLEGDiscardEvents)
prometheus.MustRegister(PLEGRelistInterval) legacyregistry.MustRegister(PLEGRelistInterval)
prometheus.MustRegister(RuntimeOperations) legacyregistry.MustRegister(RuntimeOperations)
prometheus.MustRegister(RuntimeOperationsDuration) legacyregistry.MustRegister(RuntimeOperationsDuration)
prometheus.MustRegister(RuntimeOperationsErrors) legacyregistry.MustRegister(RuntimeOperationsErrors)
prometheus.MustRegister(Evictions) legacyregistry.MustRegister(Evictions)
prometheus.MustRegister(EvictionStatsAge) legacyregistry.MustRegister(EvictionStatsAge)
prometheus.MustRegister(DevicePluginRegistrationCount) legacyregistry.MustRegister(DevicePluginRegistrationCount)
prometheus.MustRegister(DevicePluginAllocationDuration) legacyregistry.MustRegister(DevicePluginAllocationDuration)
prometheus.MustRegister(DeprecatedPodWorkerLatency) legacyregistry.MustRegister(DeprecatedPodWorkerLatency)
prometheus.MustRegister(DeprecatedPodStartLatency) legacyregistry.MustRegister(DeprecatedPodStartLatency)
prometheus.MustRegister(DeprecatedCgroupManagerLatency) legacyregistry.MustRegister(DeprecatedCgroupManagerLatency)
prometheus.MustRegister(DeprecatedPodWorkerStartLatency) legacyregistry.MustRegister(DeprecatedPodWorkerStartLatency)
prometheus.MustRegister(DeprecatedPLEGRelistLatency) legacyregistry.MustRegister(DeprecatedPLEGRelistLatency)
prometheus.MustRegister(DeprecatedPLEGRelistInterval) legacyregistry.MustRegister(DeprecatedPLEGRelistInterval)
prometheus.MustRegister(DeprecatedRuntimeOperations) legacyregistry.MustRegister(DeprecatedRuntimeOperations)
prometheus.MustRegister(DeprecatedRuntimeOperationsLatency) legacyregistry.MustRegister(DeprecatedRuntimeOperationsLatency)
prometheus.MustRegister(DeprecatedRuntimeOperationsErrors) legacyregistry.MustRegister(DeprecatedRuntimeOperationsErrors)
prometheus.MustRegister(DeprecatedEvictionStatsAge) legacyregistry.MustRegister(DeprecatedEvictionStatsAge)
prometheus.MustRegister(DeprecatedDevicePluginRegistrationCount) legacyregistry.MustRegister(DeprecatedDevicePluginRegistrationCount)
prometheus.MustRegister(DeprecatedDevicePluginAllocationLatency) legacyregistry.MustRegister(DeprecatedDevicePluginAllocationLatency)
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) { if utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
prometheus.MustRegister(AssignedConfig) legacyregistry.MustRegister(AssignedConfig)
prometheus.MustRegister(ActiveConfig) legacyregistry.MustRegister(ActiveConfig)
prometheus.MustRegister(LastKnownGoodConfig) legacyregistry.MustRegister(LastKnownGoodConfig)
prometheus.MustRegister(ConfigError) legacyregistry.MustRegister(ConfigError)
} }
for _, collector := range collectors { for _, collector := range collectors {
prometheus.MustRegister(collector) legacyregistry.RawMustRegister(collector)
} }
}) })
} }

View File

@ -32,6 +32,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library", "//vendor/k8s.io/utils/exec:go_default_library",

View File

@ -19,12 +19,12 @@ package prober
import ( import (
"sync" "sync"
"github.com/prometheus/client_golang/prometheus"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/component-base/metrics"
"k8s.io/klog" "k8s.io/klog"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/prober/results" "k8s.io/kubernetes/pkg/kubelet/prober/results"
@ -33,11 +33,12 @@ import (
) )
// ProberResults stores the cumulative number of a probe by result as prometheus metrics. // ProberResults stores the cumulative number of a probe by result as prometheus metrics.
var ProberResults = prometheus.NewCounterVec( var ProberResults = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: "prober", Subsystem: "prober",
Name: "probe_total", Name: "probe_total",
Help: "Cumulative number of a liveness or readiness probe for a container by result.", Help: "Cumulative number of a liveness or readiness probe for a container by result.",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"probe_type", []string{"probe_type",
"result", "result",

View File

@ -47,6 +47,7 @@ go_library(
"//staging/src/k8s.io/apiserver/pkg/util/flushwriter:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/flushwriter:go_default_library",
"//staging/src/k8s.io/component-base/logs:go_default_library", "//staging/src/k8s.io/component-base/logs:go_default_library",
"//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/legacyregistry:go_default_library",
"//vendor/github.com/emicklei/go-restful:go_default_library", "//vendor/github.com/emicklei/go-restful:go_default_library",
"//vendor/github.com/google/cadvisor/container:go_default_library", "//vendor/github.com/google/cadvisor/container:go_default_library",
"//vendor/github.com/google/cadvisor/info/v1:go_default_library", "//vendor/github.com/google/cadvisor/info/v1:go_default_library",

View File

@ -10,6 +10,8 @@ go_library(
srcs = ["metrics.go"], srcs = ["metrics.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/server/metrics", importpath = "k8s.io/kubernetes/pkg/kubelet/server/metrics",
deps = [ deps = [
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
], ],
) )

View File

@ -21,6 +21,9 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
) )
const ( const (
@ -29,11 +32,12 @@ const (
var ( var (
// HTTPRequests tracks the number of the http requests received since the server started. // HTTPRequests tracks the number of the http requests received since the server started.
HTTPRequests = prometheus.NewCounterVec( HTTPRequests = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: "http_requests_total", Name: "http_requests_total",
Help: "Number of the http requests received since the server started", Help: "Number of the http requests received since the server started",
StabilityLevel: metrics.ALPHA,
}, },
// server_type aims to differentiate the readonly server and the readwrite server. // server_type aims to differentiate the readonly server and the readwrite server.
// long_running marks whether the request is long-running or not. // long_running marks whether the request is long-running or not.
@ -41,22 +45,24 @@ var (
[]string{"method", "path", "server_type", "long_running"}, []string{"method", "path", "server_type", "long_running"},
) )
// HTTPRequestsDuration tracks the duration in seconds to serve http requests. // HTTPRequestsDuration tracks the duration in seconds to serve http requests.
HTTPRequestsDuration = prometheus.NewHistogramVec( HTTPRequestsDuration = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: "http_requests_duration_seconds", Name: "http_requests_duration_seconds",
Help: "Duration in seconds to serve http requests", Help: "Duration in seconds to serve http requests",
// Use DefBuckets for now, will customize the buckets if necessary. // Use DefBuckets for now, will customize the buckets if necessary.
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
StabilityLevel: metrics.ALPHA,
}, },
[]string{"method", "path", "server_type", "long_running"}, []string{"method", "path", "server_type", "long_running"},
) )
// HTTPInflightRequests tracks the number of the inflight http requests. // HTTPInflightRequests tracks the number of the inflight http requests.
HTTPInflightRequests = prometheus.NewGaugeVec( HTTPInflightRequests = metrics.NewGaugeVec(
prometheus.GaugeOpts{ &metrics.GaugeOpts{
Subsystem: kubeletSubsystem, Subsystem: kubeletSubsystem,
Name: "http_inflight_requests", Name: "http_inflight_requests",
Help: "Number of the inflight http requests", Help: "Number of the inflight http requests",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"method", "path", "server_type", "long_running"}, []string{"method", "path", "server_type", "long_running"},
) )
@ -67,9 +73,9 @@ var registerMetrics sync.Once
// Register all metrics. // Register all metrics.
func Register() { func Register() {
registerMetrics.Do(func() { registerMetrics.Do(func() {
prometheus.MustRegister(HTTPRequests) legacyregistry.MustRegister(HTTPRequests)
prometheus.MustRegister(HTTPRequestsDuration) legacyregistry.MustRegister(HTTPRequestsDuration)
prometheus.MustRegister(HTTPInflightRequests) legacyregistry.MustRegister(HTTPInflightRequests)
}) })
} }

View File

@ -32,7 +32,7 @@ import (
"strings" "strings"
"time" "time"
restful "github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
cadvisormetrics "github.com/google/cadvisor/container" cadvisormetrics "github.com/google/cadvisor/container"
cadvisorapi "github.com/google/cadvisor/info/v1" cadvisorapi "github.com/google/cadvisor/info/v1"
"github.com/google/cadvisor/metrics" "github.com/google/cadvisor/metrics"
@ -56,6 +56,7 @@ import (
"k8s.io/apiserver/pkg/util/flushwriter" "k8s.io/apiserver/pkg/util/flushwriter"
"k8s.io/component-base/logs" "k8s.io/component-base/logs"
compbasemetrics "k8s.io/component-base/metrics" compbasemetrics "k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core/v1/validation" "k8s.io/kubernetes/pkg/apis/core/v1/validation"
@ -297,7 +298,7 @@ func (s *Server) InstallDefaultHandlers(enableCAdvisorJSONEndpoints bool) {
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer, enableCAdvisorJSONEndpoints)) s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer, enableCAdvisorJSONEndpoints))
//lint:ignore SA1019 https://github.com/kubernetes/enhancements/issues/1206 //lint:ignore SA1019 https://github.com/kubernetes/enhancements/issues/1206
s.restfulCont.Handle(metricsPath, prometheus.Handler()) s.restfulCont.Handle(metricsPath, legacyregistry.Handler())
// cAdvisor metrics are exposed under the secured handler as well // cAdvisor metrics are exposed under the secured handler as well
r := prometheus.NewRegistry() r := prometheus.NewRegistry()
@ -325,8 +326,9 @@ func (s *Server) InstallDefaultHandlers(enableCAdvisorJSONEndpoints bool) {
) )
// prober metrics are exposed under a different endpoint // prober metrics are exposed under a different endpoint
p := prometheus.NewRegistry()
compbasemetrics.RegisterProcessStartTime(p) p := compbasemetrics.NewKubeRegistry()
compbasemetrics.RegisterProcessStartTime(p.RawRegister)
p.MustRegister(prober.ProberResults) p.MustRegister(prober.ProberResults)
s.restfulCont.Handle(proberMetricsPath, s.restfulCont.Handle(proberMetricsPath,
promhttp.HandlerFor(p, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}), promhttp.HandlerFor(p, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}),

View File

@ -9,6 +9,7 @@ go_library(
"//pkg/kubelet/volumemanager/cache:go_default_library", "//pkg/kubelet/volumemanager/cache:go_default_library",
"//pkg/volume:go_default_library", "//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library", "//pkg/volume/util:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
], ],

View File

@ -17,6 +17,7 @@ limitations under the License.
package metrics package metrics
import ( import (
"k8s.io/component-base/metrics/legacyregistry"
"sync" "sync"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -59,7 +60,7 @@ func (v volumeCount) add(state, plugin string) {
// Register registers Volume Manager metrics. // Register registers Volume Manager metrics.
func Register(asw cache.ActualStateOfWorld, dsw cache.DesiredStateOfWorld, pluginMgr *volume.VolumePluginMgr) { func Register(asw cache.ActualStateOfWorld, dsw cache.DesiredStateOfWorld, pluginMgr *volume.VolumePluginMgr) {
registerMetrics.Do(func() { registerMetrics.Do(func() {
prometheus.MustRegister(&totalVolumesCollector{asw, dsw, pluginMgr}) legacyregistry.RawMustRegister(&totalVolumesCollector{asw, dsw, pluginMgr})
}) })
} }

View File

@ -41,7 +41,8 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/strings:go_default_library", "//vendor/k8s.io/utils/strings:go_default_library",
], ],

View File

@ -20,7 +20,8 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/prometheus/client_golang/prometheus" "k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
) )
@ -29,36 +30,48 @@ const (
statusFailUnknown = "fail-unknown" statusFailUnknown = "fail-unknown"
) )
var storageOperationMetric = prometheus.NewHistogramVec( /*
prometheus.HistogramOpts{ * By default, all the following metrics are defined as falling under
Name: "storage_operation_duration_seconds", * ALPHA stability level https://github.com/kubernetes/enhancements/blob/master/keps/sig-instrumentation/20190404-kubernetes-control-plane-metrics-stability.md#stability-classes)
Help: "Storage operation duration", *
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 25, 50, 120, 300, 600}, * Promoting the stability level of the metric is a responsibility of the component owner, since it
* involves explicitly acknowledging support for the metric across multiple releases, in accordance with
* the metric stability policy.
*/
var storageOperationMetric = metrics.NewHistogramVec(
&metrics.HistogramOpts{
Name: "storage_operation_duration_seconds",
Help: "Storage operation duration",
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 25, 50, 120, 300, 600},
StabilityLevel: metrics.ALPHA,
}, },
[]string{"volume_plugin", "operation_name"}, []string{"volume_plugin", "operation_name"},
) )
var storageOperationErrorMetric = prometheus.NewCounterVec( var storageOperationErrorMetric = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Name: "storage_operation_errors_total", Name: "storage_operation_errors_total",
Help: "Storage operation errors", Help: "Storage operation errors",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"volume_plugin", "operation_name"}, []string{"volume_plugin", "operation_name"},
) )
var storageOperationStatusMetric = prometheus.NewCounterVec( var storageOperationStatusMetric = metrics.NewCounterVec(
prometheus.CounterOpts{ &metrics.CounterOpts{
Name: "storage_operation_status_count", Name: "storage_operation_status_count",
Help: "Storage operation return statuses count", Help: "Storage operation return statuses count",
StabilityLevel: metrics.ALPHA,
}, },
[]string{"volume_plugin", "operation_name", "status"}, []string{"volume_plugin", "operation_name", "status"},
) )
var storageOperationEndToEndLatencyMetric = prometheus.NewHistogramVec( var storageOperationEndToEndLatencyMetric = metrics.NewHistogramVec(
prometheus.HistogramOpts{ &metrics.HistogramOpts{
Name: "volume_operation_total_seconds", Name: "volume_operation_total_seconds",
Help: "Storage operation end to end duration in seconds", Help: "Storage operation end to end duration in seconds",
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 25, 50, 120, 300, 600}, Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 25, 50, 120, 300, 600},
StabilityLevel: metrics.ALPHA,
}, },
[]string{"plugin_name", "operation_name"}, []string{"plugin_name", "operation_name"},
) )
@ -68,10 +81,12 @@ func init() {
} }
func registerMetrics() { func registerMetrics() {
prometheus.MustRegister(storageOperationMetric) // legacyregistry is the internal k8s wrapper around the prometheus
prometheus.MustRegister(storageOperationErrorMetric) // global registry, used specifically for metric stability enforcement
prometheus.MustRegister(storageOperationStatusMetric) legacyregistry.MustRegister(storageOperationMetric)
prometheus.MustRegister(storageOperationEndToEndLatencyMetric) legacyregistry.MustRegister(storageOperationErrorMetric)
legacyregistry.MustRegister(storageOperationStatusMetric)
legacyregistry.MustRegister(storageOperationEndToEndLatencyMetric)
} }
// OperationCompleteHook returns a hook to call when an operation is completed // OperationCompleteHook returns a hook to call when an operation is completed

View File

@ -65,8 +65,8 @@ go_test(
"//staging/src/k8s.io/client-go/tools/record:go_default_library", "//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//staging/src/k8s.io/component-base/featuregate:go_default_library", "//staging/src/k8s.io/component-base/featuregate:go_default_library",
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library", "//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
"//staging/src/k8s.io/csi-translation-lib/plugins:go_default_library", "//staging/src/k8s.io/csi-translation-lib/plugins:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus: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/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",
], ],

View File

@ -18,7 +18,6 @@ package operationexecutor
import ( import (
"fmt" "fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_model/go" "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -30,6 +29,7 @@ import (
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/component-base/featuregate" "k8s.io/component-base/featuregate"
featuregatetesting "k8s.io/component-base/featuregate/testing" featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/csi-translation-lib/plugins" "k8s.io/csi-translation-lib/plugins"
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
@ -229,7 +229,7 @@ func getTestVolumeToUnmount(pod *v1.Pod, pvSpec v1.PersistentVolumeSpec, pluginN
} }
func getMetricFamily(metricFamilyName string) *io_prometheus_client.MetricFamily { func getMetricFamily(metricFamilyName string) *io_prometheus_client.MetricFamily {
metricFamilies, _ := prometheus.DefaultGatherer.Gather() metricFamilies, _ := legacyregistry.DefaultGatherer.Gather()
for _, mf := range metricFamilies { for _, mf := range metricFamilies {
if *mf.Name == metricFamilyName { if *mf.Name == metricFamilyName {
return mf return mf

View File

@ -32,17 +32,22 @@ var processStartTime = prometheus.NewGaugeVec(
[]string{}, []string{},
) )
// Registerer is an interface expected by RegisterProcessStartTime in order to register the metric
type Registerer interface {
Register(prometheus.Collector) error
}
// RegisterProcessStartTime registers the process_start_time_seconds to // RegisterProcessStartTime registers the process_start_time_seconds to
// a prometheus registry. This metric needs to be included to ensure counter // a prometheus registry. This metric needs to be included to ensure counter
// data fidelity. // data fidelity.
func RegisterProcessStartTime(registerer prometheus.Registerer) error { func RegisterProcessStartTime(registrationFunc func(prometheus.Collector) error) error {
start, err := getProcessStart() start, err := getProcessStart()
if err != nil { if err != nil {
klog.Errorf("Could not get process start time, %v", err) klog.Errorf("Could not get process start time, %v", err)
start = float64(time.Now().Unix()) start = float64(time.Now().Unix())
} }
processStartTime.WithLabelValues().Set(start) processStartTime.WithLabelValues().Set(start)
return registerer.Register(processStartTime) return registrationFunc(processStartTime)
} }
func getProcessStart() (float64, error) { func getProcessStart() (float64, error) {

View File

@ -32,6 +32,6 @@ var (
// RegisterBuildInfo registers the build and version info in a metadata metric in prometheus // RegisterBuildInfo registers the build and version info in a metadata metric in prometheus
func RegisterBuildInfo(r KubeRegistry) { func RegisterBuildInfo(r KubeRegistry) {
info := version.Get() info := version.Get()
buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
r.MustRegister(buildInfo) r.MustRegister(buildInfo)
buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
} }