swarm-controller: move the observability concern into its own module
Refs #6897
This commit is contained in:
parent
9b2ba275d8
commit
cd8feedf73
7 changed files with 32 additions and 27 deletions
|
|
@ -56,7 +56,7 @@ hive-meta-flake.workspace = true
|
|||
# (e.g. hive-c0re, for its own per-hive job graph) doesn't have to depend on
|
||||
# this whole binary to reuse it.
|
||||
hive-jobq-metrics.workspace = true
|
||||
# Direct OTEL SDK use in `vcs_metrics.rs` — sync counters recorded off
|
||||
# Direct OTEL SDK use in `observability/vcs_metrics.rs` — sync counters recorded off
|
||||
# webhook deliveries, a different shape from `hive-jobq-metrics`'s
|
||||
# observable-gauge rollup, so it isn't a fit for that crate's API and lives
|
||||
# here instead. Same three crates that pairing already pulls in transitively,
|
||||
|
|
@ -135,7 +135,7 @@ swarm-wire = { workspace = true, features = ["schema"] }
|
|||
# The appservice calls `matrix_account::agent_token` mints agents' accounts
|
||||
# with — shared with `swarm-matrix-ctl`, which pins the same device id.
|
||||
swarm-matrix-client.workspace = true
|
||||
# `otel_http_client.rs`'s `AuthenticatedHttpClient` — an
|
||||
# `observability/otel_http_client.rs`'s `AuthenticatedHttpClient` — an
|
||||
# `opentelemetry_http::HttpClient` impl authenticated with this crate's own
|
||||
# `swarm-queue-client` identity. Lives in this crate rather than
|
||||
# `swarm-queue-client` (mara's own call during review) since this daemon is
|
||||
|
|
|
|||
|
|
@ -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::{
|
||||
|
|
|
|||
7
swarm-controller/src/observability/mod.rs
Normal file
7
swarm-controller/src/observability/mod.rs
Normal 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;
|
||||
|
|
@ -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>>,
|
||||
) {
|
||||
Loading…
Reference in a new issue