Skip to content

Commit b2cf1cc

Browse files
committed
healthcheck: don't depend on --prometheus, always run healthcheck server
1 parent 2d6a62f commit b2cf1cc

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

pkg/agent/run.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,32 @@ func Run(cmd *cobra.Command, args []string) {
7575
}
7676
}()
7777
}
78-
if Flags.Prometheus {
79-
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus server on port :8081")
80-
go func() {
78+
79+
go func() {
80+
server := http.NewServeMux()
81+
82+
if Flags.Prometheus {
83+
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus on port :8081")
8184
prometheus.MustRegister(metricPayloadSize)
82-
metricsServer := http.NewServeMux()
83-
84-
// Health check endpoint. Since we haven't figured a good way of knowning
85-
// what "ready" means for the agent, we just return 200 OK inconditionally.
86-
// The goal is to satisfy some Kubernetes distributions, like OpenShift,
87-
// that require a liveness and health probe to be present for each pod.
88-
metricsServer.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
89-
w.WriteHeader(http.StatusOK)
90-
})
91-
metricsServer.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
92-
w.WriteHeader(http.StatusOK)
93-
})
94-
95-
metricsServer.Handle("/metrics", promhttp.Handler())
96-
err := http.ListenAndServe(":8081", metricsServer)
97-
if err != nil && !errors.Is(err, http.ErrServerClosed) {
98-
logs.Log.Fatalf("failed to run prometheus server: %s", err)
99-
}
100-
}()
101-
}
85+
server.Handle("/metrics", promhttp.Handler())
86+
}
87+
88+
// Health check endpoint. Since we haven't figured a good way of knowning
89+
// what "ready" means for the agent, we just return 200 OK inconditionally.
90+
// The goal is to satisfy some Kubernetes distributions, like OpenShift,
91+
// that require a liveness and health probe to be present for each pod.
92+
server.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
93+
w.WriteHeader(http.StatusOK)
94+
})
95+
server.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
96+
w.WriteHeader(http.StatusOK)
97+
})
98+
99+
err := http.ListenAndServe(":8081", server)
100+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
101+
logs.Log.Fatalf("failed to run the health check server: %s", err)
102+
}
103+
}()
102104

103105
_, isVenConn := preflightClient.(*client.VenConnClient)
104106
if isVenConn {

0 commit comments

Comments
 (0)