mirror of https://github.com/k3s-io/k3s
Improve usability of CSI plugin metrics
Use full qualified plugin name if volume spec is present.pull/58/head
parent
8307fb2fb3
commit
dfe0a08f05
|
@ -9,6 +9,7 @@ go_library(
|
||||||
"//pkg/controller/volume/attachdetach/cache:go_default_library",
|
"//pkg/controller/volume/attachdetach/cache:go_default_library",
|
||||||
"//pkg/controller/volume/attachdetach/util:go_default_library",
|
"//pkg/controller/volume/attachdetach/util:go_default_library",
|
||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
|
"//pkg/volume/util:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/controller/volume/attachdetach/cache"
|
"k8s.io/kubernetes/pkg/controller/volume/attachdetach/cache"
|
||||||
"k8s.io/kubernetes/pkg/controller/volume/attachdetach/util"
|
"k8s.io/kubernetes/pkg/controller/volume/attachdetach/util"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
|
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pluginNameNotAvailable = "N/A"
|
const pluginNameNotAvailable = "N/A"
|
||||||
|
@ -166,7 +167,8 @@ func (collector *attachDetachStateCollector) getVolumeInUseCount() volumeCount {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nodeVolumeMap.add(pod.Spec.NodeName, volumePlugin.GetPluginName())
|
pluginName := volumeutil.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeSpec)
|
||||||
|
nodeVolumeMap.add(pod.Spec.NodeName, pluginName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodeVolumeMap
|
return nodeVolumeMap
|
||||||
|
@ -178,7 +180,7 @@ func (collector *attachDetachStateCollector) getTotalVolumesCount() volumeCount
|
||||||
if plugin, err := collector.volumePluginMgr.FindPluginBySpec(v.VolumeSpec); err == nil {
|
if plugin, err := collector.volumePluginMgr.FindPluginBySpec(v.VolumeSpec); err == nil {
|
||||||
pluginName := pluginNameNotAvailable
|
pluginName := pluginNameNotAvailable
|
||||||
if plugin != nil {
|
if plugin != nil {
|
||||||
pluginName = plugin.GetPluginName()
|
pluginName = volumeutil.GetFullQualifiedPluginNameForVolume(plugin.GetPluginName(), v.VolumeSpec)
|
||||||
}
|
}
|
||||||
stateVolumeMap.add("desired_state_of_world", pluginName)
|
stateVolumeMap.add("desired_state_of_world", pluginName)
|
||||||
}
|
}
|
||||||
|
@ -187,7 +189,7 @@ func (collector *attachDetachStateCollector) getTotalVolumesCount() volumeCount
|
||||||
if plugin, err := collector.volumePluginMgr.FindPluginBySpec(v.VolumeSpec); err == nil {
|
if plugin, err := collector.volumePluginMgr.FindPluginBySpec(v.VolumeSpec); err == nil {
|
||||||
pluginName := pluginNameNotAvailable
|
pluginName := pluginNameNotAvailable
|
||||||
if plugin != nil {
|
if plugin != nil {
|
||||||
pluginName = plugin.GetPluginName()
|
pluginName = volumeutil.GetFullQualifiedPluginNameForVolume(plugin.GetPluginName(), v.VolumeSpec)
|
||||||
}
|
}
|
||||||
stateVolumeMap.add("actual_state_of_world", pluginName)
|
stateVolumeMap.add("actual_state_of_world", pluginName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ go_library(
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/kubelet/volumemanager/cache:go_default_library",
|
"//pkg/kubelet/volumemanager/cache:go_default_library",
|
||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
|
"//pkg/volume/util:go_default_library",
|
||||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
],
|
],
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/volumemanager/cache"
|
"k8s.io/kubernetes/pkg/kubelet/volumemanager/cache"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
|
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -95,7 +96,7 @@ func (c *totalVolumesCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
func (c *totalVolumesCollector) getVolumeCount() volumeCount {
|
func (c *totalVolumesCollector) getVolumeCount() volumeCount {
|
||||||
counter := make(volumeCount)
|
counter := make(volumeCount)
|
||||||
for _, mountedVolume := range c.asw.GetMountedVolumes() {
|
for _, mountedVolume := range c.asw.GetMountedVolumes() {
|
||||||
pluginName := mountedVolume.PluginName
|
pluginName := volumeutil.GetFullQualifiedPluginNameForVolume(mountedVolume.PluginName, mountedVolume.VolumeSpec)
|
||||||
if pluginName == "" {
|
if pluginName == "" {
|
||||||
pluginName = pluginNameNotAvailable
|
pluginName = pluginNameNotAvailable
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ func (c *totalVolumesCollector) getVolumeCount() volumeCount {
|
||||||
for _, volumeToMount := range c.dsw.GetVolumesToMount() {
|
for _, volumeToMount := range c.dsw.GetVolumesToMount() {
|
||||||
pluginName := pluginNameNotAvailable
|
pluginName := pluginNameNotAvailable
|
||||||
if plugin, err := c.pluginMgr.FindPluginBySpec(volumeToMount.VolumeSpec); err == nil {
|
if plugin, err := c.pluginMgr.FindPluginBySpec(volumeToMount.VolumeSpec); err == nil {
|
||||||
pluginName = plugin.GetPluginName()
|
pluginName = volumeutil.GetFullQualifiedPluginNameForVolume(plugin.GetPluginName(), volumeToMount.VolumeSpec)
|
||||||
}
|
}
|
||||||
counter.add("desired_state_of_world", pluginName)
|
counter.add("desired_state_of_world", pluginName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,11 @@ limitations under the License.
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
var storageOperationMetric = prometheus.NewHistogramVec(
|
var storageOperationMetric = prometheus.NewHistogramVec(
|
||||||
|
@ -62,3 +64,15 @@ func OperationCompleteHook(plugin, operationName string) func(*error) {
|
||||||
}
|
}
|
||||||
return opComplete
|
return opComplete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFullQualifiedPluginNameForVolume returns full qualified plugin name for
|
||||||
|
// given volume. For CSI plugin, it appends plugin driver name at the end of
|
||||||
|
// plugin name, e.g. kubernetes.io/csi:csi-hostpath. It helps to distinguish
|
||||||
|
// between metrics emitted for CSI volumes which may be handled by different
|
||||||
|
// CSI plugin drivers.
|
||||||
|
func GetFullQualifiedPluginNameForVolume(pluginName string, spec *volume.Spec) string {
|
||||||
|
if spec != nil && spec.PersistentVolume != nil && spec.PersistentVolume.Spec.CSI != nil {
|
||||||
|
return fmt.Sprintf("%s:%s", pluginName, spec.PersistentVolume.Spec.CSI.Driver)
|
||||||
|
}
|
||||||
|
return pluginName
|
||||||
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ func (og *operationGenerator) GenerateVolumesAreAttachedFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: volumesAreAttachedFunc,
|
OperationFunc: volumesAreAttachedFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook("<n/a>", "verify_volumes_are_attached_per_node"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume("<n/a>", nil), "verify_volumes_are_attached_per_node"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ func (og *operationGenerator) GenerateBulkVolumeVerifyFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: bulkVolumeVerifyFunc,
|
OperationFunc: bulkVolumeVerifyFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(pluginName, "verify_volumes_are_attached"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(pluginName, nil), "verify_volumes_are_attached"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ func (og *operationGenerator) GenerateAttachVolumeFunc(
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: attachVolumeFunc,
|
OperationFunc: attachVolumeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(attachableVolumePlugin.GetPluginName(), "volume_attach"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(attachableVolumePlugin.GetPluginName(), volumeToAttach.VolumeSpec), "volume_attach"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ func (og *operationGenerator) GenerateDetachVolumeFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: getVolumePluginMgrFunc,
|
OperationFunc: getVolumePluginMgrFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(pluginName, "volume_detach"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(pluginName, volumeToDetach.VolumeSpec), "volume_detach"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -593,7 +593,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: mountVolumeFunc,
|
OperationFunc: mountVolumeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(volumePlugin.GetPluginName(), "volume_mount"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "volume_mount"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@ func (og *operationGenerator) GenerateUnmountVolumeFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: unmountVolumeFunc,
|
OperationFunc: unmountVolumeFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(volumePlugin.GetPluginName(), "volume_unmount"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToUnmount.VolumeSpec), "volume_unmount"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -780,7 +780,7 @@ func (og *operationGenerator) GenerateUnmountDeviceFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: unmountDeviceFunc,
|
OperationFunc: unmountDeviceFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(deviceMountableVolumePlugin.GetPluginName(), "unmount_device"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(deviceMountableVolumePlugin.GetPluginName(), deviceToDetach.VolumeSpec), "unmount_device"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -946,7 +946,7 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: mapVolumeFunc,
|
OperationFunc: mapVolumeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(blockVolumePlugin.GetPluginName(), "map_volume"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(blockVolumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "map_volume"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1015,7 +1015,7 @@ func (og *operationGenerator) GenerateUnmapVolumeFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: unmapVolumeFunc,
|
OperationFunc: unmapVolumeFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(blockVolumePlugin.GetPluginName(), "unmap_volume"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(blockVolumePlugin.GetPluginName(), volumeToUnmount.VolumeSpec), "unmap_volume"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1130,7 +1130,7 @@ func (og *operationGenerator) GenerateUnmapDeviceFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: unmapDeviceFunc,
|
OperationFunc: unmapDeviceFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(blockVolumePlugin.GetPluginName(), "unmap_device"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(blockVolumePlugin.GetPluginName(), deviceToDetach.VolumeSpec), "unmap_device"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1204,7 +1204,7 @@ func (og *operationGenerator) GenerateVerifyControllerAttachedVolumeFunc(
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: verifyControllerAttachedVolumeFunc,
|
OperationFunc: verifyControllerAttachedVolumeFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(volumePlugin.GetPluginName(), "verify_controller_attached_volume"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "verify_controller_attached_volume"),
|
||||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
|
@ -1321,7 +1321,7 @@ func (og *operationGenerator) GenerateExpandVolumeFunc(
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: expandVolumeFunc,
|
OperationFunc: expandVolumeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(volumePlugin.GetPluginName(), "expand_volume"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeSpec), "expand_volume"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1378,7 +1378,7 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: fsResizeFunc,
|
OperationFunc: fsResizeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(volumePlugin.GetPluginName(), "volume_fs_resize"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "volume_fs_resize"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue