mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
migrate kube-proxy metrics to stability framework
This commit is contained in:
parent
8b4fd4104d
commit
0895ac212d
@ -20,10 +20,9 @@ go_library(
|
||||
importpath = "k8s.io/kubernetes/cmd/kube-proxy",
|
||||
deps = [
|
||||
"//cmd/kube-proxy/app:go_default_library",
|
||||
"//pkg/client/metrics/prometheus:go_default_library",
|
||||
"//pkg/version/prometheus:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/logs:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/prometheus/restclient:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -61,9 +61,9 @@ go_library(
|
||||
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/config:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
|
||||
"//staging/src/k8s.io/kube-proxy/config/v1alpha1:go_default_library",
|
||||
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
|
||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"net/http"
|
||||
"os"
|
||||
goruntime "runtime"
|
||||
@ -74,7 +75,6 @@ import (
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/klog"
|
||||
@ -549,7 +549,7 @@ func (s *ProxyServer) Run() error {
|
||||
proxyMux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s", s.ProxyMode)
|
||||
})
|
||||
proxyMux.Handle("/metrics", prometheus.Handler())
|
||||
proxyMux.Handle("/metrics", legacyregistry.Handler())
|
||||
if s.EnableProfiling {
|
||||
routes.Profiling{}.Install(proxyMux)
|
||||
}
|
||||
|
@ -26,9 +26,8 @@ import (
|
||||
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
"k8s.io/component-base/logs"
|
||||
_ "k8s.io/component-base/metrics/prometheus/restclient" // for client metric registration
|
||||
"k8s.io/kubernetes/cmd/kube-proxy/app"
|
||||
_ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration
|
||||
_ "k8s.io/kubernetes/pkg/version/prometheus" // for version metric registration
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -5,7 +5,11 @@ go_library(
|
||||
srcs = ["metrics.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/dockershim/network/metrics",
|
||||
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(
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -38,23 +40,25 @@ const (
|
||||
var (
|
||||
// NetworkPluginOperationsLatency collects operation latency numbers by operation
|
||||
// type.
|
||||
NetworkPluginOperationsLatency = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Subsystem: kubeletSubsystem,
|
||||
Name: NetworkPluginOperationsLatencyKey,
|
||||
Help: "Latency in seconds of network plugin operations. Broken down by operation type.",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
NetworkPluginOperationsLatency = metrics.NewHistogramVec(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeletSubsystem,
|
||||
Name: NetworkPluginOperationsLatencyKey,
|
||||
Help: "Latency in seconds of network plugin operations. Broken down by operation type.",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"operation_type"},
|
||||
)
|
||||
|
||||
// DeprecatedNetworkPluginOperationsLatency collects operation latency numbers by operation
|
||||
// type.
|
||||
DeprecatedNetworkPluginOperationsLatency = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Subsystem: kubeletSubsystem,
|
||||
Name: DeprecatedNetworkPluginOperationsLatencyKey,
|
||||
Help: "(Deprecated) Latency in microseconds of network plugin operations. Broken down by operation type.",
|
||||
DeprecatedNetworkPluginOperationsLatency = metrics.NewSummaryVec(
|
||||
&metrics.SummaryOpts{
|
||||
Subsystem: kubeletSubsystem,
|
||||
Name: DeprecatedNetworkPluginOperationsLatencyKey,
|
||||
Help: "(Deprecated) Latency in microseconds of network plugin operations. Broken down by operation type.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"operation_type"},
|
||||
)
|
||||
@ -65,8 +69,8 @@ var registerMetrics sync.Once
|
||||
// Register all metrics.
|
||||
func Register() {
|
||||
registerMetrics.Do(func() {
|
||||
prometheus.MustRegister(NetworkPluginOperationsLatency)
|
||||
prometheus.MustRegister(DeprecatedNetworkPluginOperationsLatency)
|
||||
legacyregistry.MustRegister(NetworkPluginOperationsLatency)
|
||||
legacyregistry.MustRegister(DeprecatedNetworkPluginOperationsLatency)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,11 @@ go_library(
|
||||
srcs = ["metrics.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/proxy/metrics",
|
||||
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(
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -27,32 +29,35 @@ const kubeProxySubsystem = "kubeproxy"
|
||||
|
||||
var (
|
||||
// SyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules.
|
||||
SyncProxyRulesLatency = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_duration_seconds",
|
||||
Help: "SyncProxyRules latency in seconds",
|
||||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
|
||||
SyncProxyRulesLatency = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_duration_seconds",
|
||||
Help: "SyncProxyRules latency in seconds",
|
||||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// DeprecatedSyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules.
|
||||
DeprecatedSyncProxyRulesLatency = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_latency_microseconds",
|
||||
Help: "(Deprecated) SyncProxyRules latency in microseconds",
|
||||
Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
|
||||
DeprecatedSyncProxyRulesLatency = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_latency_microseconds",
|
||||
Help: "(Deprecated) SyncProxyRules latency in microseconds",
|
||||
Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// SyncProxyRulesLastTimestamp is the timestamp proxy rules were last
|
||||
// successfully synced.
|
||||
SyncProxyRulesLastTimestamp = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_last_timestamp_seconds",
|
||||
Help: "The last time proxy rules were successfully synced",
|
||||
SyncProxyRulesLastTimestamp = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_last_timestamp_seconds",
|
||||
Help: "The last time proxy rules were successfully synced",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
@ -63,8 +68,8 @@ var (
|
||||
// Note that the metrics is partially based on the time exported by the endpoints controller on
|
||||
// the master machine. The measurement may be inaccurate if there is a clock drift between the
|
||||
// node and master machine.
|
||||
NetworkProgrammingLatency = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
NetworkProgrammingLatency = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "network_programming_duration_seconds",
|
||||
Help: "In Cluster Network Programming Latency in seconds",
|
||||
@ -74,56 +79,62 @@ var (
|
||||
prometheus.LinearBuckets(60, 5, 12), // 60s, 65s, 70s, ... 115s
|
||||
prometheus.LinearBuckets(120, 30, 7), // 2min, 2.5min, 3min, ..., 5min
|
||||
),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// EndpointChangesPending is the number of pending endpoint changes that
|
||||
// have not yet been synced to the proxy.
|
||||
EndpointChangesPending = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_endpoint_changes_pending",
|
||||
Help: "Pending proxy rules Endpoint changes",
|
||||
EndpointChangesPending = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_endpoint_changes_pending",
|
||||
Help: "Pending proxy rules Endpoint changes",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// EndpointChangesTotal is the number of endpoint changes that the proxy
|
||||
// has seen.
|
||||
EndpointChangesTotal = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_endpoint_changes_total",
|
||||
Help: "Cumulative proxy rules Endpoint changes",
|
||||
EndpointChangesTotal = metrics.NewCounter(
|
||||
&metrics.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_endpoint_changes_total",
|
||||
Help: "Cumulative proxy rules Endpoint changes",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// ServiceChangesPending is the number of pending service changes that
|
||||
// have not yet been synced to the proxy.
|
||||
ServiceChangesPending = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_service_changes_pending",
|
||||
Help: "Pending proxy rules Service changes",
|
||||
ServiceChangesPending = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_service_changes_pending",
|
||||
Help: "Pending proxy rules Service changes",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// ServiceChangesTotal is the number of service changes that the proxy has
|
||||
// seen.
|
||||
ServiceChangesTotal = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_service_changes_total",
|
||||
Help: "Cumulative proxy rules Service changes",
|
||||
ServiceChangesTotal = metrics.NewCounter(
|
||||
&metrics.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_service_changes_total",
|
||||
Help: "Cumulative proxy rules Service changes",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// IptablesRestoreFailuresTotal is the number of iptables restore failures that the proxy has
|
||||
// seen.
|
||||
IptablesRestoreFailuresTotal = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_iptables_restore_failures_total",
|
||||
Help: "Cumulative proxy iptables restore failures",
|
||||
IptablesRestoreFailuresTotal = metrics.NewCounter(
|
||||
&metrics.CounterOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_iptables_restore_failures_total",
|
||||
Help: "Cumulative proxy iptables restore failures",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
)
|
||||
@ -133,15 +144,15 @@ var registerMetricsOnce sync.Once
|
||||
// RegisterMetrics registers kube-proxy metrics.
|
||||
func RegisterMetrics() {
|
||||
registerMetricsOnce.Do(func() {
|
||||
prometheus.MustRegister(SyncProxyRulesLatency)
|
||||
prometheus.MustRegister(DeprecatedSyncProxyRulesLatency)
|
||||
prometheus.MustRegister(SyncProxyRulesLastTimestamp)
|
||||
prometheus.MustRegister(NetworkProgrammingLatency)
|
||||
prometheus.MustRegister(EndpointChangesPending)
|
||||
prometheus.MustRegister(EndpointChangesTotal)
|
||||
prometheus.MustRegister(ServiceChangesPending)
|
||||
prometheus.MustRegister(ServiceChangesTotal)
|
||||
prometheus.MustRegister(IptablesRestoreFailuresTotal)
|
||||
legacyregistry.MustRegister(SyncProxyRulesLatency)
|
||||
legacyregistry.MustRegister(DeprecatedSyncProxyRulesLatency)
|
||||
legacyregistry.MustRegister(SyncProxyRulesLastTimestamp)
|
||||
legacyregistry.MustRegister(NetworkProgrammingLatency)
|
||||
legacyregistry.MustRegister(EndpointChangesPending)
|
||||
legacyregistry.MustRegister(EndpointChangesTotal)
|
||||
legacyregistry.MustRegister(ServiceChangesPending)
|
||||
legacyregistry.MustRegister(ServiceChangesTotal)
|
||||
legacyregistry.MustRegister(IptablesRestoreFailuresTotal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@ go_library(
|
||||
importpath = "k8s.io/kubernetes/pkg/proxy/winkernel",
|
||||
visibility = ["//visibility:public"],
|
||||
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",
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:windows": [
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package winkernel
|
||||
|
||||
import (
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -26,31 +28,34 @@ import (
|
||||
const kubeProxySubsystem = "kubeproxy"
|
||||
|
||||
var (
|
||||
SyncProxyRulesLatency = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_duration_seconds",
|
||||
Help: "SyncProxyRules latency in seconds",
|
||||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
|
||||
SyncProxyRulesLatency = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_duration_seconds",
|
||||
Help: "SyncProxyRules latency in seconds",
|
||||
Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
DeprecatedSyncProxyRulesLatency = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_latency_microseconds",
|
||||
Help: "(Deprecated) SyncProxyRules latency in microseconds",
|
||||
Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
|
||||
DeprecatedSyncProxyRulesLatency = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_latency_microseconds",
|
||||
Help: "(Deprecated) SyncProxyRules latency in microseconds",
|
||||
Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
// SyncProxyRulesLastTimestamp is the timestamp proxy rules were last
|
||||
// successfully synced.
|
||||
SyncProxyRulesLastTimestamp = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_last_timestamp_seconds",
|
||||
Help: "The last time proxy rules were successfully synced",
|
||||
SyncProxyRulesLastTimestamp = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: kubeProxySubsystem,
|
||||
Name: "sync_proxy_rules_last_timestamp_seconds",
|
||||
Help: "The last time proxy rules were successfully synced",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
)
|
||||
@ -59,9 +64,9 @@ var registerMetricsOnce sync.Once
|
||||
|
||||
func RegisterMetrics() {
|
||||
registerMetricsOnce.Do(func() {
|
||||
prometheus.MustRegister(SyncProxyRulesLatency)
|
||||
prometheus.MustRegister(DeprecatedSyncProxyRulesLatency)
|
||||
prometheus.MustRegister(SyncProxyRulesLastTimestamp)
|
||||
legacyregistry.MustRegister(SyncProxyRulesLatency)
|
||||
legacyregistry.MustRegister(DeprecatedSyncProxyRulesLatency)
|
||||
legacyregistry.MustRegister(SyncProxyRulesLastTimestamp)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ type GaugeMetric interface {
|
||||
Dec()
|
||||
Add(float64)
|
||||
Write(out *dto.Metric) error
|
||||
SetToCurrentTime()
|
||||
}
|
||||
|
||||
// ObserverMetric captures individual observations.
|
||||
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -1663,6 +1663,7 @@ k8s.io/component-base/metrics/prometheus/clientgo
|
||||
k8s.io/component-base/metrics/prometheus/clientgo/leaderelection
|
||||
k8s.io/component-base/metrics/prometheus/restclient
|
||||
k8s.io/component-base/metrics/prometheus/workqueue
|
||||
k8s.io/component-base/metrics/prometheus/restclient
|
||||
k8s.io/component-base/version
|
||||
# k8s.io/cri-api v0.0.0 => ./staging/src/k8s.io/cri-api
|
||||
k8s.io/cri-api/pkg/apis
|
||||
|
Loading…
Reference in New Issue
Block a user