swarm-controller: emit vcs commit/push otel counters from an instance-wide forge webhook

This commit is contained in:
damocles 2026-08-24 19:59:41 +02:00 committed by mara
commit 6bb64d8bc2
6 changed files with 290 additions and 3 deletions

View file

@ -173,6 +173,13 @@ pub(super) enum DeliveryKind {
Knowledge,
/// `pull_request` events on the agent-config repos.
ConfigPr,
/// `push` events on every repo in the instance — see
/// `crate::vcs_metrics`'s doc comment for why this exists as its own
/// kind rather than folding into [`Self::Knowledge`]'s already-`push`
/// hook: that one is repo-scoped to the knowledge repo alone, and this
/// one is instance-wide (registered via `admin_create_hook`, not
/// `repo_create_hook`) — different scope, same event name.
VcsActivity,
}
/// The route prefix a registered `target_url` must point at.
@ -192,7 +199,7 @@ impl DeliveryKind {
/// Every kind, for the registration sweep. An array rather than a
/// hand-written list at the call site, so adding a kind cannot leave one
/// hook unregistered.
pub(super) const ALL: [Self; 2] = [Self::Knowledge, Self::ConfigPr];
pub(super) const ALL: [Self; 3] = [Self::Knowledge, Self::ConfigPr, Self::VcsActivity];
/// The `target_url` to register with Forgejo for this kind, given the
/// swarm's public base URL.
@ -217,6 +224,7 @@ impl DeliveryKind {
match segment {
"knowledge" => Some(Self::Knowledge),
"config-pr" => Some(Self::ConfigPr),
"vcs-activity" => Some(Self::VcsActivity),
_ => None,
}
}
@ -233,6 +241,7 @@ impl DeliveryKind {
match self {
Self::Knowledge => "knowledge",
Self::ConfigPr => "config-pr",
Self::VcsActivity => "vcs-activity",
}
}
}
@ -383,6 +392,13 @@ pub(super) async fn post_webhook_forge(
cache.apply_webhook_delivery(&body);
}
}
DeliveryKind::VcsActivity => {
if let Some(activity) = crate::vcs_metrics::parse_push(&body) {
crate::vcs_metrics::record_push(&activity);
} else {
tracing::warn!("webhook: vcs-activity delivery did not parse as a push payload");
}
}
}
(StatusCode::OK, "ok").into_response()