mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 01:23:48 +00:00
Merge pull request #105406 from marosset/kubelet-metrics-for-host-process-containers
Adding kubelet metrics for started and failed to start HostProcess containers
This commit is contained in:
@@ -55,6 +55,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/cache"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||
sc "k8s.io/kubernetes/pkg/securitycontext"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -883,12 +884,18 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, podStatus *kubecontaine
|
||||
}
|
||||
|
||||
metrics.StartedContainersTotal.WithLabelValues(metricLabel).Inc()
|
||||
if sc.HasWindowsHostProcessRequest(pod, spec.container) {
|
||||
metrics.StartedHostProcessContainersTotal.WithLabelValues(metricLabel).Inc()
|
||||
}
|
||||
klog.V(4).InfoS("Creating container in pod", "containerType", typeName, "container", spec.container, "pod", klog.KObj(pod))
|
||||
// NOTE (aramase) podIPs are populated for single stack and dual stack clusters. Send only podIPs.
|
||||
if msg, err := m.startContainer(podSandboxID, podSandboxConfig, spec, pod, podStatus, pullSecrets, podIP, podIPs); err != nil {
|
||||
// startContainer() returns well-defined error codes that have reasonable cardinality for metrics and are
|
||||
// useful to cluster administrators to distinguish "server errors" from "user errors".
|
||||
metrics.StartedContainersErrorsTotal.WithLabelValues(metricLabel, err.Error()).Inc()
|
||||
if sc.HasWindowsHostProcessRequest(pod, spec.container) {
|
||||
metrics.StartedHostProcessContainersErrorsTotal.WithLabelValues(metricLabel, err.Error()).Inc()
|
||||
}
|
||||
startContainerResult.Fail(err, msg)
|
||||
// known errors that are logged in other places are logged at higher levels here to avoid
|
||||
// repetitive log spam
|
||||
|
@@ -90,6 +90,10 @@ const (
|
||||
StartedContainersTotalKey = "started_containers_total"
|
||||
StartedContainersErrorsTotalKey = "started_containers_errors_total"
|
||||
|
||||
// Metrics to track HostProcess container usage by this kubelet
|
||||
StartedHostProcessContainersTotalKey = "started_host_process_containers_total"
|
||||
StartedHostProcessContainersErrorsTotalKey = "started_host_process_containers_errors_total"
|
||||
|
||||
// Metrics to track ephemeral container usage by this kubelet
|
||||
ManagedEphemeralContainersKey = "managed_ephemeral_containers"
|
||||
|
||||
@@ -488,6 +492,26 @@ var (
|
||||
},
|
||||
[]string{"container_type", "code"},
|
||||
)
|
||||
// StartedHostProcessContainersTotal is a counter that tracks the number of hostprocess container creation operations
|
||||
StartedHostProcessContainersTotal = metrics.NewCounterVec(
|
||||
&metrics.CounterOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: StartedHostProcessContainersTotalKey,
|
||||
Help: "Cumulative number of hostprocess containers started. This metric will only be collected on Windows and requires WindowsHostProcessContainers feature gate to be enabled.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"container_type"},
|
||||
)
|
||||
// StartedHostProcessContainersErrorsTotal is a counter that tracks the number of errors creating hostprocess containers
|
||||
StartedHostProcessContainersErrorsTotal = metrics.NewCounterVec(
|
||||
&metrics.CounterOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: StartedHostProcessContainersErrorsTotalKey,
|
||||
Help: "Cumulative number of errors when starting hostprocess containers. This metric will only be collected on Windows and requires WindowsHostProcessContainers feature gate to be enabled.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"container_type", "code"},
|
||||
)
|
||||
// ManagedEphemeralContainers is a gauge that indicates how many ephemeral containers are managed by this kubelet.
|
||||
ManagedEphemeralContainers = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
@@ -530,6 +554,10 @@ func Register(collectors ...metrics.StableCollector) {
|
||||
legacyregistry.MustRegister(StartedPodsErrorsTotal)
|
||||
legacyregistry.MustRegister(StartedContainersTotal)
|
||||
legacyregistry.MustRegister(StartedContainersErrorsTotal)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.WindowsHostProcessContainers) {
|
||||
legacyregistry.MustRegister(StartedHostProcessContainersTotal)
|
||||
legacyregistry.MustRegister(StartedHostProcessContainersErrorsTotal)
|
||||
}
|
||||
legacyregistry.MustRegister(RunPodSandboxDuration)
|
||||
legacyregistry.MustRegister(RunPodSandboxErrors)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
|
||||
|
Reference in New Issue
Block a user