mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Remove ManagedPod,ManagedContainer metrics
This replaces the generic ManagedPod and ManagedContainer kubelet metrics with a gauge to track only ephemeral container usage.
This commit is contained in:
parent
29178fff1c
commit
30d2ad576a
@ -84,14 +84,15 @@ const (
|
|||||||
RunPodSandboxDurationKey = "run_podsandbox_duration_seconds"
|
RunPodSandboxDurationKey = "run_podsandbox_duration_seconds"
|
||||||
RunPodSandboxErrorsKey = "run_podsandbox_errors_total"
|
RunPodSandboxErrorsKey = "run_podsandbox_errors_total"
|
||||||
|
|
||||||
// Metrics to keep track of objects under management
|
// Metrics to keep track of total number of Pods and Containers started
|
||||||
ManagedPodsKey = "managed_pods"
|
|
||||||
ManagedContainersKey = "managed_containers"
|
|
||||||
StartedPodsTotalKey = "started_pods_total"
|
StartedPodsTotalKey = "started_pods_total"
|
||||||
StartedPodsErrorsTotalKey = "started_pods_errors_total"
|
StartedPodsErrorsTotalKey = "started_pods_errors_total"
|
||||||
StartedContainersTotalKey = "started_containers_total"
|
StartedContainersTotalKey = "started_containers_total"
|
||||||
StartedContainersErrorsTotalKey = "started_containers_errors_total"
|
StartedContainersErrorsTotalKey = "started_containers_errors_total"
|
||||||
|
|
||||||
|
// Metrics to track ephemeral container usage by this kubelet
|
||||||
|
ManagedEphemeralContainersKey = "managed_ephemeral_containers"
|
||||||
|
|
||||||
// Values used in metric labels
|
// Values used in metric labels
|
||||||
Container = "container"
|
Container = "container"
|
||||||
InitContainer = "init_container"
|
InitContainer = "init_container"
|
||||||
@ -483,25 +484,15 @@ var (
|
|||||||
},
|
},
|
||||||
[]string{"container_type", "code"},
|
[]string{"container_type", "code"},
|
||||||
)
|
)
|
||||||
// ManagedPods is a gauge that tracks how many pods are managed by this kubelet
|
// ManagedEphemeralContainers is a gauge that indicates how many ephemeral containers are managed by this kubelet.
|
||||||
ManagedPods = metrics.NewGauge(
|
ManagedEphemeralContainers = metrics.NewGauge(
|
||||||
&metrics.GaugeOpts{
|
&metrics.GaugeOpts{
|
||||||
Subsystem: KubeletSubsystem,
|
Subsystem: KubeletSubsystem,
|
||||||
Name: ManagedPodsKey,
|
Name: ManagedEphemeralContainersKey,
|
||||||
Help: "Number of pods managed by this kubelet",
|
Help: "Current number of ephemeral containers in pods managed by this kubelet. Ephemeral containers will be ignored if disabled by the EphemeralContainers feature gate, and this number will be 0.",
|
||||||
StabilityLevel: metrics.ALPHA,
|
StabilityLevel: metrics.ALPHA,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// ManagedContainers is a gauge that tracks how many containers are managed by this kubelet
|
|
||||||
ManagedContainers = metrics.NewGaugeVec(
|
|
||||||
&metrics.GaugeOpts{
|
|
||||||
Subsystem: KubeletSubsystem,
|
|
||||||
Name: ManagedContainersKey,
|
|
||||||
Help: "Number of containers managed by this kubelet",
|
|
||||||
StabilityLevel: metrics.ALPHA,
|
|
||||||
},
|
|
||||||
[]string{"container_type"},
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var registerMetrics sync.Once
|
var registerMetrics sync.Once
|
||||||
@ -530,8 +521,7 @@ func Register(collectors ...metrics.StableCollector) {
|
|||||||
legacyregistry.MustRegister(DevicePluginAllocationDuration)
|
legacyregistry.MustRegister(DevicePluginAllocationDuration)
|
||||||
legacyregistry.MustRegister(RunningContainerCount)
|
legacyregistry.MustRegister(RunningContainerCount)
|
||||||
legacyregistry.MustRegister(RunningPodCount)
|
legacyregistry.MustRegister(RunningPodCount)
|
||||||
legacyregistry.MustRegister(ManagedPods)
|
legacyregistry.MustRegister(ManagedEphemeralContainers)
|
||||||
legacyregistry.MustRegister(ManagedContainers)
|
|
||||||
legacyregistry.MustRegister(StartedPodsTotal)
|
legacyregistry.MustRegister(StartedPodsTotal)
|
||||||
legacyregistry.MustRegister(StartedPodsErrorsTotal)
|
legacyregistry.MustRegister(StartedPodsErrorsTotal)
|
||||||
legacyregistry.MustRegister(StartedContainersTotal)
|
legacyregistry.MustRegister(StartedContainersTotal)
|
||||||
|
@ -162,42 +162,22 @@ func isPodInTerminatedState(pod *v1.Pod) bool {
|
|||||||
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
|
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateMetrics updates the gauge metrics that track how many pods and containers this kubelet manages.
|
// updateMetrics updates the metrics surfaced by the pod manager.
|
||||||
// oldPod or newPod may be nil to signify creation or deletion, respectively.
|
// oldPod or newPod may be nil to signify creation or deletion.
|
||||||
func updateMetrics(oldPod, newPod *v1.Pod) {
|
func updateMetrics(oldPod, newPod *v1.Pod) {
|
||||||
var numC, numIC, numEC int
|
if !utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers) {
|
||||||
countEC := utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var numEC int
|
||||||
if oldPod != nil {
|
if oldPod != nil {
|
||||||
if newPod == nil {
|
numEC -= len(oldPod.Spec.EphemeralContainers)
|
||||||
metrics.ManagedPods.Dec()
|
|
||||||
}
|
|
||||||
numC -= len(oldPod.Spec.Containers)
|
|
||||||
numIC -= len(oldPod.Spec.InitContainers)
|
|
||||||
if countEC {
|
|
||||||
numEC -= len(oldPod.Spec.EphemeralContainers)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if newPod != nil {
|
if newPod != nil {
|
||||||
if oldPod == nil {
|
numEC += len(newPod.Spec.EphemeralContainers)
|
||||||
metrics.ManagedPods.Inc()
|
|
||||||
}
|
|
||||||
numC += len(newPod.Spec.Containers)
|
|
||||||
numIC += len(newPod.Spec.InitContainers)
|
|
||||||
if countEC {
|
|
||||||
numEC += len(newPod.Spec.EphemeralContainers)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if numEC != 0 {
|
||||||
if numC != 0 {
|
metrics.ManagedEphemeralContainers.Add(float64(numEC))
|
||||||
metrics.ManagedContainers.WithLabelValues(metrics.Container).Add(float64(numC))
|
|
||||||
}
|
|
||||||
if numIC != 0 {
|
|
||||||
metrics.ManagedContainers.WithLabelValues(metrics.InitContainer).Add(float64(numIC))
|
|
||||||
}
|
|
||||||
if countEC && numEC != 0 {
|
|
||||||
metrics.ManagedContainers.WithLabelValues(metrics.EphemeralContainer).Add(float64(numEC))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user