Skip to content

Commit b980579

Browse files
committed
fixup! fix: add readyz endpoint
1 parent dae1f06 commit b980579

File tree

9 files changed

+27
-17
lines changed

9 files changed

+27
-17
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ After running the above, if you see `Clusterrolebinding "cluster-admin-binding"
346346

347347
#### Healthcheck Endpoints
348348

349-
The following healthcheck endpoints are available, some of which are used to determine the result of the aforementioned probes:
349+
The following healthcheck endpoints are available (`self` refers to the telemetry port, while `main` refers to the exposition port):
350350

351-
* `/healthz`: Returns a 200 status code if the application is running. We recommend to use this for the startup probe.
352-
* `/livez`: Returns a 200 status code if the application is not affected by an outage of the Kubernetes API Server. We recommend to using this for the liveness probe.
353-
* `/readyz`: Returns a 200 status code if the application is ready to accept traffic. We recommend using this for the readiness probe.
351+
* `/healthz` (exposed on `main`): Returns a 200 status code if the application is running. We recommend to use this for the startup probe.
352+
* `/livez` (exposed on `main`): Returns a 200 status code if the application is not affected by an outage of the Kubernetes API Server. We recommend to using this for the liveness probe.
353+
* `/readyz` (exposed on `self`): Returns a 200 status code if the application is ready to accept traffic. We recommend using this for the readiness probe.
354354

355355
Note that it is discouraged to use the telemetry metrics endpoint for any probe when proxying the exposition data.
356356

README.md.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ After running the above, if you see `Clusterrolebinding "cluster-admin-binding"
347347

348348
#### Healthcheck Endpoints
349349

350-
The following healthcheck endpoints are available, some of which are used to determine the result of the aforementioned probes:
350+
The following healthcheck endpoints are available (`self` refers to the telemetry port, while `main` refers to the exposition port):
351351

352-
* `/healthz`: Returns a 200 status code if the application is running. We recommend to use this for the startup probe.
353-
* `/livez`: Returns a 200 status code if the application is not affected by an outage of the Kubernetes API Server. We recommend to using this for the liveness probe.
354-
* `/readyz`: Returns a 200 status code if the application is ready to accept traffic. We recommend using this for the readiness probe.
352+
* `/healthz` (exposed on `main`): Returns a 200 status code if the application is running. We recommend to use this for the startup probe.
353+
* `/livez` (exposed on `main`): Returns a 200 status code if the application is not affected by an outage of the Kubernetes API Server. We recommend to using this for the liveness probe.
354+
* `/readyz` (exposed on `self`): Returns a 200 status code if the application is ready to accept traffic. We recommend using this for the readiness probe.
355355

356356
Note that it is discouraged to use the telemetry metrics endpoint for any probe when proxying the exposition data.
357357

examples/autosharding/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
readinessProbe:
5151
httpGet:
5252
path: /readyz
53-
port: http-metrics
53+
port: telemetry
5454
initialDelaySeconds: 5
5555
timeoutSeconds: 5
5656
securityContext:

examples/daemonsetsharding/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
readinessProbe:
4646
httpGet:
4747
path: /readyz
48-
port: http-metrics
48+
port: telemetry
4949
initialDelaySeconds: 5
5050
timeoutSeconds: 5
5151
securityContext:

examples/daemonsetsharding/deployment-no-node-pods.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
readinessProbe:
4141
httpGet:
4242
path: /readyz
43-
port: http-metrics
43+
port: telemetry
4444
initialDelaySeconds: 5
4545
timeoutSeconds: 5
4646
securityContext:

examples/daemonsetsharding/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
readinessProbe:
4040
httpGet:
4141
path: /readyz
42-
port: http-metrics
42+
port: telemetry
4343
initialDelaySeconds: 5
4444
timeoutSeconds: 5
4545
securityContext:

examples/standard/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
readinessProbe:
3838
httpGet:
3939
path: /readyz
40-
port: http-metrics
40+
port: telemetry
4141
initialDelaySeconds: 5
4242
timeoutSeconds: 5
4343
securityContext:

jsonnet/kube-state-metrics/kube-state-metrics.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
path: '/livez',
197197
} },
198198
readinessProbe: { timeoutSeconds: 5, initialDelaySeconds: 5, httpGet: {
199-
port: "http-metrics",
199+
port: "telemetry",
200200
path: '/readyz',
201201
} },
202202
};

pkg/app/server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
versionCollector "github.com/prometheus/client_golang/prometheus/collectors/version"
4343
"github.com/prometheus/client_golang/prometheus/promauto"
4444
"github.com/prometheus/client_golang/prometheus/promhttp"
45+
"github.com/prometheus/client_golang/prometheus/testutil"
4546
"github.com/prometheus/common/version"
4647
"github.com/prometheus/exporter-toolkit/web"
4748

@@ -377,6 +378,18 @@ func buildTelemetryServer(registry prometheus.Gatherer) *http.ServeMux {
377378
// Add metricsPath
378379
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorLog: promLogger{}}))
379380

381+
// Add readyzPath
382+
mux.Handle(readyzPath, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
383+
count, err := testutil.GatherAndCount(registry)
384+
if err != nil || count == 0 {
385+
w.WriteHeader(http.StatusServiceUnavailable)
386+
w.Write([]byte(http.StatusText(http.StatusServiceUnavailable)))
387+
return
388+
}
389+
w.WriteHeader(http.StatusOK)
390+
w.Write([]byte(http.StatusText(http.StatusOK)))
391+
}))
392+
380393
// Add index
381394
landingConfig := web.LandingConfig{
382395
Name: "kube-state-metrics",
@@ -426,9 +439,6 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
426439
// Add livezPath
427440
mux.Handle(livezPath, handleClusterDelegationForProber(client, livezPath))
428441

429-
// Add readyzPath
430-
mux.Handle(readyzPath, handleClusterDelegationForProber(client, readyzPath))
431-
432442
// Add healthzPath
433443
mux.Handle(healthzPath, handleClusterDelegationForProber(client, healthzPath))
434444

0 commit comments

Comments
 (0)