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

Fix leak memory and upgrade csi-lib-util dependency #94

Merged
merged 1 commit into from
Dec 9, 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
  •  
  •  
  •  
13 changes: 11 additions & 2 deletions cmd/livenessprobe/livenessprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

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

Expand Down Expand Up @@ -83,7 +84,11 @@ func TestProbe(t *testing.T) {
outProbe := &csi.ProbeResponse{}
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1)

hp := &healthProbe{driverName: driverName}
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
hp := &healthProbe{
driverName: driverName,
metricsManager: metricsManager,
}

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.String() == "/healthz" {
Expand Down Expand Up @@ -121,7 +126,11 @@ func TestProbe_issue68(t *testing.T) {
outProbe := &csi.ProbeResponse{}
idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1)

hp := &healthProbe{driverName: driverName}
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
hp := &healthProbe{
driverName: driverName,
metricsManager: metricsManager,
}

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.String() == "/healthz" {
Expand Down
19 changes: 11 additions & 8 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ var (
)

type healthProbe struct {
driverName string
driverName string
metricsManager metrics.CSIMetricsManager
}

func (h *healthProbe) checkProbe(w http.ResponseWriter, req *http.Request) {
ctx, cancel := context.WithTimeout(req.Context(), *probeTimeout)
defer cancel()

conn, err := acquireConnection(ctx, metrics.NewCSIMetricsManager(""))
conn, err := acquireConnection(ctx, h.metricsManager)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down Expand Up @@ -114,7 +115,7 @@ func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()
metricsManager := metrics.NewCSIMetricsManager("")
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
csiConn, err := acquireConnection(context.Background(), metricsManager)
if err != nil {
// connlib should retry forever so a returned error should mean
Expand All @@ -131,16 +132,18 @@ func main() {
klog.Infof("CSI driver name: %q", csiDriverName)

hp := &healthProbe{
driverName: csiDriverName,
driverName: csiDriverName,
metricsManager: metricsManager,
}

mux := http.NewServeMux()
addr := net.JoinHostPort("0.0.0.0", *healthzPort)
metricsManager.RegisterToServer(mux, *metricsPath)
metricsManager.SetDriverName(csiDriverName)
metricsManager.StartMetricsEndpoint(*metricsAddress, *metricsPath)

addr := net.JoinHostPort("0.0.0.0", *healthzPort)
http.HandleFunc("/healthz", hp.checkProbe)
mux.HandleFunc("/healthz", hp.checkProbe)
klog.Infof("Serving requests to /healthz on: %s", addr)
err = http.ListenAndServe(addr, nil)
err = http.ListenAndServe(addr, mux)
if err != nil {
klog.Fatalf("failed to start http server with error: %v", err)
}
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ go 1.15
require (
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-lib-utils v0.9.0
Jiawei0227 marked this conversation as resolved.
Show resolved Hide resolved
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/grpc v1.29.0
k8s.io/klog/v2 v2.3.0
)
247 changes: 174 additions & 73 deletions go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Loading