Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: move the observability concern into its own module

Refs #6897
This commit is contained in:
atlas 2026-11-27 14:21:35 +01:00
commit cd8feedf73
6 changed files with 32 additions and 27 deletions

View file

@ -45,7 +45,6 @@ mod agent_status;
mod agent_todos;
mod agents_md;
mod agents_md_initial;
mod alerts;
mod archetypes;
mod archive_access;
mod attic_copy;
@ -63,7 +62,6 @@ mod egress_allow;
mod egress_deny;
mod forge;
mod forge_events;
mod held_deploys;
mod inference;
mod issue_report;
mod jobq;
@ -71,8 +69,8 @@ mod message_stream;
mod meta_build;
mod meta_fanout;
mod meta_flake;
mod observability;
mod observability_grant;
mod otel_http_client;
mod pause_hold;
mod pr_conflicts;
mod pr_report;
@ -92,15 +90,15 @@ mod tcp_tls;
mod term_stream;
#[cfg(test)]
mod test_nats;
mod vcs_metrics;
mod wanted;
mod webhook;
// The accounts and review modules keep their crate-root paths (`crate::matrix_account::…`).
// The accounts, observability and review modules keep their crate-root paths (`crate::matrix_account::…`).
use accounts::{
forge_account, github_account, gitlab_account, link_egress, linked_accounts, matrix_account,
};
use jobq::{Late, WorkerDeps, spawn_jobq_worker};
use observability::{alerts, held_deploys, otel_http_client, vcs_metrics};
use review::{notify_flows, notify_router_api, request_reviewer, review_classifier};
use routes::AppState;
use startup::{

View file

@ -0,0 +1,7 @@
//! The observability concern: the Grafana alerts route, the held-deploy
//! gauge, the OTLP HTTP client and the forge metrics helpers.
pub(crate) mod alerts;
pub(crate) mod held_deploys;
pub(crate) mod otel_http_client;
pub(crate) mod vcs_metrics;

View file

@ -42,30 +42,30 @@ pub(crate) const EXPORT_INTERVAL: Duration = Duration::from_mins(1);
/// this module needs, not a full mirror of Forgejo's push-event schema.
/// Kept separate from the wire parsing so a test can construct one without
/// a JSON literal.
pub(super) struct PushActivity {
pub(crate) struct PushActivity {
/// The pushed ref, e.g. `refs/heads/main`.
pub(super) git_ref: String,
pub(crate) git_ref: String,
/// `repository.default_branch`; empty when the payload names none, in
/// which case no push counts as a default-branch push.
pub(super) default_branch: String,
pub(crate) default_branch: String,
/// The ref's tip before and after the push. All zeros means the ref did
/// not exist before (`before`) or no longer exists (`after`).
pub(super) before: String,
pub(super) after: String,
pub(crate) before: String,
pub(crate) after: String,
/// `repository.full_name` (`org/repo`) — the attribute every series
/// this module emits carries, so a dashboard can break activity down
/// per repo without a second join.
pub(super) repo: String,
pub(crate) repo: String,
/// `commits.len()` from the payload. A push with zero commits is real
/// (a branch delete, a force-push moving the ref backward) and still
/// counted as a push — just with a commit delta of zero, not skipped.
pub(super) commit_count: u64,
pub(crate) commit_count: u64,
}
/// Parse a Forgejo `push` webhook body into a [`PushActivity`]. `None` on
/// anything unparseable — a malformed body is logged and dropped by the
/// caller, not a reason to fail the delivery Forgejo already got a 200 for.
pub(super) fn parse_push(body: &[u8]) -> Option<PushActivity> {
pub(crate) fn parse_push(body: &[u8]) -> Option<PushActivity> {
let v: serde_json::Value = serde_json::from_slice(body).ok()?;
let repo = v.get("repository")?.get("full_name")?.as_str()?.to_owned();
let commit_count = v.get("commits")?.as_array()?.len();
@ -99,7 +99,7 @@ static INSTRUMENTS: OnceLock<Option<Instruments>> = OnceLock::new();
/// (`OTEL_EXPORTER_OTLP_ENDPOINT` unset) — the same graceful-absence shape
/// every other exporter in this tree uses, so a deployment with no
/// collector pays nothing beyond the one-time `OnceLock` check.
pub(super) fn record_push(activity: &PushActivity) {
pub(crate) fn record_push(activity: &PushActivity) {
let Some(inst) = INSTRUMENTS.get_or_init(build).as_ref() else {
return;
};
@ -112,10 +112,10 @@ pub(super) fn record_push(activity: &PushActivity) {
/// What one default-branch push adds to the counters.
#[derive(Debug, PartialEq, Eq)]
pub(super) struct DefaultBranchTally {
pub(crate) struct DefaultBranchTally {
/// `None` when the lines are unknown: the push created the branch, or
/// the compare failed. Nothing is added to the line counters then.
pub(super) lines: Option<LineStats>,
pub(crate) lines: Option<LineStats>,
}
fn is_null_sha(sha: &str) -> bool {
@ -134,7 +134,7 @@ fn is_null_sha(sha: &str) -> bool {
/// `after` and not from `before`, with their stats. The commits the push
/// discarded are not subtracted, so a rewrite of already-counted history
/// counts those lines a second time.
pub(super) async fn default_branch_tally<F, Fut>(
pub(crate) async fn default_branch_tally<F, Fut>(
activity: &PushActivity,
compare: F,
) -> Option<DefaultBranchTally>
@ -164,7 +164,7 @@ where
/// Count `activity` on the default-branch counters, comparing through
/// `forge`. Runs after the webhook has answered; nothing here can fail it.
pub(super) async fn count_default_branch_push(
pub(crate) async fn count_default_branch_push(
activity: PushActivity,
forge: Option<Arc<crate::forge::Client>>,
) {