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

Correct connlib.Connect and update dependencies. #70

Merged
merged 2 commits into from
Aug 24, 2020
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 @@ -75,6 +75,10 @@ spec:

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

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

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

* All glog / klog arguments are supported, such as `-v <log level>` or `-alsologtostderr`.

## Community, discussion, contribution, and support
Expand Down
2 changes: 1 addition & 1 deletion cmd/livenessprobe/livenessprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/mock/gomock"
"github.com/kubernetes-csi/csi-test/driver"
"github.com/kubernetes-csi/csi-test/v4/driver"
)

const (
Expand Down
28 changes: 17 additions & 11 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ import (
"sync"
"time"

"k8s.io/klog"
"google.golang.org/grpc"
"k8s.io/klog/v2"

connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
"github.com/kubernetes-csi/csi-lib-utils/rpc"

"google.golang.org/grpc"
)

// Command line flags
var (
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
probeTimeout = flag.Duration("probe-timeout", time.Second, "Probe timeout in seconds")
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
healthzPort = flag.String("health-port", "9808", "TCP ports for listening healthz requests")
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.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
)

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

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

// acquireConnection wraps the connlib.Connect but adding support to context
// cancelation.
func acquireConnection(ctx context.Context) (conn *grpc.ClientConn, err error) {
func acquireConnection(ctx context.Context, metricsManager metrics.CSIMetricsManager) (conn *grpc.ClientConn, err error) {

var m sync.Mutex
var canceled bool
ready := make(chan bool)
go func() {
conn, err = connlib.Connect(*csiAddress)
conn, err = connlib.Connect(*csiAddress, metricsManager)

m.Lock()
defer m.Unlock()
Expand All @@ -111,8 +114,8 @@ func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

csiConn, err := acquireConnection(context.Background())
metricsManager := metrics.NewCSIMetricsManager("")
csiConn, err := acquireConnection(context.Background(), metricsManager)
if err != nil {
// connlib should retry forever so a returned error should mean
// the grpc client is misconfigured rather than an error on the network
Expand All @@ -131,6 +134,9 @@ func main() {
driverName: csiDriverName,
}

metricsManager.SetDriverName(csiDriverName)
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)

addr := net.JoinHostPort("0.0.0.0", *healthzPort)
http.HandleFunc("/healthz", hp.checkProbe)
klog.Infof("Serving requests to /healthz on: %s", addr)
Expand Down
21 changes: 9 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
module github.com/kubernetes-csi/livenessprobe

go 1.12
go 1.15

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