Merge pull request #75303 from obitech/fix_golint_failures_pkg_kubelet

Fix golint failures in some pkg/kubelet packages
This commit is contained in:
Kubernetes Prow Robot 2019-08-05 15:07:50 -07:00 committed by GitHub
commit cea34cc1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 98 additions and 31 deletions

View File

@ -129,7 +129,6 @@ pkg/kubelet/dockershim/network/kubenet
pkg/kubelet/dockershim/network/testing pkg/kubelet/dockershim/network/testing
pkg/kubelet/events pkg/kubelet/events
pkg/kubelet/lifecycle pkg/kubelet/lifecycle
pkg/kubelet/metrics
pkg/kubelet/pluginmanager/pluginwatcher pkg/kubelet/pluginmanager/pluginwatcher
pkg/kubelet/pod/testing pkg/kubelet/pod/testing
pkg/kubelet/preemption pkg/kubelet/preemption

View File

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Reads the pod configuration from the Kubernetes apiserver.
package config package config
import ( import (

View File

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Common logic used by both http and file channels.
package config package config
import ( import (
@ -30,6 +29,7 @@ import (
utilyaml "k8s.io/apimachinery/pkg/util/yaml" utilyaml "k8s.io/apimachinery/pkg/util/yaml"
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core/helper" "k8s.io/kubernetes/pkg/apis/core/helper"
// TODO: remove this import if // TODO: remove this import if
// api.Registry.GroupOrDie(v1.GroupName).GroupVersion.String() is changed // api.Registry.GroupOrDie(v1.GroupName).GroupVersion.String() is changed
// to "v1"? // to "v1"?
@ -110,6 +110,7 @@ func getSelfLink(name, namespace string) string {
type defaultFunc func(pod *api.Pod) error type defaultFunc func(pod *api.Pod) error
// tryDecodeSinglePod takes data and tries to extract valid Pod config information from it.
func tryDecodeSinglePod(data []byte, defaultFn defaultFunc) (parsed bool, pod *v1.Pod, err error) { func tryDecodeSinglePod(data []byte, defaultFn defaultFunc) (parsed bool, pod *v1.Pod, err error) {
// JSON is valid YAML, so this should work for everything. // JSON is valid YAML, so this should work for everything.
json, err := utilyaml.ToJSON(data) json, err := utilyaml.ToJSON(data)

View File

@ -16,6 +16,7 @@ limitations under the License.
package config package config
// Defines sane defaults for the kubelet config.
const ( const (
DefaultKubeletPodsDirName = "pods" DefaultKubeletPodsDirName = "pods"
DefaultKubeletVolumesDirName = "volumes" DefaultKubeletVolumesDirName = "volumes"

View File

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Reads the pod configuration from file or a directory of files.
package config package config
import ( import (
@ -60,6 +59,7 @@ type sourceFile struct {
watchEvents chan *watchEvent watchEvents chan *watchEvent
} }
// NewSourceFile watches a config file for changes.
func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) { func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) {
// "github.com/sigma/go-inotify" requires a path without trailing "/" // "github.com/sigma/go-inotify" requires a path without trailing "/"
path = strings.TrimRight(path, string(os.PathSeparator)) path = strings.TrimRight(path, string(os.PathSeparator))
@ -196,6 +196,7 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
return pods, nil return pods, nil
} }
// extractFromFile parses a file for Pod configuration information.
func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) { func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
klog.V(3).Infof("Reading config file %q", filename) klog.V(3).Infof("Reading config file %q", filename)
defer func() { defer func() {
@ -232,7 +233,7 @@ func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
return pod, nil return pod, nil
} }
return pod, fmt.Errorf("%v: couldn't parse as pod(%v), please check config file.\n", filename, podErr) return pod, fmt.Errorf("%v: couldn't parse as pod(%v), please check config file", filename, podErr)
} }
func (s *sourceFile) replaceStore(pods ...*v1.Pod) (err error) { func (s *sourceFile) replaceStore(pods ...*v1.Pod) (err error) {

View File

@ -16,7 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Reads the pod configuration from file or a directory of files.
package config package config
import ( import (
@ -50,17 +49,17 @@ func (e *retryableError) Error() string {
func (s *sourceFile) startWatch() { func (s *sourceFile) startWatch() {
backOff := flowcontrol.NewBackOff(retryPeriod, maxRetryPeriod) backOff := flowcontrol.NewBackOff(retryPeriod, maxRetryPeriod)
backOffId := "watch" backOffID := "watch"
go wait.Forever(func() { go wait.Forever(func() {
if backOff.IsInBackOffSinceUpdate(backOffId, time.Now()) { if backOff.IsInBackOffSinceUpdate(backOffID, time.Now()) {
return return
} }
if err := s.doWatch(); err != nil { if err := s.doWatch(); err != nil {
klog.Errorf("Unable to read config path %q: %v", s.path, err) klog.Errorf("Unable to read config path %q: %v", s.path, err)
if _, retryable := err.(*retryableError); !retryable { if _, retryable := err.(*retryableError); !retryable {
backOff.Next(backOffId, time.Now()) backOff.Next(backOffID, time.Now())
} }
} }
}, retryPeriod) }, retryPeriod)
@ -130,11 +129,11 @@ func (s *sourceFile) produceWatchEvent(e *fsnotify.Event) error {
func (s *sourceFile) consumeWatchEvent(e *watchEvent) error { func (s *sourceFile) consumeWatchEvent(e *watchEvent) error {
switch e.eventType { switch e.eventType {
case podAdd, podModify: case podAdd, podModify:
if pod, err := s.extractFromFile(e.fileName); err != nil { pod, err := s.extractFromFile(e.fileName)
if err != nil {
return fmt.Errorf("can't process config file %q: %v", e.fileName, err) return fmt.Errorf("can't process config file %q: %v", e.fileName, err)
} else {
return s.store.Add(pod)
} }
return s.store.Add(pod)
case podDelete: case podDelete:
if objKey, keyExist := s.fileKeyMapping[e.fileName]; keyExist { if objKey, keyExist := s.fileKeyMapping[e.fileName]; keyExist {
pod, podExist, err := s.store.GetByKey(objKey) pod, podExist, err := s.store.GetByKey(objKey)
@ -145,9 +144,8 @@ func (s *sourceFile) consumeWatchEvent(e *watchEvent) error {
} else { } else {
if err = s.store.Delete(pod); err != nil { if err = s.store.Delete(pod); err != nil {
return fmt.Errorf("failed to remove deleted pod from cache: %v", err) return fmt.Errorf("failed to remove deleted pod from cache: %v", err)
} else {
delete(s.fileKeyMapping, e.fileName)
} }
delete(s.fileKeyMapping, e.fileName)
} }
} }
} }

View File

@ -16,7 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Reads the pod configuration from file or a directory of files.
package config package config
import ( import (

View File

@ -23,9 +23,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
// ContainerRuntimeOptions defines options for the container runtime.
type ContainerRuntimeOptions struct { type ContainerRuntimeOptions struct {
// General Options.
// General options.
// ContainerRuntime is the container runtime to use. // ContainerRuntime is the container runtime to use.
ContainerRuntime string ContainerRuntime string
@ -78,6 +78,7 @@ type ContainerRuntimeOptions struct {
CNICacheDir string CNICacheDir string
} }
// AddFlags adds flags to the container runtime, according to ContainerRuntimeOptions.
func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) { func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) {
dockerOnlyWarning := "This docker-specific flag only works when container-runtime is set to docker." dockerOnlyWarning := "This docker-specific flag only works when container-runtime is set to docker."

View File

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Reads the pod configuration from an HTTP GET response.
package config package config
import ( import (
@ -43,6 +42,7 @@ type sourceURL struct {
client *http.Client client *http.Client
} }
// NewSourceURL specifies the URL where to read the Pod configuration from, then watches it for changes.
func NewSourceURL(url string, header http.Header, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) { func NewSourceURL(url string, header http.Header, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) {
config := &sourceURL{ config := &sourceURL{
url: url, url: url,

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"time" "time"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
podutil "k8s.io/kubernetes/pkg/api/v1/pod" podutil "k8s.io/kubernetes/pkg/api/v1/pod"
corev1 "k8s.io/kubernetes/pkg/apis/core/v1" corev1 "k8s.io/kubernetes/pkg/apis/core/v1"

View File

@ -16,9 +16,7 @@ limitations under the License.
package configmap package configmap
import ( import v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
)
// fakeManager implements Manager interface for testing purposes. // fakeManager implements Manager interface for testing purposes.
// simple operations to apiserver. // simple operations to apiserver.

View File

@ -30,6 +30,7 @@ import (
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
) )
// This const block defines the metric names for the kubelet metrics.
const ( const (
KubeletSubsystem = "kubelet" KubeletSubsystem = "kubelet"
NodeNameKey = "node_name" NodeNameKey = "node_name"
@ -85,6 +86,7 @@ const (
) )
var ( var (
// NodeName is a Gauge that tracks the ode's name. The count is always 1.
NodeName = prometheus.NewGaugeVec( NodeName = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -93,6 +95,7 @@ var (
}, },
[]string{NodeLabelKey}, []string{NodeLabelKey},
) )
// ContainersPerPodCount is a Counter that tracks the number of containers per pod.
ContainersPerPodCount = prometheus.NewHistogram( ContainersPerPodCount = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -101,6 +104,8 @@ var (
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}, },
) )
// PodWorkerDuration is a Histogram that tracks the duration (in seconds) in takes to sync a single pod.
// Broken down by the operation type.
PodWorkerDuration = prometheus.NewHistogramVec( PodWorkerDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -110,6 +115,7 @@ var (
}, },
[]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 = prometheus.NewHistogram( PodStartDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -118,6 +124,8 @@ var (
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}, },
) )
// CgroupManagerDuration is a Histogram that tracks the duration (in seconds) it takes for cgroup manager operations to complete.
// Broken down by method.
CgroupManagerDuration = prometheus.NewHistogramVec( CgroupManagerDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -127,6 +135,7 @@ var (
}, },
[]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 = prometheus.NewHistogram( PodWorkerStartDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -135,6 +144,8 @@ var (
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}, },
) )
// PLEGRelistDuration is a Histogram that tracks the duration (in seconds) it takes for relisting pods in the Kubelet's
// Pod Lifecycle Event Generator (PLEG).
PLEGRelistDuration = prometheus.NewHistogram( PLEGRelistDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -143,6 +154,8 @@ var (
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}, },
) )
// PLEGDiscardEvents is a Histogram that tracks the duration (in seconds) it takes for discarding events in the Kubelet's
// Pod Lifecycle Event Generator (PLEG).
PLEGDiscardEvents = prometheus.NewCounterVec( PLEGDiscardEvents = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -151,6 +164,8 @@ var (
}, },
[]string{}, []string{},
) )
// PLEGRelistInterval is a Histogram that tracks the intervals (in seconds) between relisting in the Kubelet's
// Pod Lifecycle Event Generator (PLEG).
PLEGRelistInterval = prometheus.NewHistogram( PLEGRelistInterval = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -159,7 +174,8 @@ var (
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}, },
) )
// Metrics of remote runtime operations. // RuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations.
// Broken down by operation type.
RuntimeOperations = prometheus.NewCounterVec( RuntimeOperations = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -168,6 +184,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// RuntimeOperationsDuration is a Histogram that tracks the duration (in seconds) for remote runtime operations to complete.
// Broken down by operation type.
RuntimeOperationsDuration = prometheus.NewHistogramVec( RuntimeOperationsDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -177,6 +195,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// RuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operations errors.
// Broken down by operation type.
RuntimeOperationsErrors = prometheus.NewCounterVec( RuntimeOperationsErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -185,6 +205,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// 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.
EvictionStatsAge = prometheus.NewHistogramVec( EvictionStatsAge = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -194,6 +216,8 @@ var (
}, },
[]string{"eviction_signal"}, []string{"eviction_signal"},
) )
// DevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations.
// Broken down by resource name.
DevicePluginRegistrationCount = prometheus.NewCounterVec( DevicePluginRegistrationCount = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -202,6 +226,8 @@ var (
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// DevicePluginAllocationDuration is a Histogram that tracks the duration (in seconds) to serve a device plugin allocation request.
// Broken down by resource name.
DevicePluginAllocationDuration = prometheus.NewHistogramVec( DevicePluginAllocationDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -211,7 +237,8 @@ var (
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// DeprecatedPodWorkerLatency is a Summary that tracks the latency (in microseconds) to sync a single pod.
// Broken down by operation type. This metric is deprecated.
DeprecatedPodWorkerLatency = prometheus.NewSummaryVec( DeprecatedPodWorkerLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -220,6 +247,8 @@ var (
}, },
[]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.
// This metric is deprecated.
DeprecatedPodStartLatency = prometheus.NewSummary( DeprecatedPodStartLatency = prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -227,6 +256,8 @@ var (
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.",
}, },
) )
// 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.
DeprecatedCgroupManagerLatency = prometheus.NewSummaryVec( DeprecatedCgroupManagerLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -235,6 +266,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedPodWorkerStartLatency is a Summary that tracks the latency (in microseconds) from seeing a pod to starting a worker.
// This metric is deprecated.
DeprecatedPodWorkerStartLatency = prometheus.NewSummary( DeprecatedPodWorkerStartLatency = prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -242,6 +275,8 @@ var (
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.",
}, },
) )
// DeprecatedPLEGRelistLatency is a Summary that tracks the latency (in microseconds) for relisting pods in PLEG.
// This metric is deprecated.
DeprecatedPLEGRelistLatency = prometheus.NewSummary( DeprecatedPLEGRelistLatency = prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -249,6 +284,8 @@ var (
Help: "(Deprecated) Latency in microseconds for relisting pods in PLEG.", Help: "(Deprecated) Latency in microseconds for relisting pods in PLEG.",
}, },
) )
// DeprecatedPLEGRelistInterval is a Summary that tracks the interval (in microseconds) between relistings in PLEG.
// This metric is deprecated.
DeprecatedPLEGRelistInterval = prometheus.NewSummary( DeprecatedPLEGRelistInterval = prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -256,6 +293,8 @@ var (
Help: "(Deprecated) Interval in microseconds between relisting in PLEG.", Help: "(Deprecated) Interval in microseconds between relisting in PLEG.",
}, },
) )
// DeprecatedRuntimeOperations is a Counter that tracks the cumulative number of remote runtime operations.
// Broken down by operation type. This metric is deprecated.
DeprecatedRuntimeOperations = prometheus.NewCounterVec( DeprecatedRuntimeOperations = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -264,6 +303,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// 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.
DeprecatedRuntimeOperationsLatency = prometheus.NewSummaryVec( DeprecatedRuntimeOperationsLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -272,6 +313,8 @@ var (
}, },
[]string{"operation_type"}, []string{"operation_type"},
) )
// DeprecatedRuntimeOperationsErrors is a Counter that tracks the cumulative number of remote runtime operation errors.
// Broken down by operation type. This metric is deprecated.
DeprecatedRuntimeOperationsErrors = prometheus.NewCounterVec( DeprecatedRuntimeOperationsErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -280,6 +323,8 @@ var (
}, },
[]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
// is evicted based on those stats. Broken down by eviction signal. This metric is deprecated.
DeprecatedEvictionStatsAge = prometheus.NewSummaryVec( DeprecatedEvictionStatsAge = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -288,6 +333,8 @@ var (
}, },
[]string{"eviction_signal"}, []string{"eviction_signal"},
) )
// DeprecatedDevicePluginRegistrationCount is a Counter that tracks the cumulative number of device plugin registrations.
// Broken down by resource name. This metric is deprecated.
DeprecatedDevicePluginRegistrationCount = prometheus.NewCounterVec( DeprecatedDevicePluginRegistrationCount = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -296,6 +343,8 @@ var (
}, },
[]string{"resource_name"}, []string{"resource_name"},
) )
// 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.
DeprecatedDevicePluginAllocationLatency = prometheus.NewSummaryVec( DeprecatedDevicePluginAllocationLatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -307,6 +356,7 @@ 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 = prometheus.NewGaugeVec( AssignedConfig = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -315,6 +365,7 @@ var (
}, },
[]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 = prometheus.NewGaugeVec( ActiveConfig = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -323,6 +374,8 @@ var (
}, },
[]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
// are certain errors.
LastKnownGoodConfig = prometheus.NewGaugeVec( LastKnownGoodConfig = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -331,6 +384,7 @@ var (
}, },
[]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 = prometheus.NewGauge( ConfigError = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -338,6 +392,8 @@ var (
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.",
}, },
) )
// RunPodSandboxDuration is a Histogram that tracks the duration (in seconds) it takes to run Pod Sandbox operations.
// Broken down by RuntimeClass.
RunPodSandboxDuration = prometheus.NewHistogramVec( RunPodSandboxDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -348,6 +404,8 @@ var (
}, },
[]string{"runtime_handler"}, []string{"runtime_handler"},
) )
// RunPodSandboxErrors is a Counter that tracks the cumulative number of Pod Sandbox operations errors.
// Broken down by RuntimeClass.
RunPodSandboxErrors = prometheus.NewCounterVec( RunPodSandboxErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Subsystem: KubeletSubsystem, Subsystem: KubeletSubsystem,
@ -360,7 +418,7 @@ var (
var registerMetrics sync.Once var registerMetrics sync.Once
// Register all metrics. // Register registers all metrics.
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() {
@ -404,7 +462,7 @@ func Register(containerCache kubecontainer.RuntimeCache, collectors ...prometheu
}) })
} }
// Gets the time since the specified start in microseconds. // SinceInMicroseconds gets the time since the specified start in microseconds.
func SinceInMicroseconds(start time.Time) float64 { func SinceInMicroseconds(start time.Time) float64 {
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds()) return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
} }
@ -438,11 +496,15 @@ var (
nil, nil) nil, nil)
) )
// Describe implements Prometheus' Describe method from the Collector interface. It sends all
// available descriptions to the provided channel and retunrs once the last description has been sent.
func (pc *podAndContainerCollector) Describe(ch chan<- *prometheus.Desc) { func (pc *podAndContainerCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- runningPodCountDesc ch <- runningPodCountDesc
ch <- runningContainerCountDesc ch <- runningContainerCountDesc
} }
// Collect implements Prometheus' Collect method from the Collector interface. It's called by the Prometheus
// registry when collecting metrics.
func (pc *podAndContainerCollector) Collect(ch chan<- prometheus.Metric) { func (pc *podAndContainerCollector) Collect(ch chan<- prometheus.Metric) {
runningPods, err := pc.containerCache.GetPods() runningPods, err := pc.containerCache.GetPods()
if err != nil { if err != nil {
@ -488,8 +550,10 @@ func configLabels(source *corev1.NodeConfigSource) (map[string]string, error) {
} }
// track labels across metric updates, so we can delete old label sets and prevent leaks // track labels across metric updates, so we can delete old label sets and prevent leaks
var assignedConfigLabels map[string]string = map[string]string{} var assignedConfigLabels map[string]string
// SetAssignedConfig tracks labels according to the assigned NodeConfig. It also tracks labels
// across metric updates so old labels can be safely deleted.
func SetAssignedConfig(source *corev1.NodeConfigSource) error { func SetAssignedConfig(source *corev1.NodeConfigSource) error {
// compute the timeseries labels from the source // compute the timeseries labels from the source
labels, err := configLabels(source) labels, err := configLabels(source)
@ -508,8 +572,10 @@ func SetAssignedConfig(source *corev1.NodeConfigSource) error {
} }
// track labels across metric updates, so we can delete old label sets and prevent leaks // track labels across metric updates, so we can delete old label sets and prevent leaks
var activeConfigLabels map[string]string = map[string]string{} var activeConfigLabels map[string]string
// SetActiveConfig tracks labels according to the NodeConfig that is currently used by the Kubelet.
// It also tracks labels across metric updates so old labels can be safely deleted.
func SetActiveConfig(source *corev1.NodeConfigSource) error { func SetActiveConfig(source *corev1.NodeConfigSource) error {
// compute the timeseries labels from the source // compute the timeseries labels from the source
labels, err := configLabels(source) labels, err := configLabels(source)
@ -528,8 +594,10 @@ func SetActiveConfig(source *corev1.NodeConfigSource) error {
} }
// track labels across metric updates, so we can delete old label sets and prevent leaks // track labels across metric updates, so we can delete old label sets and prevent leaks
var lastKnownGoodConfigLabels map[string]string = map[string]string{} var lastKnownGoodConfigLabels map[string]string
// SetLastKnownGoodConfig tracks labels according to the NodeConfig that was successfully applied last.
// It also tracks labels across metric updates so old labels can be safely deleted.
func SetLastKnownGoodConfig(source *corev1.NodeConfigSource) error { func SetLastKnownGoodConfig(source *corev1.NodeConfigSource) error {
// compute the timeseries labels from the source // compute the timeseries labels from the source
labels, err := configLabels(source) labels, err := configLabels(source)
@ -547,6 +615,7 @@ func SetLastKnownGoodConfig(source *corev1.NodeConfigSource) error {
return nil return nil
} }
// SetConfigError sets a the ConfigError metric to 1 in case any errors were encountered.
func SetConfigError(err bool) { func SetConfigError(err bool) {
if err { if err {
ConfigError.Set(1) ConfigError.Set(1)
@ -555,6 +624,7 @@ func SetConfigError(err bool) {
} }
} }
// SetNodeName sets the NodeName Gauge to 1.
func SetNodeName(name types.NodeName) { func SetNodeName(name types.NodeName) {
NodeName.WithLabelValues(string(name)).Set(1) NodeName.WithLabelValues(string(name)).Set(1)
} }

View File

@ -105,13 +105,13 @@ func (mc *basicMirrorClient) DeleteMirrorPod(podFullName string, uid *types.UID)
return true, nil return true, nil
} }
// IsStaticPod returns true if the pod is a static pod. // IsStaticPod returns true if the passed Pod is static.
func IsStaticPod(pod *v1.Pod) bool { func IsStaticPod(pod *v1.Pod) bool {
source, err := kubetypes.GetPodSource(pod) source, err := kubetypes.GetPodSource(pod)
return err == nil && source != kubetypes.ApiserverSource return err == nil && source != kubetypes.ApiserverSource
} }
// IsMirrorPod returns true if the pod is a mirror pod. // IsMirrorPod returns true if the passed Pod is a Mirror Pod.
func IsMirrorPod(pod *v1.Pod) bool { func IsMirrorPod(pod *v1.Pod) bool {
_, ok := pod.Annotations[kubetypes.ConfigMirrorAnnotationKey] _, ok := pod.Annotations[kubetypes.ConfigMirrorAnnotationKey]
return ok return ok