An open-source, faster Devin alternative
TypeScript
metrics: stamp correct cell_id via shared-cell-id KV secret (#248)
Mohamed Habibf01e301acd21
diff --git a/deploy/vector/populate-vector-env.sh b/deploy/vector/populate-vector-env.shindex 577d5010..89b2b4a2 100755--- a/deploy/vector/populate-vector-env.sh+++ b/deploy/vector/populate-vector-env.sh@@ -21,6 +21,7 @@# shared-axiom-platform-dataset → AXIOM_PLATFORM_DATASET (required — logs)# shared-axiom-platform-metrics-ingest-token → AXIOM_PLATFORM_METRICS_TOKEN (optional — metrics)# shared-axiom-platform-metrics-dataset → AXIOM_PLATFORM_METRICS_DATASET (optional — metrics)+# shared-cell-id → OPENCOMPUTER_CELL_ID (optional — cell tag)## Logs secrets are hard-required: missing → exit 0 without writing env file,# Vector fails healthcheck and buffers to disk until the secret appears@@ -30,6 +31,11 @@# with logs creds set, metrics ones empty. The metrics sink fails healthcheck# and buffers to disk independently. Lets operators roll out the metrics# dataset asynchronously without coordinating with the worker fleet.+#+# shared-cell-id is soft-optional too: missing → fall back to whatever+# OPENCOMPUTER_CELL_ID was already in the populator's shell env (typically+# unset on prod), then to literal "unknown". Vector keeps shipping; events+# just won't be tagged with the right cell until KV gets the secret.set -euo pipefailVAULT_NAME="${OPENSANDBOX_AZURE_KEY_VAULT_NAME:-}"@@ -38,6 +44,7 @@ TOKEN_SECRET=shared-axiom-platform-ingest-tokenDATASET_SECRET=shared-axiom-platform-datasetMETRICS_TOKEN_SECRET=shared-axiom-platform-metrics-ingest-tokenMETRICS_DATASET_SECRET=shared-axiom-platform-metrics-dataset+CELL_ID_SECRET=shared-cell-idlog() { logger -t populate-vector-env "$*"; echo "$*"; }@@ -88,6 +95,15 @@ if [ -z "$METRICS_TOKEN_VALUE" ] || [ -z "$METRICS_DATASET_VALUE" ]; thenlog "metrics secrets ($METRICS_TOKEN_SECRET / $METRICS_DATASET_SECRET) missing — metrics sink will buffer to disk until configured"fi+# Cell tag — fall through KV → inherited env → "unknown". KV wins so the+# value matches what the Go binary will load via secretMapping in+# internal/config/keyvault.go; events from both pipelines stay coherent.+CELL_ID_VALUE=$(kv_get "$CELL_ID_SECRET")+if [ -z "$CELL_ID_VALUE" ]; then+ CELL_ID_VALUE="${OPENCOMPUTER_CELL_ID:-unknown}"+ log "secret $CELL_ID_SECRET not found in $VAULT_NAME — falling back to OPENCOMPUTER_CELL_ID=$CELL_ID_VALUE"+fi+# Auto-detect HOST_IP via the kernel's source-address selection (skips link-local).HOST_IP=$(ip route get 8.8.8.8 2>/dev/null | awk '/src/ {for(i=1;i<NF;i++) if($i=="src") print $(i+1); exit}' || true)@@ -98,7 +114,7 @@ AXIOM_PLATFORM_TOKEN=${TOKEN_VALUE}AXIOM_PLATFORM_DATASET=${DATASET_VALUE}AXIOM_PLATFORM_METRICS_TOKEN=${METRICS_TOKEN_VALUE}AXIOM_PLATFORM_METRICS_DATASET=${METRICS_DATASET_VALUE}-OPENCOMPUTER_CELL_ID=${OPENCOMPUTER_CELL_ID:-unknown}+OPENCOMPUTER_CELL_ID=${CELL_ID_VALUE}OPENSANDBOX_REGION=${OPENSANDBOX_REGION:-unknown}OPENCOMPUTER_HOST_IP=${HOST_IP:-unknown}EOF@@ -110,4 +126,4 @@ metrics_status="absent"if [ -n "$METRICS_TOKEN_VALUE" ] && [ -n "$METRICS_DATASET_VALUE" ]; thenmetrics_status="present"fi-log "populated $ENV_FILE (logs token+dataset from $VAULT_NAME, metrics=$metrics_status, host_ip=${HOST_IP:-unknown})"+log "populated $ENV_FILE (logs token+dataset from $VAULT_NAME, metrics=$metrics_status, cell_id=$CELL_ID_VALUE, host_ip=${HOST_IP:-unknown})"diff --git a/internal/config/keyvault.go b/internal/config/keyvault.goindex b0ede32b..4b7c3709 100644--- a/internal/config/keyvault.go+++ b/internal/config/keyvault.go@@ -85,6 +85,14 @@ var secretMapping = map[string]string{// config (e.g. an admin endpoint) gets them for free."shared-axiom-platform-ingest-token": "AXIOM_PLATFORM_TOKEN","shared-axiom-platform-dataset": "AXIOM_PLATFORM_DATASET",+ // Cell identifier — stamped on every log + metric event so platform+ // dashboards can filter per cell. Same dual-consumer pattern as the+ // platform-* secrets above: Vector reads it from /etc/opensandbox/vector.env+ // (written by populate-vector-env.sh) for its remap substitutions, and the+ // Go binary reads it from os.Getenv("OPENCOMPUTER_CELL_ID") (config.go) so+ // app-side logging and metrics get the same value. Per-cell KV stores a+ // different literal here (e.g. eastus2-default, westeurope-dev).+ "shared-cell-id": "OPENCOMPUTER_CELL_ID",}// LoadSecretsFromKeyVault fetches secrets from Azure Key Vault and sets them