Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ingestion-control-plane): start changelog backups after the metrics recorder (#130431)

Zach Brown5bafe5e24dd1
diff --git a/rust/ingestion-control-plane/src/main.rs b/rust/ingestion-control-plane/src/main.rs
index 845ffefb880c..6d07316a71dd 100644
--- a/rust/ingestion-control-plane/src/main.rs
+++ b/rust/ingestion-control-plane/src/main.rs
@@ -1,4 +1,4 @@
-use std::future::ready;
+use std::future::{ready, Future};
use std::sync::Arc;
use std::time::Duration;
@@ -67,7 +67,7 @@ async fn main() {
});
let mut state = AppState::new(config).expect("failed to initialize app state");
- start_changelog_backups(&mut state).await;
+ let backups = changelog_backups(&mut state).await;
record_changelog_cluster(&state);
let router = api::router(state)
@@ -77,6 +77,11 @@ async fn main() {
get(move || ready(health_registry.get_status())),
);
let router = setup_metrics_routes(router);
+ // The recorder exists only once setup_metrics_routes returns, and the first sync
+ // sets the in-sync gauge, so the loop starts after it or the gauge is lost.
+ if let Some(backups) = backups {
+ tokio::spawn(backups);
+ }
info!("Listening on {}", bind);
let listener = tokio::net::TcpListener::bind(bind)
@@ -120,21 +125,21 @@ fn record_changelog_cluster(state: &AppState) {
});
}
-async fn start_changelog_backups(state: &mut AppState) {
+async fn changelog_backups(state: &mut AppState) -> Option<impl Future<Output = ()>> {
let bucket = state.config.changelog_backup_bucket.clone();
if bucket.is_empty() {
info!("CHANGELOG_BACKUP_BUCKET not set; changelog backups disabled");
- return;
+ return None;
}
let Some(etcd) = state.etcd.clone() else {
warn!("CHANGELOG_BACKUP_BUCKET is set without ETCD_ENDPOINTS; changelog backups disabled");
- return;
+ return None;
};
let backups: Arc<dyn BackupStore> = Arc::new(S3BackupStore::from_env(bucket).await);
state.backups = Some(backups.clone());
- tokio::spawn(backup::run(
+ Some(backup::run(
etcd,
state.config.personhog_etcd_prefix.clone(),
backups,
- ));
+ ))
}