Skip to content

Commit 2fb6b19

Browse files
committed
Introduce metrics library
1 parent 2127c90 commit 2fb6b19

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ Note that the external-provisioner does not scale with more replicas. Only one e
5555

5656
* `--timeout <duration>`: Timeout of all calls to CSI driver. It should be set to value that accommodates majority of `ControllerCreateVolume` and `ControllerDeleteVolume` calls. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details. 15 seconds is used by default.
5757

58-
* `--retry-interval-start <duration>` - Initial retry interval of failed provisioning or deletion. It doubles with each failure, up to `--retry-interval-max` and then it stops increasing. Default value is 1 second. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details.
58+
* `--retry-interval-start <duration>`: Initial retry interval of failed provisioning or deletion. It doubles with each failure, up to `--retry-interval-max` and then it stops increasing. Default value is 1 second. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details.
5959

60-
* `--retry-interval-max <duration>` - Maximum retry interval of failed provisioning or deletion. Default value is 5 minutes. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details.
60+
* `--retry-interval-max <duration>`: Maximum retry interval of failed provisioning or deletion. Default value is 5 minutes. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details.
6161

6262
* `--worker-threads <num>`: Number of simultaneously running `ControllerCreateVolume` and `ControllerDeleteVolume` operations. Default value is `100`.
6363

64+
* `--metrics-address`: The TCP network address address where the prometheus metrics endpoint will run (example: `:8080` which corresponds to port 8080 on local host). The default is empty string, which means metrics endpoint is disabled.
65+
66+
* `--metrics-path`: The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.
67+
6468
#### Other recognized arguments
6569
* `--feature-gates <gates>`: A set of comma separated `<feature-name>=<true|false>` pairs that describe feature gates for alpha/experimental features. See [list of features](#feature-status) or `--help` output for list of recognized features. Example: `--feature-gates Topology=true` to enable Topology feature that's disabled by default.
6670

cmd/csi-provisioner/csi-provisioner.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/kubernetes-csi/csi-lib-utils/deprecatedflags"
3232
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
33+
"github.com/kubernetes-csi/csi-lib-utils/metrics"
3334
ctrl "github.com/kubernetes-csi/external-provisioner/pkg/controller"
3435
snapclientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
3536
"sigs.k8s.io/sig-storage-lib-external-provisioner/controller"
@@ -43,7 +44,7 @@ import (
4344

4445
utilfeature "k8s.io/apiserver/pkg/util/feature"
4546
"k8s.io/client-go/informers"
46-
"k8s.io/client-go/listers/core/v1"
47+
v1 "k8s.io/client-go/listers/core/v1"
4748
storagelisters "k8s.io/client-go/listers/storage/v1beta1"
4849
utilflag "k8s.io/component-base/cli/flag"
4950
csitrans "k8s.io/csi-translation-lib"
@@ -68,6 +69,9 @@ var (
6869
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource lives. Defaults to the pod namespace if not set.")
6970
strictTopology = flag.Bool("strict-topology", false, "Passes only selected node topology to CreateVolume Request, unlike default behavior of passing aggregated cluster topologies that match with topology keys of the selected node.")
7071

72+
metricsAddress = flag.String("metrics-address", "", "The TCP network address address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
73+
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
74+
7175
featureGates map[string]bool
7276
provisionController *controller.ProvisionController
7377
version = "unknown"
@@ -135,7 +139,9 @@ func main() {
135139
klog.Fatalf("Error getting server version: %v", err)
136140
}
137141

138-
grpcClient, err := ctrl.Connect(*csiEndpoint)
142+
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
143+
144+
grpcClient, err := ctrl.Connect(*csiEndpoint, metricsManager)
139145
if err != nil {
140146
klog.Error(err.Error())
141147
os.Exit(1)
@@ -153,6 +159,8 @@ func main() {
153159
klog.Fatalf("Error getting CSI driver name: %s", err)
154160
}
155161
klog.V(2).Infof("Detected CSI driver %s", provisionerName)
162+
metricsManager.SetDriverName(provisionerName)
163+
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)
156164

157165
pluginCapabilities, controllerCapabilities, err := ctrl.GetDriverCapabilities(grpcClient, *operationTimeout)
158166
if err != nil {

pkg/controller/controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ import (
3030

3131
"github.com/container-storage-interface/spec/lib/go/csi"
3232
"github.com/kubernetes-csi/csi-lib-utils/connection"
33+
"github.com/kubernetes-csi/csi-lib-utils/metrics"
3334
snapapi "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
3435
snapclientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
3536
"sigs.k8s.io/sig-storage-lib-external-provisioner/controller"
3637
"sigs.k8s.io/sig-storage-lib-external-provisioner/util"
3738

38-
"k8s.io/api/core/v1"
39+
v1 "k8s.io/api/core/v1"
3940
storagev1 "k8s.io/api/storage/v1"
4041
"k8s.io/apimachinery/pkg/api/resource"
4142
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -214,8 +215,8 @@ var (
214215
provisionerIDKey = "storage.kubernetes.io/csiProvisionerIdentity"
215216
)
216217

217-
func Connect(address string) (*grpc.ClientConn, error) {
218-
return connection.Connect(address, connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
218+
func Connect(address string, metricsManager metrics.CSIMetricsManager) (*grpc.ClientConn, error) {
219+
return connection.Connect(address, metricsManager, connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
219220
}
220221

221222
func Probe(conn *grpc.ClientConn, singleCallTimeout time.Duration) error {

0 commit comments

Comments
 (0)