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

Introducing http-endpoint #96

Closed
wants to merge 1 commit into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ spec:

#### Other recognized arguments

* `--health-port <number>`: TCP ports for listening for HTTP requests (default "9808")

* `--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.
* `--http-endpoint <port>`: The TCP network address where the HTTP server for diagnostics, including CSI driver health check and metrics, will listen (example: `:8080`). The default is `:9808`.

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

* `--health-port <number>`: TCP ports for listening for HTTP requests (default "9808")
* Removed in version 3.0.0, where the flag is replaced by `--http-endpoint`.

* `--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.
* Removed in version 3.0.0, where the flag is replaced by `--http-endpoint` and is always enabled.

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

## Community, discussion, contribution, and support
Expand Down
21 changes: 12 additions & 9 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package main
import (
"context"
"flag"
"net"
"fmt"
"net/http"
"sync"
"time"
Expand All @@ -32,13 +32,16 @@ import (
"github.com/kubernetes-csi/csi-lib-utils/rpc"
)

const (
defaultHttpEndpoint = ":9808"
)

// 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")
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`.")
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.")
httpEndpoint = flag.String("http-endpoint", defaultHttpEndpoint, fmt.Sprintf("The TCP network address where the HTTP server for diagnostics, including CSI driver health check and metrics, will listen (example: `:8080`). The default is `%s`.", defaultHttpEndpoint))
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
)

type healthProbe struct {
Expand Down Expand Up @@ -115,6 +118,7 @@ func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
csiConn, err := acquireConnection(context.Background(), metricsManager)
if err != nil {
Expand All @@ -137,13 +141,12 @@ func main() {
}

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

mux.HandleFunc("/healthz", hp.checkProbe)
klog.Infof("Serving requests to /healthz on: %s", addr)
err = http.ListenAndServe(addr, mux)
klog.Infof("ServeMux listening at %q", *httpEndpoint)
err = http.ListenAndServe(*httpEndpoint, mux)
if err != nil {
klog.Fatalf("failed to start http server with error: %v", err)
}
Expand Down