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

Add prometheus metrics to CSI external-attacher using new csi-lib-utils library #201

Merged
merged 2 commits into from
Dec 31, 2019
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Note that the external-attacher does not scale with more replicas. Only one exte

* `--retry-interval-max`: The exponential backoff maximum value. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details. 5 minutes is used by default.

* `--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.

* `--metrics-path`: The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.

#### Other recognized arguments
* `--kubeconfig <path>`: Path to Kubernetes client configuration that the external-attacher uses to connect to Kubernetes API server. When omitted, default token provided by Kubernetes will be used. This option is useful only when the external-attacher does not run as a Kubernetes pod, e.g. for debugging.

Expand Down
10 changes: 9 additions & 1 deletion cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
"github.com/kubernetes-csi/csi-lib-utils/rpc"
"github.com/kubernetes-csi/external-attacher/pkg/attacher"
"github.com/kubernetes-csi/external-attacher/pkg/controller"
Expand Down Expand Up @@ -65,6 +66,9 @@ var (
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource lives. Defaults to the pod namespace if not set.")

reconcileSync = flag.Duration("reconcile-sync", 1*time.Minute, "Resync interval of the VolumeAttachment reconciler.")

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.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
)

var (
Expand Down Expand Up @@ -107,8 +111,10 @@ func main() {

factory := informers.NewSharedInformerFactory(clientset, *resync)
var handler controller.Handler
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)

// Connect to CSI.
csiConn, err := connection.Connect(*csiAddress, connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
csiConn, err := connection.Connect(*csiAddress, metricsManager, connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
if err != nil {
klog.Error(err.Error())
os.Exit(1)
Expand All @@ -129,6 +135,8 @@ func main() {
os.Exit(1)
}
klog.V(2).Infof("CSI driver name: %q", csiAttacher)
metricsManager.SetDriverName(csiAttacher)
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)

supportsService, err := supportsPluginControllerService(ctx, csiConn)
if err != nil {
Expand Down
69 changes: 28 additions & 41 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,56 @@ go 1.12
require (
github.com/container-storage-interface/spec v1.2.0
github.com/davecgh/go-spew v1.1.1
github.com/evanphx/json-patch v4.2.0+incompatible
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.1
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/golang/protobuf v1.3.2
github.com/imdario/mergo v0.3.7 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.6.1
github.com/kubernetes-csi/csi-lib-utils v0.7.0
github.com/kubernetes-csi/csi-test v2.0.0+incompatible
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7 // indirect
google.golang.org/grpc v1.19.1
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20191005115622-2e41325d9e4b
k8s.io/apimachinery v0.0.0-20191006235458-f9f2f3f8ab02
k8s.io/client-go v0.0.0-20190918200256-06eb1244587a
k8s.io/csi-translation-lib v0.0.0-20191009030015-17db17aaadeb
google.golang.org/grpc v1.26.0
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.1-beta.0
k8s.io/client-go v0.17.0
k8s.io/csi-translation-lib v0.17.0
k8s.io/klog v1.0.0
)

replace k8s.io/api => k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.0

replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604
replace k8s.io/apiserver => k8s.io/apiserver v0.17.0

replace k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d
replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.17.0

replace k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190918200908-1e17798da8c1
replace k8s.io/cloud-provider => k8s.io/cloud-provider v0.17.0

replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190918202139-0b14c719ca62
replace k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.17.0

replace k8s.io/client-go => k8s.io/client-go v0.0.0-20190918200256-06eb1244587a
replace k8s.io/code-generator => k8s.io/code-generator v0.17.1-beta.0

replace k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190918203125-ae665f80358a
replace k8s.io/component-base => k8s.io/component-base v0.17.0

replace k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20190918202959-c340507a5d48
replace k8s.io/cri-api => k8s.io/cri-api v0.17.1-beta.0

replace k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b
replace k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.17.0

replace k8s.io/component-base => k8s.io/component-base v0.0.0-20190918200425-ed2f0867c778
replace k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.17.0

replace k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190817025403-3ae76f584e79
replace k8s.io/kube-proxy => k8s.io/kube-proxy v0.17.0

replace k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190918201136-c3a845f1fbb2
replace k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.17.0

replace k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20190918202837-c54ce30c680e
replace k8s.io/kubectl => k8s.io/kubectl v0.17.0

replace k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20190918202429-08c8357f8e2d
replace k8s.io/kubelet => k8s.io/kubelet v0.17.0

replace k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20190918202713-c34a54b3ec8e
replace k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.17.0

replace k8s.io/kubectl => k8s.io/kubectl v0.0.0-20190602132728-7075c07e78bf
replace k8s.io/metrics => k8s.io/metrics v0.17.0

replace k8s.io/kubelet => k8s.io/kubelet v0.0.0-20190918202550-958285cf3eef
replace k8s.io/node-api => k8s.io/node-api v0.17.0

replace k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20190918203421-225f0541b3ea
replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.17.0

replace k8s.io/metrics => k8s.io/metrics v0.0.0-20190918202012-3c1ca76f5bda
replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.17.0

replace k8s.io/node-api => k8s.io/node-api v0.0.0-20190918203548-2c4c2679bece

replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20190918201353-5cc279503896

replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.0.0-20190918202305-ed68a9f09ae1

replace k8s.io/sample-controller => k8s.io/sample-controller v0.0.0-20190918201537-fabef0de90df
replace k8s.io/sample-controller => k8s.io/sample-controller v0.17.0
Loading