Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce metrics for pdcsi node #1952

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cmd/gce-pd-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,22 @@ func handle() {
}

var metricsManager *metrics.MetricsManager = nil
if *runControllerService && *httpEndpoint != "" {
runServiceWithMetrics := *runControllerService || *runNodeService
if runServiceWithMetrics && *httpEndpoint != "" {
mm := metrics.NewMetricsManager()
mm.InitializeHttpHandler(*httpEndpoint, *metricsPath)
mm.RegisterPDCSIMetric()

if metrics.IsGKEComponentVersionAvailable() {
mm.EmitGKEComponentVersion()
switch {
case *runControllerService:
mm.RegisterPDCSIMetric()
if metrics.IsGKEComponentVersionAvailable() {
mm.EmitGKEComponentVersion()
}
case *runNodeService:
if err := mm.EmmitProcessStartTime(); err != nil {
klog.Errorf("Failed to emit process start time: %v", err.Error())
}
mm.RegisterMountMetric()
}
metricsManager = &mm
}
Expand Down Expand Up @@ -250,6 +259,7 @@ func handle() {
DeviceInUseTimeout: *deviceInUseTimeout,
EnableDataCache: *enableDataCacheFlag,
DataCacheEnabledNodePool: isDataCacheEnabledNodePool(ctx, *nodeName),
MetricsManager: metricsManager,
}
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, nsArgs)
if *maxConcurrentFormatAndMount > 0 {
Expand Down
1 change: 1 addition & 0 deletions pkg/gce-pd-csi-driver/gce-pd-driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, devi
deviceInUseErrors: newDeviceErrMap(args.DeviceInUseTimeout),
EnableDataCache: args.EnableDataCache,
DataCacheEnabledNodePool: args.DataCacheEnabledNodePool,
metricsManager: args.MetricsManager,
}
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/gce-pd-csi-driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/metrics"
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/resizefs"
)
Expand Down Expand Up @@ -72,6 +73,8 @@ type GCENodeServer struct {
// Embed UnimplementedNodeServer to ensure the driver returns Unimplemented for any
// new RPC methods that might be introduced in future versions of the spec.
csi.UnimplementedNodeServer

metricsManager *metrics.MetricsManager
}

type NodeServerArgs struct {
Expand All @@ -84,6 +87,8 @@ type NodeServerArgs struct {
EnableDataCache bool

DataCacheEnabledNodePool bool

MetricsManager *metrics.MetricsManager
}

var _ csi.NodeServer = &GCENodeServer{}
Expand Down Expand Up @@ -416,6 +421,10 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
return &csi.NodeStageVolumeResponse{}, nil
}
}

if ns.metricsManager != nil {
ns.metricsManager.RecordMountErrorMetric(err)
}
return nil, status.Error(codes.Internal,
fmt.Sprintf("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v",
devicePath, stagingTargetPath, fstype, options, err.Error()))
Expand Down
6 changes: 3 additions & 3 deletions pkg/gce-pd-csi-driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func getTestGCEDriverWithCustomMounter(t *testing.T, mounter *mount.SafeFormatAn
func getCustomTestGCEDriver(t *testing.T, mounter *mount.SafeFormatAndMount, deviceUtils deviceutils.DeviceUtils, metaService metadataservice.MetadataService) *GCEDriver {
gceDriver := GetGCEDriver()
enableDataCache := false
nodeServer := NewNodeServer(gceDriver, mounter, deviceUtils, metaService, mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */})
nodeServer := NewNodeServer(gceDriver, mounter, deviceUtils, metaService, mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */, nil /*metricsMangager*/})
err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
if err != nil {
t.Fatalf("Failed to setup GCE Driver: %v", err)
Expand All @@ -63,7 +63,7 @@ func getCustomTestGCEDriver(t *testing.T, mounter *mount.SafeFormatAndMount, dev
func getTestBlockingMountGCEDriver(t *testing.T, readyToExecute chan chan struct{}) *GCEDriver {
gceDriver := GetGCEDriver()
mounter := mountmanager.NewFakeSafeBlockingMounter(readyToExecute)
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, true, false /*dataCacheEnableNodePool */})
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, true, false /*dataCacheEnableNodePool */, nil /*metricsMangager*/})
err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
if err != nil {
t.Fatalf("Failed to setup GCE Driver: %v", err)
Expand All @@ -75,7 +75,7 @@ func getTestBlockingFormatAndMountGCEDriver(t *testing.T, readyToExecute chan ch
gceDriver := GetGCEDriver()
enableDataCache := true
mounter := mountmanager.NewFakeSafeBlockingMounter(readyToExecute)
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */}).WithSerializedFormatAndMount(5*time.Second, 1)
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */, nil /*metricsMangager*/}).WithSerializedFormatAndMount(5*time.Second, 1)

err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/grpc/codes"
"k8s.io/component-base/metrics"
"k8s.io/klog/v2"
"k8s.io/mount-utils"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
)

Expand Down Expand Up @@ -53,6 +54,15 @@ var (
StabilityLevel: metrics.ALPHA,
},
[]string{"driver_name", "method_name", "grpc_status_code", "disk_type", "enable_confidential_storage", "enable_storage_pools"})

mountErrorMetric = metrics.NewCounterVec(&metrics.CounterOpts{
Subsystem: "node",
Name: "mount_errors",
Help: "Node server file system mounting errors",
StabilityLevel: metrics.ALPHA,
},
[]string{"error_type"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a SLO design doc for this metrics? We probably also want info of "driver_name", "grpc_status_code", "disk_type" etc. extra information?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is we need success calls and error calls to calculate the right SLO, so we probably need to emit both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out existing csi/k8s volume metrics to follow similar patterns.

)
)

type MetricsManager struct {
Expand All @@ -78,6 +88,10 @@ func (mm *MetricsManager) RegisterPDCSIMetric() {
mm.registry.MustRegister(pdcsiOperationErrorsMetric)
}

func (mm *MetricsManager) RegisterMountMetric() {
mm.registry.MustRegister(mountErrorMetric)
}

func (mm *MetricsManager) recordComponentVersionMetric() error {
v := getEnvVar(envGKEPDCSIVersion)
if v == "" {
Expand All @@ -101,6 +115,19 @@ func (mm *MetricsManager) RecordOperationErrorMetrics(
klog.Infof("Recorded PDCSI operation error code: %q", errCode)
}

func (mm *MetricsManager) RecordMountErrorMetric(err error) {
mntErr := &mount.MountError{}
if errors.As(err, mntErr) {
mountErrorMetric.WithLabelValues(string(mntErr.Type)).Inc()
}

klog.Infof("Recorded mount error type: %q", mntErr.Type)
}

func (mm *MetricsManager) EmmitProcessStartTime() error {
return metrics.RegisterProcessStartTime(mm.registry.Register)
}

func (mm *MetricsManager) EmitGKEComponentVersion() error {
mm.registerComponentVersionMetric()
if err := mm.recordComponentVersionMetric(); err != nil {
Expand Down