-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: better startup and readiness probes #976
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
Open
razvan
wants to merge
13
commits into
main
Choose a base branch
from
worktree-nifi-2x-health-probes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2eefa4a
feat: add exec-based NiFi 2.x management-server probe builders
razvan 51bdfa7
feat: gate NiFi startup/readiness on management-server health endpoints
razvan 236210b
feat: pin NiFi management-server address explicitly via JVM property
razvan e67829a
test: assert NiFi 2.x management-server probes and readiness gating i…
razvan c5ba5fc
fix: set explicit timeout_seconds on management-server exec probes
razvan 2a8df57
fix: revert retry-unsafe NotReady polling assertion in cluster_operat…
razvan cf041f0
fix: increase probe timeout_seconds from 3 to 5 for real headroom
razvan 63267ee
docs: changelog entry for NiFi 2.x management-server health probes
razvan 88a8f27
refactor: relocate MANAGEMENT_SERVER_PORT, document override caveat, …
razvan 6e04800
Update the changelog and cleanups
razvan 19c6f97
Move liveliness probe to probes.rs
razvan 2033b58
Fix the kuttl smoke test
razvan a5795a9
Extract the management IP into a constant
razvan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
rust/operator-binary/src/controller/build/resource/probes.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| //! Builds the exec-based startup and readiness probes that check NiFi 2.x's | ||
| //! local, unauthenticated management-server endpoints (`/health` and | ||
| //! `/health/cluster`). | ||
| //! | ||
| //! The management server binds `127.0.0.1` only, so these must be `exec` | ||
| //! probes using `curl` from inside the container - a `httpGet` probe cannot | ||
| //! reach a loopback-only address. | ||
|
|
||
| use stackable_operator::k8s_openapi::{ | ||
| api::core::v1::{ExecAction, Probe, TCPSocketAction}, | ||
| apimachinery::pkg::util::intstr::IntOrString, | ||
| }; | ||
|
|
||
| use crate::controller::build::{ | ||
| HTTPS_PORT_NAME, MANAGEMENT_SERVER_ADDRESS, MANAGEMENT_SERVER_PORT, | ||
| }; | ||
|
|
||
| fn management_health_exec(path: &str) -> ExecAction { | ||
| ExecAction { | ||
| command: Some(vec![ | ||
| "/bin/bash".to_string(), | ||
| "-euo".to_string(), | ||
| "pipefail".to_string(), | ||
| "-c".to_string(), | ||
| format!( | ||
| "curl --fail --silent --show-error --output /dev/null http://{MANAGEMENT_SERVER_ADDRESS}:{MANAGEMENT_SERVER_PORT}{path}" | ||
| ), | ||
| ]), | ||
| } | ||
| } | ||
| pub fn management_startup_probe() -> Probe { | ||
| Probe { | ||
| initial_delay_seconds: Some(10), | ||
| period_seconds: Some(10), | ||
| timeout_seconds: Some(5), | ||
| failure_threshold: Some(20 * 6), | ||
| exec: Some(management_health_exec("/health")), | ||
| ..Probe::default() | ||
| } | ||
| } | ||
| pub fn management_readiness_probe() -> Probe { | ||
| Probe { | ||
| period_seconds: Some(10), | ||
| timeout_seconds: Some(5), | ||
| failure_threshold: Some(3), | ||
| exec: Some(management_health_exec("/health/cluster")), | ||
| ..Probe::default() | ||
| } | ||
| } | ||
|
|
||
| pub fn tcp_liveliness_probe() -> Probe { | ||
| Probe { | ||
| initial_delay_seconds: Some(10), | ||
| period_seconds: Some(10), | ||
| tcp_socket: Some(TCPSocketAction { | ||
| port: IntOrString::String(HTTPS_PORT_NAME.to_string()), | ||
| ..TCPSocketAction::default() | ||
| }), | ||
| ..Probe::default() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn startup_probe_execs_curl_against_health_endpoint() { | ||
| let probe = management_startup_probe(); | ||
|
|
||
| let command = probe | ||
| .exec | ||
| .expect("startup probe must be an exec probe") | ||
| .command | ||
| .expect("exec action must have a command"); | ||
| let script = command.last().expect("bash -c script argument"); | ||
|
|
||
| assert!( | ||
| script.contains("http://127.0.0.1:52020/health") && !script.contains("/health/cluster"), | ||
| "expected curl against /health, got: {script}" | ||
| ); | ||
| assert_eq!(probe.failure_threshold, Some(120)); | ||
| assert_eq!(probe.timeout_seconds, Some(5)); | ||
| assert!( | ||
| probe.tcp_socket.is_none(), | ||
| "must not fall back to tcp_socket" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn readiness_probe_execs_curl_against_cluster_health_endpoint() { | ||
| let probe = management_readiness_probe(); | ||
|
|
||
| let command = probe | ||
| .exec | ||
| .expect("readiness probe must be an exec probe") | ||
| .command | ||
| .expect("exec action must have a command"); | ||
| let script = command.last().expect("bash -c script argument"); | ||
|
|
||
| assert!( | ||
| script.contains("http://127.0.0.1:52020/health/cluster"), | ||
| "expected curl against /health/cluster, got: {script}" | ||
| ); | ||
| assert_eq!(probe.failure_threshold, Some(3)); | ||
| assert_eq!(probe.timeout_seconds, Some(5)); | ||
| assert_eq!( | ||
| probe.initial_delay_seconds, None, | ||
| "readiness probe delay is redundant: k8s already suppresses readiness checks \ | ||
| until the startup probe succeeds" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn probes_use_bash_pipefail_wrapper_not_bare_curl_argv() { | ||
| for probe in [management_startup_probe(), management_readiness_probe()] { | ||
| let command = probe.exec.unwrap().command.unwrap(); | ||
| assert_eq!( | ||
| command[..4], | ||
| [ | ||
| "/bin/bash".to_string(), | ||
| "-euo".to_string(), | ||
| "pipefail".to_string(), | ||
| "-c".to_string(), | ||
| ], | ||
| "exec command must follow the repo's bash -euo pipefail -c convention" | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be hard-coded (same further up)? I know it was, but seems like it shouldn't be.
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.
I had a long chat with Claude on this topic and the conclusion was that this is the recommended way
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.
I made the IP address a constant here in case this is what you meant.