: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(pgcollector): expose build_info metrics and update the deploy docs (#94660)
Nick Best74d977bd7457
diff --git a/rust/pgapi/README.md b/rust/pgapi/README.mdindex f2e44fb73132..9ff18897a14d 100644--- a/rust/pgapi/README.md+++ b/rust/pgapi/README.md@@ -56,14 +56,21 @@ authenticate headless clients.## Deploying-`values.example.yaml` is the golden-chart values file (ingress.internal +-tailscaleIngress + NetworkPolicy + read-only `psql`). Also needed:+The charts app is `apps/pgapi` in PostHog/charts, onboarded through platformctl+(`service.yaml` per app; platformctl generates the Argo CD Application and the+Kargo resources). [`values.example.yaml`](values.example.yaml) shows the values:+`tailscaleIngress` with `whois`, the NetworkPolicy that makes the identity header+trustworthy, and a read-only `psql` entry for the stats database.-* Tailscale ACL (`posthog-cloud-infra/tailnet-policy.hujson`): `tag:pgapi`- owned by `tag:k8s-operator`, `group:[email protected] → tag:pgapi:443`,- plus the positive/negative tests — copy the `tag:secrets-ui` block.-* Egress to the ALB public-key endpoint for token verification.-* A `users_readonly` user for the stats DB.+Outside the chart:++* `tag:pgapi` in `posthog-cloud-infra/tailnet-policy.hujson`, owned by+ `tag:k8s-operator`, with `group:[email protected] -> tag:pgapi:443`.+ That grant is the login for the tailnet host.+* The `pgapi` readonly user on the stats database, from+ `terraform/modules/pgcollector`.+* For the Cognito/ALB path, once enabled: egress to the ALB public-key endpoint+ for token verification.## Layoutdiff --git a/rust/pgapi/src/main.rs b/rust/pgapi/src/main.rsindex f9e0a81ce896..a40b3878795b 100644--- a/rust/pgapi/src/main.rs+++ b/rust/pgapi/src/main.rs@@ -158,8 +158,18 @@ async fn main() -> Result<()> {.layer(tower_http::trace::TraceLayer::new_for_http()).with_state(state);+ // Constant 1 with the crate version as a label, so dashboards can show which+ // build each pod runs without reading pod specs.+ prometheus::register_int_gauge_vec!("pgapi_build_info", "build metadata", &["version"])?+ .with_label_values(&[env!("CARGO_PKG_VERSION")])+ .set(1);+let listener = tokio::net::TcpListener::bind(&cli.listen).await?;- tracing::info!(listen = cli.listen, "pgapi listening");+ tracing::info!(+ listen = cli.listen,+ version = env!("CARGO_PKG_VERSION"),+ "pgapi listening"+ );axum::serve(listener, app).await?;Ok(())}diff --git a/rust/pgcollector/docs/deploy.md b/rust/pgcollector/docs/deploy.mdindex bdf16929d3b0..445583ff9ede 100644--- a/rust/pgcollector/docs/deploy.md+++ b/rust/pgcollector/docs/deploy.md@@ -2,55 +2,21 @@## 1. Database users (posthog-cloud-infra)-`aurora_user_management/v3.0.0` has four tiers, all built on-`pg_read_all_data` / `pg_write_all_data`. None fit a monitoring agent:-`readonly` grants SELECT on every table (too much) while still **not** letting-the role see other users' rows in `pg_stat_statements` / `pg_stat_activity`-(too little — that needs `pg_read_all_stats`, which `pg_monitor` includes).--Add a `monitor` tier to the module. It is the same shape as the others:--```hcl-# variables.tf-variable "users_monitor" {- description = "Users granted pg_monitor (pg_read_all_stats + pg_read_all_settings + pg_stat_scan_tables): full visibility into stats views and settings, NO data access. For telemetry agents such as pgcollector."- type = list(string)- default = []-}--# main.tf — locals-tier = merge(- ...,- { for u in var.users_monitor : u => "monitor" },-)-all_users = concat(..., var.users_monitor)--builtin_roles = {- ...- monitor = ["pg_monitor"]-}-database_privileges = {- ...- monitor = ["CONNECT"]-}-```--(`validate_tiers`' error message should mention the new list.)--Then, per monitored cluster, add `"pgcollector"` to `users_monitor` in that-cluster's users config — for the `cloud` cluster that's the `posthog_app_db_users`-module outputs (a new `cloud_users_monitor` output feeding the v3 lane), for-`persons` the `postgres-persons` configuration.--The **sink** database is a normal app database: pgcollector creates and alters-its own tables, so its user goes in `users_ddl` of whichever config manages-the stats cluster.--`pg_monitor` is enough for every collector shipped today, including-`pg_stat_statements` (the extension must be installed in the target database-— `CREATE EXTENSION pg_stat_statements` once, by a DDL user — and-`shared_preload_libraries` must include it, which is the RDS default parameter-group's setting on Aurora Postgres).+`aurora_user_management/v3.0.0` has a `monitor` tier for telemetry agents:+`pg_monitor` plus `CONNECT`, no table data. `readonly` is the wrong tier for+this job: it grants SELECT on every table and still hides other users' rows in+`pg_stat_statements` / `pg_stat_activity` (that needs `pg_read_all_stats`,+which `pg_monitor` includes).++Per monitored cluster, add `"pgcollector"` to `users_monitor` in that cluster's+own user config. The dev cloud cluster does this in+`terraform/environments/aws-accnt-dev/us-east-1/postgres/users.tf`; keep it out+of the shared `posthog_app_db_users` registry unless every cluster should get it.++The **sink** database, its `pgcollector` (ddl) and `pgapi` (readonly) users,+the `PostHogAppDatabaseId` tag the golden chart selects nodes by, and the+`k8s-pgcollector` IRSA role all come from `terraform/modules/pgcollector`. One+module call per environment; see its README for the inputs.### Extensions and Aurora functions@@ -106,7 +72,11 @@ database this is a non-issue.## 2. Helm (charts/posthog-app)-See [`deploy/values.example.yaml`](../deploy/values.example.yaml). Key points:+The charts app is `apps/pgcollector`, onboarded through platformctl: a+`service.yaml` per app declares the Stages, and platformctl generates the Argo CD+Application and the Kargo project, warehouse and stage. Do not hand-write an+ApplicationSet. See [`deploy/values.example.yaml`](../deploy/values.example.yaml)+for the values. Key points:* **`pgbouncer: false` on every `psql:` entry.** pgcollector sets session GUCsand needs stable backends; it refuses to start if it detects PgBouncer.diff --git a/rust/pgcollector/src/http.rs b/rust/pgcollector/src/http.rsindex 4f61d604f855..c33ef7c6477d 100644--- a/rust/pgcollector/src/http.rs+++ b/rust/pgcollector/src/http.rs@@ -46,10 +46,22 @@ impl Metrics {&["server"],).unwrap();+ // Constant 1 with the crate version as a label, so dashboards can show which+ // build each pod runs without reading pod specs.+ let build_info = IntGaugeVec::new(+ prometheus::opts!("pgcollector_build_info", "build metadata"),+ &["version"],+ )+ .unwrap();+ build_info+ .with_label_values(&[env!("CARGO_PKG_VERSION")])+ .set(1);registry.register(Box::new(tick_seconds.clone())).unwrap();registry.register(Box::new(rows.clone())).unwrap();registry.register(Box::new(errors.clone())).unwrap();registry.register(Box::new(targets.clone())).unwrap();+ // The registry owns the gauge; nothing updates it after this point.+ registry.register(Box::new(build_info)).unwrap();Self {registry,tick_seconds,diff --git a/rust/pgcollector/src/main.rs b/rust/pgcollector/src/main.rsindex d069a559458c..d164d1691a11 100644--- a/rust/pgcollector/src/main.rs+++ b/rust/pgcollector/src/main.rs@@ -55,6 +55,7 @@ async fn main() -> Result<()> {let cfg = config::Config::load(&cli.config)?;let registry = collectors::Registry::load(cli.collectors_dir.as_deref())?;tracing::info!(+ version = env!("CARGO_PKG_VERSION"),servers = cfg.servers.len(),collectors = registry.len(),"loaded config"