Skip to content

Commit 6fd0ae8

Browse files
authored
Merge pull request #70 from humblec/livenessprobe
Correct connlib.Connect and update dependencies.
2 parents 094ef04 + 7f7b14d commit 6fd0ae8

File tree

667 files changed

+162635
-56962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

667 files changed

+162635
-56962
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ spec:
7575

7676
* `--probe-timeout <duration>`: Maximum duration of single `Probe()` call (default "1s").
7777

78+
* `--metrics-address <port>`: The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.
79+
80+
* `--metrics-path <path>`: The HTTP path where prometheus metrics will be exposed. Default is `/metrics`."
81+
7882
* All glog / klog arguments are supported, such as `-v <log level>` or `-alsologtostderr`.
7983

8084
## Community, discussion, contribution, and support

cmd/livenessprobe/livenessprobe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
csi "github.com/container-storage-interface/spec/lib/go/csi"
2929
"github.com/golang/mock/gomock"
30-
"github.com/kubernetes-csi/csi-test/driver"
30+
"github.com/kubernetes-csi/csi-test/v4/driver"
3131
)
3232

3333
const (

cmd/livenessprobe/main.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ import (
2424
"sync"
2525
"time"
2626

27-
"k8s.io/klog"
27+
"google.golang.org/grpc"
28+
"k8s.io/klog/v2"
2829

2930
connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
31+
"github.com/kubernetes-csi/csi-lib-utils/metrics"
3032
"github.com/kubernetes-csi/csi-lib-utils/rpc"
31-
32-
"google.golang.org/grpc"
3333
)
3434

3535
// Command line flags
3636
var (
37-
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
38-
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
39-
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
37+
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
38+
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
39+
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
40+
metricsAddress = flag.String("metrics-address", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
41+
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
4042
)
4143

4244
type healthProbe struct {
@@ -47,7 +49,7 @@ func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {
4749
ctx, cancel := context.WithTimeout(req.Context(), *probeTimeout)
4850
defer cancel()
4951

50-
conn, err := acquireConnection(ctx)
52+
conn, err := acquireConnection(ctx, metrics.NewCSIMetricsManager(""))
5153
if err != nil {
5254
w.WriteHeader(http.StatusInternalServerError)
5355
w.Write([]byte(err.Error()))
@@ -79,12 +81,13 @@ func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {
7981

8082
// acquireConnection wraps the connlib.Connect but adding support to context
8183
// cancelation.
82-
func acquireConnection(ctx context.Context) (conn *grpc.ClientConn, err error) {
84+
func acquireConnection(ctx context.Context, metricsManager metrics.CSIMetricsManager) (conn *grpc.ClientConn, err error) {
85+
8386
var m sync.Mutex
8487
var canceled bool
8588
ready := make(chan bool)
8689
go func() {
87-
conn, err = connlib.Connect(*csiAddress)
90+
conn, err = connlib.Connect(*csiAddress, metricsManager)
8891

8992
m.Lock()
9093
defer m.Unlock()
@@ -111,8 +114,8 @@ func main() {
111114
klog.InitFlags(nil)
112115
flag.Set("logtostderr", "true")
113116
flag.Parse()
114-
115-
csiConn, err := acquireConnection(context.Background())
117+
metricsManager := metrics.NewCSIMetricsManager("")
118+
csiConn, err := acquireConnection(context.Background(), metricsManager)
116119
if err != nil {
117120
// connlib should retry forever so a returned error should mean
118121
// the grpc client is misconfigured rather than an error on the network
@@ -131,6 +134,9 @@ func main() {
131134
driverName: csiDriverName,
132135
}
133136

137+
metricsManager.SetDriverName(csiDriverName)
138+
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)
139+
134140
addr := net.JoinHostPort("0.0.0.0", *healthzPort)
135141
http.HandleFunc("/healthz", hp.checkProbe)
136142
klog.Infof("Serving requests to /healthz on: %s", addr)

go.mod

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
module github.com/kubernetes-csi/livenessprobe
22

3-
go 1.12
3+
go 1.15
44

55
require (
6-
github.com/container-storage-interface/spec v1.1.0
7-
github.com/golang/mock v1.2.0
8-
github.com/golang/protobuf v1.3.1 // indirect
9-
github.com/kubernetes-csi/csi-lib-utils v0.6.1
10-
github.com/kubernetes-csi/csi-test v2.0.0+incompatible
11-
github.com/stretchr/testify v1.4.0 // indirect
12-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect
13-
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
6+
github.com/container-storage-interface/spec v1.3.0
7+
github.com/golang/mock v1.4.3
8+
github.com/golang/protobuf v1.4.2 // indirect
9+
github.com/kubernetes-csi/csi-lib-utils v0.7.0
10+
github.com/kubernetes-csi/csi-test/v4 v4.0.0-20200806214950-555d70a11a8b
11+
github.com/stretchr/testify v1.5.1 // indirect
1412
golang.org/x/text v0.3.3 // indirect
15-
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect
16-
google.golang.org/grpc v1.20.0
17-
k8s.io/klog v0.3.0
13+
google.golang.org/grpc v1.29.0
14+
k8s.io/klog/v2 v2.3.0
1815
)

0 commit comments

Comments
 (0)