Use csi-lib-utils v0.10.0
This commit is contained in:
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/google/gofuzz v1.2.0
|
||||
github.com/imdario/mergo v0.3.11 // indirect
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.9.0
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.10.0
|
||||
github.com/kubernetes-csi/csi-test/v4 v4.0.2
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.1.0
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
|
6
go.sum
6
go.sum
@@ -118,7 +118,6 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
|
||||
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
|
||||
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
|
||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
|
||||
github.com/container-storage-interface/spec v1.2.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
|
||||
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
|
||||
github.com/container-storage-interface/spec v1.5.0 h1:lvKxe3uLgqQeVQcrnL2CPQKISoKjTJxojEs9cBk+HXo=
|
||||
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
|
||||
@@ -390,8 +389,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.9.0 h1:TbuDmxoVqM+fvVkzG/7sShyX/8jUln0ElLHuETcsQJI=
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.9.0/go.mod h1:8E2jVUX9j3QgspwHXa6LwyN7IHQDjW9jX3kwoWnSC+M=
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.10.0 h1:Aqm8X81eCzzfH/bvIEqSWtcbK9HF9NbFk4d+le1snVA=
|
||||
github.com/kubernetes-csi/csi-lib-utils v0.10.0/go.mod h1:BmGZZB16L18+9+Lgg9YWwBKfNEHIDdgGfAyuW6p2NV0=
|
||||
github.com/kubernetes-csi/csi-test/v4 v4.0.2 h1:MNj94SFHOGK6lOy+yDgxI+zlFWaPcgByqBH3JZZGyZI=
|
||||
github.com/kubernetes-csi/csi-test/v4 v4.0.2/go.mod h1:z3FYigjLFAuzmFzKdHQr8gUPm5Xr4Du2twKcxfys0eI=
|
||||
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
|
||||
@@ -997,7 +996,6 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
||||
google.golang.org/grpc v1.29.0/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
|
38
vendor/github.com/kubernetes-csi/csi-lib-utils/connection/connection.go
generated
vendored
38
vendor/github.com/kubernetes-csi/csi-lib-utils/connection/connection.go
generated
vendored
@@ -84,7 +84,8 @@ func ExitOnConnectionLoss() func() bool {
|
||||
if err := ioutil.WriteFile(terminationLogPath, []byte(terminationMsg), 0644); err != nil {
|
||||
klog.Errorf("%s: %s", terminationLogPath, err)
|
||||
}
|
||||
klog.Fatalf(terminationMsg)
|
||||
klog.Exit(terminationMsg)
|
||||
// Not reached.
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -150,7 +151,7 @@ func connect(
|
||||
return nil, errors.New("OnConnectionLoss callback only supported for unix:// addresses")
|
||||
}
|
||||
|
||||
klog.Infof("Connecting to %s", address)
|
||||
klog.V(5).Infof("Connecting to %s", address)
|
||||
|
||||
// Connect in background.
|
||||
var conn *grpc.ClientConn
|
||||
@@ -191,6 +192,13 @@ type ExtendedCSIMetricsManager struct {
|
||||
metrics.CSIMetricsManager
|
||||
}
|
||||
|
||||
type AdditionalInfo struct {
|
||||
Migrated string
|
||||
}
|
||||
type AdditionalInfoKeyType struct{}
|
||||
|
||||
var AdditionalInfoKey AdditionalInfoKeyType
|
||||
|
||||
// RecordMetricsClientInterceptor is a gPRC unary interceptor for recording metrics for CSI operations
|
||||
// in a gRPC client.
|
||||
func (cmm ExtendedCSIMetricsManager) RecordMetricsClientInterceptor(
|
||||
@@ -203,11 +211,35 @@ func (cmm ExtendedCSIMetricsManager) RecordMetricsClientInterceptor(
|
||||
start := time.Now()
|
||||
err := invoker(ctx, method, req, reply, cc, opts...)
|
||||
duration := time.Since(start)
|
||||
cmm.RecordMetrics(
|
||||
|
||||
var cmmBase metrics.CSIMetricsManager
|
||||
cmmBase = cmm
|
||||
if cmm.HaveAdditionalLabel(metrics.LabelMigrated) {
|
||||
// record migration status
|
||||
additionalInfo := ctx.Value(AdditionalInfoKey)
|
||||
migrated := "false"
|
||||
if additionalInfo != nil {
|
||||
additionalInfoVal, ok := additionalInfo.(AdditionalInfo)
|
||||
if !ok {
|
||||
klog.Errorf("Failed to record migrated status, cannot convert additional info %v", additionalInfo)
|
||||
return err
|
||||
}
|
||||
migrated = additionalInfoVal.Migrated
|
||||
}
|
||||
cmmv, metricsErr := cmm.WithLabelValues(map[string]string{metrics.LabelMigrated: migrated})
|
||||
if metricsErr != nil {
|
||||
klog.Errorf("Failed to record migrated status, error: %v", metricsErr)
|
||||
} else {
|
||||
cmmBase = cmmv
|
||||
}
|
||||
}
|
||||
// Record the default metric
|
||||
cmmBase.RecordMetrics(
|
||||
method, /* operationName */
|
||||
err, /* operationErr */
|
||||
duration, /* operationDuration */
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
18
vendor/github.com/kubernetes-csi/csi-lib-utils/metrics/metrics.go
generated
vendored
18
vendor/github.com/kubernetes-csi/csi-lib-utils/metrics/metrics.go
generated
vendored
@@ -47,6 +47,9 @@ const (
|
||||
labelGrpcStatusCode = "grpc_status_code"
|
||||
unknownCSIDriverName = "unknown-driver"
|
||||
|
||||
// LabelMigrated is the Label that indicate whether this is a CSI migration operation
|
||||
LabelMigrated = "migrated"
|
||||
|
||||
// CSI Operation Latency with status code total - Histogram Metric
|
||||
operationsLatencyMetricName = "operations_seconds"
|
||||
operationsLatencyHelp = "Container Storage Interface operation duration with gRPC error code status total"
|
||||
@@ -83,6 +86,10 @@ type CSIMetricsManager interface {
|
||||
// and then accumulates values.
|
||||
WithLabelValues(labels map[string]string) (CSIMetricsManager, error)
|
||||
|
||||
// HaveAdditionalLabel can be used to check if the additional label
|
||||
// value is defined in the metrics manager
|
||||
HaveAdditionalLabel(name string) bool
|
||||
|
||||
// SetDriverName is called to update the CSI driver name. This should be done
|
||||
// as soon as possible, otherwise metrics recorded by this manager will be
|
||||
// recorded with an "unknown-driver" driver_name.
|
||||
@@ -149,6 +156,13 @@ func WithLabels(labels map[string]string) MetricsManagerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigration adds the migrated field to the current metrics label
|
||||
func WithMigration() MetricsManagerOption {
|
||||
return func(cmm *csiMetricsManager) {
|
||||
cmm.additionalLabelNames = append(cmm.additionalLabelNames, LabelMigrated)
|
||||
}
|
||||
}
|
||||
|
||||
// WithProcessStartTime controlls whether process_start_time_seconds is registered
|
||||
// in the registry of the metrics manager. It's enabled by default out of convenience
|
||||
// (no need to do anything special in most sidecars) but should be disabled in more
|
||||
@@ -316,7 +330,7 @@ func (cmmv *csiMetricsManagerWithValues) WithLabelValues(labels map[string]strin
|
||||
}
|
||||
// Now add all new values.
|
||||
for name, value := range labels {
|
||||
if !extended.haveAdditionalLabel(name) {
|
||||
if !extended.HaveAdditionalLabel(name) {
|
||||
return nil, fmt.Errorf("label %q was not defined via WithLabelNames", name)
|
||||
}
|
||||
if v, ok := extended.additionalValues[name]; ok {
|
||||
@@ -327,7 +341,7 @@ func (cmmv *csiMetricsManagerWithValues) WithLabelValues(labels map[string]strin
|
||||
return extended, nil
|
||||
}
|
||||
|
||||
func (cmm *csiMetricsManager) haveAdditionalLabel(name string) bool {
|
||||
func (cmm *csiMetricsManager) HaveAdditionalLabel(name string) bool {
|
||||
for _, n := range cmm.additionalLabelNames {
|
||||
if n == name {
|
||||
return true
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -56,7 +56,7 @@ github.com/imdario/mergo
|
||||
github.com/inconshreveable/mousetrap
|
||||
# github.com/json-iterator/go v1.1.11
|
||||
github.com/json-iterator/go
|
||||
# github.com/kubernetes-csi/csi-lib-utils v0.9.0
|
||||
# github.com/kubernetes-csi/csi-lib-utils v0.10.0
|
||||
## explicit
|
||||
github.com/kubernetes-csi/csi-lib-utils/connection
|
||||
github.com/kubernetes-csi/csi-lib-utils/leaderelection
|
||||
|
Reference in New Issue
Block a user