Skip to content

[release-1.8] emit metrics even for success scenarios #1297

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

Merged
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
32 changes: 8 additions & 24 deletions pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("CreateVolume", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("CreateVolume", err, diskTypeForMetric)
}()
// Validate arguments
volumeCapabilities := req.GetVolumeCapabilities()
Expand Down Expand Up @@ -430,9 +428,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("DeleteVolume", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("DeleteVolume", err, diskTypeForMetric)
}()
// Validate arguments
volumeID := req.GetVolumeId()
Expand Down Expand Up @@ -476,9 +472,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("ControllerPublishVolume", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("ControllerPublishVolume", err, diskTypeForMetric)
}()
// Only valid requests will be accepted
_, _, err = gceCS.validateControllerPublishVolumeRequest(ctx, req)
Expand Down Expand Up @@ -638,9 +632,7 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("ControllerUnpublishVolume", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("ControllerUnpublishVolume", err, diskTypeForMetric)
}()
_, _, err = gceCS.validateControllerUnpublishVolumeRequest(ctx, req)
if err != nil {
Expand Down Expand Up @@ -749,9 +741,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("ValidateVolumeCapabilities", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("ValidateVolumeCapabilities", err, diskTypeForMetric)
}()
if req.GetVolumeCapabilities() == nil || len(req.GetVolumeCapabilities()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume Capabilities must be provided")
Expand Down Expand Up @@ -908,9 +898,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("CreateSnapshot", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("CreateSnapshot", err, diskTypeForMetric)
}()
// Validate arguments
volumeID := req.GetSourceVolumeId()
Expand Down Expand Up @@ -1145,9 +1133,7 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("DeleteSnapshot", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("DeleteSnapshot", err, diskTypeForMetric)
}()
// Validate arguments
snapshotID := req.GetSnapshotId()
Expand Down Expand Up @@ -1236,9 +1222,7 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
var err error
diskTypeForMetric := ""
defer func() {
if err != nil {
gceCS.Metrics.RecordOperationErrorMetrics("ControllerExpandVolume", err, diskTypeForMetric)
}
gceCS.Metrics.RecordOperationErrorMetrics("ControllerExpandVolume", err, diskTypeForMetric)
}()
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"os"

"google.golang.org/grpc/codes"
"k8s.io/component-base/metrics"
"k8s.io/klog/v2"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
Expand Down Expand Up @@ -90,7 +91,11 @@ func (mm *MetricsManager) RecordOperationErrorMetrics(
operationName string,
operationErr error,
diskType string) {
pdcsiOperationErrorsMetric.WithLabelValues(pdcsiDriverName, "/csi.v1.Controller/"+operationName, common.CodeForError(operationErr).String(), diskType).Inc()
err := codes.OK.String()
if operationErr != nil {
err = common.CodeForError(operationErr).String()
}
pdcsiOperationErrorsMetric.WithLabelValues(pdcsiDriverName, "/csi.v1.Controller/"+operationName, err, diskType).Inc()
}

func (mm *MetricsManager) EmitGKEComponentVersion() error {
Expand Down