Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: alerts and jobq-graph handlers take their own sub-state via FromRef

This commit is contained in:
atlas 2026-11-28 06:58:15 +01:00 • committed by mara
commit b9687c54f2
2 changed files with 49 additions and 4 deletions

View file

@ -23,7 +23,8 @@ use problem_details::ProblemDetails;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::routes::{AppState, error_problem};
use super::AlertsState;
use crate::routes::error_problem;
/// The env var `swarm-controller.nix` sets.
const URL_ENV: &str = "SWARM_CONTROLLER_GRAFANA_URL";
@ -214,7 +215,7 @@ pub(crate) fn from_env() -> Option<Arc<Grafana>> {
tag = "alerts"
)]
pub(crate) async fn get_alerts(
State(state): State<AppState>,
State(state): State<AlertsState>,
) -> Result<Json<Vec<Alert>>, ProblemDetails> {
let Some(grafana) = state.alerts.as_ref() else {
return Err(error_problem(

View file

@ -5,3 +5,26 @@ pub(crate) mod alerts;
pub(crate) mod held_deploys;
pub(crate) mod otel_http_client;
pub(crate) mod vcs_metrics;
use std::sync::Arc;
use axum::extract::FromRef;
use crate::routes::AppState;
/// What the alerts route may reach of [`AppState`]: Grafana's alerts client.
///
/// Derived per request from [`AppState`] (`FromRef`), so the field is a clone
/// of the same `Arc` and nothing is held twice.
#[derive(Clone)]
pub(crate) struct AlertsState {
pub(crate) alerts: Option<Arc<alerts::Grafana>>,
}
impl FromRef<AppState> for AlertsState {
fn from_ref(state: &AppState) -> Self {
Self {
alerts: state.alerts.clone(),
}
}
}