-
Notifications
You must be signed in to change notification settings - Fork 0
feat(observability): export readiness evidence gauges #142
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
Closed
seonghobae
wants to merge
5
commits into
fix/pin-hosted-runner-20260902-v2
from
codex/readiness-metrics
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e7f9d0
feat(observability): export readiness evidence gauges
codex fa9713b
Fix CodeRabbit issues in PR #142
coderabbitai[bot] 021d51d
fix(metrics): align admin auth readiness surfaces
codex 6667046
fix(metrics): clarify write-capable admin auth gauge
codex e7ef34d
chore(stack): integrate pinned hosted-runner prerequisite
seonghobae 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,7 +282,7 @@ impl AppState { | |
| dnsbl_origin: self.dnsbl_origin.clone(), | ||
| event_limit: self.event_limit, | ||
| credentials_source: self.credentials_source.as_str().to_string(), | ||
| admin_auth_configured: self.admin_token.is_some() || !self.admin_tokens.is_empty(), | ||
| admin_auth_configured: has_write_admin_credential(self), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1104,7 +1104,7 @@ async fn evaluate_request( | |
| async fn metrics(State(state): State<AppState>) -> impl IntoResponse { | ||
| let body = { | ||
| let data = state.inner.read().await; | ||
| prometheus_exposition(&kpi_snapshot_at(&data, now_unix())) | ||
| operational_prometheus_exposition(&state, &data, now_unix()) | ||
| }; | ||
| ( | ||
| [( | ||
|
|
@@ -1115,6 +1115,72 @@ async fn metrics(State(state): State<AppState>) -> impl IntoResponse { | |
| ) | ||
| } | ||
|
|
||
| fn operational_prometheus_exposition(state: &AppState, data: &AppData, now_unix: u64) -> String { | ||
| let kpis = kpi_snapshot_at(data, now_unix); | ||
| let readiness = commercial_readiness_snapshot_at(data, now_unix); | ||
| let routes_enabled = data.routes.iter().filter(|route| route.enabled).count(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Readiness gauges preserve endpoint semantics Both route gauges use the same enabled-route predicate as Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| let checks_passed = readiness | ||
| .checks | ||
| .iter() | ||
| .filter(|check| check.status == ReadinessStatus::Pass) | ||
| .count(); | ||
| let checks_failed = readiness | ||
| .checks | ||
| .iter() | ||
| .filter(|check| check.status == ReadinessStatus::Fail) | ||
| .count(); | ||
| let mut out = prometheus_exposition(&kpis); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_commercial_ready", | ||
| "Enterprise sale readiness flag (1=ready, 0=blocked).", | ||
| usize::from(readiness.ready_for_enterprise_sale), | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_commercial_blockers", | ||
| "Current count of commercial-readiness blockers.", | ||
| readiness.blockers.len(), | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_readiness_checks_passed", | ||
| "Commercial-readiness checks currently passing.", | ||
| checks_passed, | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_readiness_checks_failed", | ||
| "Commercial-readiness checks currently failing.", | ||
| checks_failed, | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_gateway_ready", | ||
| "Kubernetes readiness-style route readiness (1=ready, 0=not ready).", | ||
| usize::from(routes_enabled > 0), | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_gateway_routes_enabled", | ||
| "Enabled gateway route count used by the readiness probe.", | ||
| routes_enabled, | ||
| ); | ||
| append_prometheus_gauge( | ||
| &mut out, | ||
| "waf_ids_admin_auth_configured", | ||
| "Admin write authentication configured (1=write-capable credential configured, 0=no write-capable credential configured; readonly auth may still exist).", | ||
| usize::from(has_write_admin_credential(state)), | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
seonghobae marked this conversation as resolved.
|
||
| ); | ||
| out | ||
| } | ||
|
|
||
| fn append_prometheus_gauge(out: &mut String, name: &str, help: &str, value: usize) { | ||
| out.push_str(&format!( | ||
| "# HELP {name} {help}\n# TYPE {name} gauge\n{name} {value}\n" | ||
| )); | ||
| } | ||
|
|
||
| async fn get_commercial_license(State(state): State<AppState>) -> Json<CommercialProfile> { | ||
| Json(state.inner.read().await.commercial.clone()) | ||
| } | ||
|
|
@@ -3707,6 +3773,41 @@ mod tests { | |
| ); | ||
| let body = body_text(response).await; | ||
| assert!(body.contains("waf_ids_security_events_blocked")); | ||
| assert!(body.contains("waf_ids_commercial_ready 0")); | ||
| assert!(body.contains("waf_ids_commercial_blockers 4")); | ||
| assert!(body.contains("waf_ids_readiness_checks_passed 2")); | ||
| assert!(body.contains("waf_ids_readiness_checks_failed 4")); | ||
| assert!(body.contains("waf_ids_gateway_ready 1")); | ||
| assert!(body.contains("waf_ids_gateway_routes_enabled 1")); | ||
| assert!(body.contains("waf_ids_admin_auth_configured 0")); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn admin_auth_metric_requires_a_write_capable_credential() { | ||
| let readonly_app = build_app( | ||
| AppState::seeded(None).with_admin_tokens(parse_admin_tokens("read:auditor:readonly")), | ||
| ); | ||
| let readonly_health: HealthStatus = | ||
| json_body(app_request(&readonly_app, empty_request(Method::GET, "/healthz")).await) | ||
| .await; | ||
| assert!(!readonly_health.admin_auth_configured); | ||
| let readonly_body = | ||
| body_text(app_request(&readonly_app, empty_request(Method::GET, "/metrics")).await) | ||
| .await; | ||
| assert!(readonly_body.contains("waf_ids_admin_auth_configured 0")); | ||
| assert!(readonly_body.contains( | ||
| "# HELP waf_ids_admin_auth_configured Admin write authentication configured (1=write-capable credential configured, 0=no write-capable credential configured; readonly auth may still exist)." | ||
| )); | ||
|
|
||
| let writer_app = build_app( | ||
| AppState::seeded(None).with_admin_tokens(parse_admin_tokens("write:operator:write")), | ||
| ); | ||
| let writer_health: HealthStatus = | ||
| json_body(app_request(&writer_app, empty_request(Method::GET, "/healthz")).await).await; | ||
| assert!(writer_health.admin_auth_configured); | ||
| let writer_body = | ||
| body_text(app_request(&writer_app, empty_request(Method::GET, "/metrics")).await).await; | ||
| assert!(writer_body.contains("waf_ids_admin_auth_configured 1")); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
|
|
@@ -7645,6 +7746,14 @@ mod tests { | |
| let health = authed.health_status(); | ||
| assert_eq!(health.credentials_source, "file"); | ||
| assert!(health.admin_auth_configured); | ||
|
|
||
| let readonly = state | ||
| .clone() | ||
| .with_admin_tokens(parse_admin_tokens("tok:auditor:readonly")) | ||
| .with_credentials_source(CredentialSource::File); | ||
| let health = readonly.health_status(); | ||
| assert_eq!(health.credentials_source, "file"); | ||
| assert!(!health.admin_auth_configured); | ||
| } | ||
|
|
||
| fn clearfolio_test_config(base_url: &str) -> ClearfolioConfig { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.