-
Notifications
You must be signed in to change notification settings - Fork 235
[WIP] improve: health probes showcase & docs to operations #3291
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| title: Health Probes | ||
| weight: 75 | ||
| --- | ||
|
|
||
| Operators running in Kubernetes should expose health probe endpoints so that the kubelet can detect startup | ||
| failures and runtime degradation. JOSDK provides the building blocks through its | ||
| [`RuntimeInfo`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java) | ||
| API. | ||
|
|
||
| ## RuntimeInfo | ||
|
|
||
| `RuntimeInfo` is available via `operator.getRuntimeInfo()` and exposes: | ||
|
|
||
| | Method | Purpose | | ||
| |---|---| | ||
| | `isStarted()` | `true` once the operator and all its controllers have fully started | | ||
| | `allEventSourcesAreHealthy()` | `true` when every registered event source (informers, polling sources, etc.) reports a healthy status | | ||
| | `unhealthyEventSources()` | returns a map of controller name → unhealthy event sources, useful for diagnostics | | ||
|
|
||
| These map naturally to Kubernetes probes: | ||
|
|
||
| - **Startup probe** → `isStarted()` — fails until all informers have synced and the operator is ready to | ||
| reconcile. | ||
| - **Readiness probe** → `allEventSourcesAreHealthy()` — fails if an informer loses its watch connection | ||
| or any event source reports an unhealthy status. | ||
|
|
||
| ## Setting Up Probe Endpoints | ||
|
|
||
| The example below uses [Jetty](https://eclipse.dev/jetty/) to expose health probe endpoints. Any HTTP | ||
| server library works — the key is calling the `RuntimeInfo` methods to determine the response code. | ||
|
|
||
| ```java | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.handler.ContextHandler; | ||
| import org.eclipse.jetty.server.handler.ContextHandlerCollection; | ||
|
|
||
| Operator operator = new Operator(); | ||
| operator.register(new MyReconciler()); | ||
| operator.start(); | ||
|
|
||
| var startup = new ContextHandler(new StartupHandler(operator), "/startup"); | ||
| var readiness = new ContextHandler(new ReadinessHandler(operator), "/ready"); | ||
| Server server = new Server(8080); | ||
| server.setHandler(new ContextHandlerCollection(startup, readiness)); | ||
| server.start(); | ||
| ``` | ||
|
|
||
| Where `StartupHandler` and `ReadinessHandler` extend `org.eclipse.jetty.server.Handler.Abstract` and | ||
| check `operator.getRuntimeInfo().isStarted()` and | ||
| `operator.getRuntimeInfo().allEventSourcesAreHealthy()` respectively. | ||
|
|
||
| See the | ||
| [`operations` sample operator](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/sample-operators/operations) | ||
| for a complete working example. | ||
|
|
||
| ## Kubernetes Deployment Configuration | ||
|
|
||
| Once your operator exposes probe endpoints, configure them in your Deployment manifest: | ||
|
|
||
| ```yaml | ||
| containers: | ||
| - name: operator | ||
| ports: | ||
| - name: probes | ||
| containerPort: 8080 | ||
| startupProbe: | ||
| httpGet: | ||
| path: /startup | ||
| port: probes | ||
| initialDelaySeconds: 1 | ||
| periodSeconds: 3 | ||
| failureThreshold: 20 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /ready | ||
| port: probes | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 5 | ||
| failureThreshold: 3 | ||
| ``` | ||
|
|
||
| The startup probe gives the operator time to start (up to ~60 s with the settings above). Once the startup | ||
| probe succeeds, the readiness probe takes over and will mark the pod as not-ready if any event source | ||
| becomes unhealthy. | ||
|
|
||
| ## Helm Chart Support | ||
|
|
||
| The [generic Helm chart](/docs/documentation/operations/helm-chart) supports health probes out of the box. | ||
| Enable them in your `values.yaml`: | ||
|
|
||
| ```yaml | ||
| probes: | ||
| port: 8080 | ||
| startup: | ||
| enabled: true | ||
| path: /startup | ||
| readiness: | ||
| enabled: true | ||
| path: /ready | ||
| ``` | ||
|
|
||
| All probe timing parameters (`initialDelaySeconds`, `periodSeconds`, `failureThreshold`) have sensible | ||
| defaults and can be overridden. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,9 +103,9 @@ observability sample (see below). | |
| #### Exploring metrics end-to-end | ||
|
|
||
| The | ||
| [`metrics-processing` sample operator](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/sample-operators/metrics-processing) | ||
| [`operations` sample operator](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/sample-operators/operations) | ||
| includes a full end-to-end test, | ||
| [`MetricsHandlingE2E`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java), | ||
| [`MetricsHandlingE2E`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/operations/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java), | ||
|
Comment on lines
+106
to
+108
|
||
| that: | ||
|
|
||
| 1. Installs a local observability stack (Prometheus, Grafana, OpenTelemetry Collector) via | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.sample.metrics; | ||
|
|
||
| import org.eclipse.jetty.server.Handler; | ||
| import org.eclipse.jetty.server.Request; | ||
| import org.eclipse.jetty.server.Response; | ||
| import org.eclipse.jetty.util.Callback; | ||
|
|
||
| import io.javaoperatorsdk.operator.Operator; | ||
|
|
||
| import static io.javaoperatorsdk.operator.sample.metrics.StartupHandler.sendMessage; | ||
|
|
||
| public class ReadinessHandler extends Handler.Abstract { | ||
|
|
||
| private final Operator operator; | ||
|
|
||
| public ReadinessHandler(Operator operator) { | ||
| this.operator = operator; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean handle(Request request, Response response, Callback callback) { | ||
| if (operator.getRuntimeInfo().allEventSourcesAreHealthy()) { | ||
| sendMessage(response, 200, "ready", callback); | ||
| } else { | ||
| sendMessage(response, 400, "not ready: an event source is not healthy", callback); | ||
| } | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The E2E workflow now targets
sample-operators/operations. If the module directory isn’t actually renamed in this PR (the diff still shows tests/resources undersample-operators/metrics-processing), CI will likely fail because the path won’t exist. Align the workflow path with the actual checked-in directory name, or include the directory rename in the PR.