mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
3
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/BUILD
generated
vendored
3
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/BUILD
generated
vendored
@ -10,9 +10,12 @@ go_library(
|
||||
srcs = ["metrics.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/metrics",
|
||||
deps = [
|
||||
"//pkg/features:go_default_library",
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
8
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/collectors/volume_stats.go
generated
vendored
8
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/collectors/volume_stats.go
generated
vendored
@ -58,17 +58,17 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
type volumeStatsCollecotr struct {
|
||||
type volumeStatsCollector struct {
|
||||
statsProvider serverstats.StatsProvider
|
||||
}
|
||||
|
||||
// NewVolumeStatsCollector creates a volume stats prometheus collector.
|
||||
func NewVolumeStatsCollector(statsProvider serverstats.StatsProvider) prometheus.Collector {
|
||||
return &volumeStatsCollecotr{statsProvider: statsProvider}
|
||||
return &volumeStatsCollector{statsProvider: statsProvider}
|
||||
}
|
||||
|
||||
// Describe implements the prometheus.Collector interface.
|
||||
func (collector *volumeStatsCollecotr) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (collector *volumeStatsCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- volumeStatsCapacityBytesDesc
|
||||
ch <- volumeStatsAvailableBytesDesc
|
||||
ch <- volumeStatsUsedBytesDesc
|
||||
@ -78,7 +78,7 @@ func (collector *volumeStatsCollecotr) Describe(ch chan<- *prometheus.Desc) {
|
||||
}
|
||||
|
||||
// Collect implements the prometheus.Collector interface.
|
||||
func (collector *volumeStatsCollecotr) Collect(ch chan<- prometheus.Metric) {
|
||||
func (collector *volumeStatsCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
podStats, err := collector.statsProvider.ListPodStats()
|
||||
if err != nil {
|
||||
return
|
||||
|
2
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/collectors/volume_stats_test.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/collectors/volume_stats_test.go
generated
vendored
@ -129,7 +129,7 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
|
||||
mockStatsProvider := new(statstest.StatsProvider)
|
||||
mockStatsProvider.On("ListPodStats").Return(podStats, nil)
|
||||
if err := gatherAndCompare(&volumeStatsCollecotr{statsProvider: mockStatsProvider}, want, metrics); err != nil {
|
||||
if err := gatherAndCompare(&volumeStatsCollector{statsProvider: mockStatsProvider}, want, metrics); err != nil {
|
||||
t.Errorf("unexpected collecting result:\n%s", err)
|
||||
}
|
||||
}
|
||||
|
140
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/metrics.go
generated
vendored
140
vendor/k8s.io/kubernetes/pkg/kubelet/metrics/metrics.go
generated
vendored
@ -17,11 +17,15 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
)
|
||||
|
||||
@ -47,6 +51,17 @@ const (
|
||||
// Metrics keys of device plugin operations
|
||||
DevicePluginRegistrationCountKey = "device_plugin_registration_count"
|
||||
DevicePluginAllocationLatencyKey = "device_plugin_alloc_latency_microseconds"
|
||||
|
||||
// Metric keys for node config
|
||||
AssignedConfigKey = "node_config_assigned"
|
||||
ActiveConfigKey = "node_config_active"
|
||||
LastKnownGoodConfigKey = "node_config_last_known_good"
|
||||
ConfigErrorKey = "node_config_error"
|
||||
ConfigSourceLabelKey = "node_config_source"
|
||||
ConfigSourceLabelValueLocal = "local"
|
||||
ConfigUIDLabelKey = "node_config_uid"
|
||||
ConfigResourceVersionLabelKey = "node_config_resource_version"
|
||||
KubeletConfigKeyLabelKey = "node_config_kubelet_key"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -150,6 +165,40 @@ var (
|
||||
},
|
||||
[]string{"resource_name"},
|
||||
)
|
||||
|
||||
// Metrics for node config
|
||||
|
||||
AssignedConfig = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: AssignedConfigKey,
|
||||
Help: "The node's understanding of intended config. The count is always 1.",
|
||||
},
|
||||
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
|
||||
)
|
||||
ActiveConfig = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: ActiveConfigKey,
|
||||
Help: "The config source the node is actively using. The count is always 1.",
|
||||
},
|
||||
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
|
||||
)
|
||||
LastKnownGoodConfig = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: LastKnownGoodConfigKey,
|
||||
Help: "The config source the node will fall back to when it encounters certain errors. The count is always 1.",
|
||||
},
|
||||
[]string{ConfigSourceLabelKey, ConfigUIDLabelKey, ConfigResourceVersionLabelKey, KubeletConfigKeyLabelKey},
|
||||
)
|
||||
ConfigError = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: ConfigErrorKey,
|
||||
Help: "This metric is true (1) if the node is experiencing a configuration-related error, false (0) otherwise.",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
var registerMetrics sync.Once
|
||||
@ -172,6 +221,12 @@ func Register(containerCache kubecontainer.RuntimeCache, collectors ...prometheu
|
||||
prometheus.MustRegister(EvictionStatsAge)
|
||||
prometheus.MustRegister(DevicePluginRegistrationCount)
|
||||
prometheus.MustRegister(DevicePluginAllocationLatency)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
|
||||
prometheus.MustRegister(AssignedConfig)
|
||||
prometheus.MustRegister(ActiveConfig)
|
||||
prometheus.MustRegister(LastKnownGoodConfig)
|
||||
prometheus.MustRegister(ConfigError)
|
||||
}
|
||||
for _, collector := range collectors {
|
||||
prometheus.MustRegister(collector)
|
||||
}
|
||||
@ -232,3 +287,88 @@ func (pc *podAndContainerCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
prometheus.GaugeValue,
|
||||
float64(runningContainers))
|
||||
}
|
||||
|
||||
const configMapAPIPathFmt = "/api/v1/namespaces/%s/configmaps/%s"
|
||||
|
||||
func configLabels(source *corev1.NodeConfigSource) (map[string]string, error) {
|
||||
if source == nil {
|
||||
return map[string]string{
|
||||
// prometheus requires all of the labels that can be set on the metric
|
||||
ConfigSourceLabelKey: "local",
|
||||
ConfigUIDLabelKey: "",
|
||||
ConfigResourceVersionLabelKey: "",
|
||||
KubeletConfigKeyLabelKey: "",
|
||||
}, nil
|
||||
}
|
||||
if source.ConfigMap != nil {
|
||||
return map[string]string{
|
||||
ConfigSourceLabelKey: fmt.Sprintf(configMapAPIPathFmt, source.ConfigMap.Namespace, source.ConfigMap.Name),
|
||||
ConfigUIDLabelKey: string(source.ConfigMap.UID),
|
||||
ConfigResourceVersionLabelKey: source.ConfigMap.ResourceVersion,
|
||||
KubeletConfigKeyLabelKey: source.ConfigMap.KubeletConfigKey,
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unrecognized config source type, all source subfields were nil")
|
||||
}
|
||||
|
||||
// track labels across metric updates, so we can delete old label sets and prevent leaks
|
||||
var assignedConfigLabels map[string]string = map[string]string{}
|
||||
|
||||
func SetAssignedConfig(source *corev1.NodeConfigSource) error {
|
||||
// compute the timeseries labels from the source
|
||||
labels, err := configLabels(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clean up the old timeseries (WithLabelValues creates a new one for each distinct label set)
|
||||
AssignedConfig.Delete(assignedConfigLabels)
|
||||
// record the new timeseries
|
||||
assignedConfigLabels = labels
|
||||
// expose the new timeseries with a constant count of 1
|
||||
AssignedConfig.With(assignedConfigLabels).Set(1)
|
||||
return nil
|
||||
}
|
||||
|
||||
// track labels across metric updates, so we can delete old label sets and prevent leaks
|
||||
var activeConfigLabels map[string]string = map[string]string{}
|
||||
|
||||
func SetActiveConfig(source *corev1.NodeConfigSource) error {
|
||||
// compute the timeseries labels from the source
|
||||
labels, err := configLabels(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clean up the old timeseries (WithLabelValues creates a new one for each distinct label set)
|
||||
ActiveConfig.Delete(activeConfigLabels)
|
||||
// record the new timeseries
|
||||
activeConfigLabels = labels
|
||||
// expose the new timeseries with a constant count of 1
|
||||
ActiveConfig.With(activeConfigLabels).Set(1)
|
||||
return nil
|
||||
}
|
||||
|
||||
// track labels across metric updates, so we can delete old label sets and prevent leaks
|
||||
var lastKnownGoodConfigLabels map[string]string = map[string]string{}
|
||||
|
||||
func SetLastKnownGoodConfig(source *corev1.NodeConfigSource) error {
|
||||
// compute the timeseries labels from the source
|
||||
labels, err := configLabels(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clean up the old timeseries (WithLabelValues creates a new one for each distinct label set)
|
||||
LastKnownGoodConfig.Delete(lastKnownGoodConfigLabels)
|
||||
// record the new timeseries
|
||||
lastKnownGoodConfigLabels = labels
|
||||
// expose the new timeseries with a constant count of 1
|
||||
LastKnownGoodConfig.With(lastKnownGoodConfigLabels).Set(1)
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetConfigError(err bool) {
|
||||
if err {
|
||||
ConfigError.Set(1)
|
||||
} else {
|
||||
ConfigError.Set(0)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user