Skip to content

Latest commit

 

History

History
343 lines (281 loc) · 20.2 KB

observability.md

File metadata and controls

343 lines (281 loc) · 20.2 KB

Observability

The platform's observability layer is a full distributed LGTM stack (Loki + Grafana + Tempo + Mimir) plus the Prometheus operator's ServiceMonitor/PodMonitor reconciler and a HA Alertmanager. The authoritative design rationale is ADR 0010; this page is the operator's tour.

Topology

                                                                              external pushers (Jenkins masters,
                                                                              Hetzner cloud plugin, future agents)
                                                                                            │
                                                                                            ▼
                                                                                     ALB (jenkins-cd)
                                                                              ┌─── mimir-push.cd.percona.com
                                                                              │      loki-push.cd.percona.com
                                                                              │      tempo-push.cd.percona.com
                                                                              ▼
                                          ┌───────────────────────────  alloy-gateway (Deployment x2)  ──┐
                                          │   nginx bearer sidecar :9009/:3100/:4318 (strips auth header)│
                                          │   alloy receivers loopback :19009/:13100/:14318              │
                                          │     /api/v1/metrics/write   /loki/api/v1/push   /v1/traces   │
                                          │                                                              │
                                          ▼                          ▼                                   ▼
                                         Mimir (distributed)         Loki (distributed)                Tempo (distributed)
                                         ────────────────────        ────────────────────              ────────────────────
                                         distributor x3              distributor x3                   distributor x3
                                         ingester x3 ─► S3           ingester x3 ─► S3                ingester x3 ─► S3
                                         query-frontend x2           query-frontend x2                query-frontend x2
                                         querier x2                  querier x2                       querier x2
                                         store-gateway x2            index-gateway x2                 compactor x1
                                         compactor x1                compactor x1
                                         ruler x1                    ruler x1
                                         alertmanager x3
                                          ▲
                                          │  in-cluster distributor URLs
                                          │
   alloy (DaemonSet)   -- LGTM-only since ADR 0016 (no Prom agent, no kps Alertmanager)
   ────────────────────
   ServiceMonitor / PodMonitor scrape (incl. kube-state-metrics, prometheus-node-exporter,
                  cloudwatch-exporter = YACE polling AWS LB CloudWatch metrics, ADR 0034) ─► Mimir
   pod logs    ─► Loki distributor (loki.source.kubernetes via the API, labels namespace/pod/container/instance)
   k8s events  ─► Loki distributor (loki.source.kubernetes_events, namespace-sharded)
   OTLP traces ─► Tempo distributor


   ┌───────────────────────────────────  Grafana (standalone, HA x2)  ──┐
   │                                                                    │
   │   datasources: Mimir (default), Loki, Tempo, Prometheus (in-cluster)
   │   auth: OIDC via Authentik (SAML SP to JumpCloud, docs/authentication.md)
   │   ALB Ingress: grafana.cd.percona.com (sticky session for the OIDC round-trip)
   │
   └────────────────────────────────────────────────────────────────────┘

Sync waves

Wave Component ArgoCD path
0 StorageClass gp3 + AZ-pinned variants resources/addons/storageclass-gp3/
1 aws-load-balancer-controller, external-dns resources/addons/aws-load-balancer-controller/, external-dns/
2 external-secrets (with ClusterSecretStore) resources/addons/external-secrets/
3 karpenter resources/addons/karpenter/
4 mimir, loki, tempo resources/addons/{mimir,loki,tempo}/
5 alloy DaemonSet (scrape + logs + events + traces), kube-state-metrics, prometheus-node-exporter, prometheus-operator-crds, cloudwatch-exporter (YACE, AWS LB metrics), jenkins-uptime (blackbox-exporter + Probes) resources/addons/alloy/, kube-state-metrics/, prometheus-node-exporter/, prometheus-operator-crds/, cloudwatch-exporter/, jenkins-uptime/
6 grafana, alloy-gateway resources/addons/grafana/, alloy-gateway/

Order matters: Mimir/Loki/Tempo must be running before Alloy can ship anything. Grafana ships last so all datasources are up at first reconcile.

Pod logs

loki.source.kubernetes "pods" tails every container through the API server (kubelet log stream), not from the node's filesystem, and runs clustered: one DS pod owns each target (Alloy shards by namespace, pod, container and pod UID). Without clustering every DS pod tailed every container, and each new DS pod replayed the full current log of every target, so Loki held 2 to 3 copies of some lines (the jenkins-mcp audit stream was 8.5% duplicates). A reshard still replays the whole kubelet-retained log of a reassigned target (the source has no start position), so dashboards that count calls count distinct request_ids, never lines.

Object storage

Three S3 buckets, shared CMK (alias/percona-ci-platform-lgtm):

Bucket Component Retention Lifecycle notes
${cluster_name}-mimir-blocks Mimir TSDB blocks 395 d (~13 mo) Hard-delete; SSE-KMS with bucket_key_enabled
${cluster_name}-loki-chunks Loki chunks 30 d Logs decay fast; longer retention belongs in IA tier
${cluster_name}-tempo-traces Tempo trace blocks 14 d Sampling-heavy; 14 d covers incident response

All three: BucketOwnerEnforced, public-access blocked, versioning on (for forensics, not retention; noncurrent versions expire 7 d), abort incomplete multipart 7 d.

IAM: each component gets s3:Get/Put/Delete/Abort/ListMultipart on its own bucket plus kms:Decrypt/Encrypt/GenerateDataKey on the LGTM CMK only — no cross-component access.

Datasource URLs (in-cluster)

Mimir  → http://mimir-query-frontend.mimir.svc.cluster.local:8080/prometheus
Loki   → http://loki-query-frontend.loki.svc.cluster.local:3100
Tempo  → http://tempo-query-frontend.tempo.svc.cluster.local:3100
Prom   → http://prometheus-operated.monitoring.svc.cluster.local:9090   (transitional)

X-Scope-OrgID for Mimir is hardcoded to percona-ci (single-tenant); set by Grafana datasource secureJsonData and by Prometheus remoteWrite headers.

External push endpoints

mimir-push.cd.percona.com  → /api/v1/metrics/write (Prometheus remote_write
                              into Alloy's prometheus.receive_http; NOT
                              /api/v1/push, which Mimir's distributor takes
                              but Alloy's receiver does not)
loki-push.cd.percona.com   → /loki/api/v1/push
tempo-push.cd.percona.com  → /v1/traces (OTLP HTTP :4318); OTLP gRPC :4317
                              stays cluster-internal (ALB doesn't yet support
                              gRPC backend health)

The Alloy gateway translates these to in-cluster Service DNS calls against Mimir/Loki/Tempo distributors.

Auth at the gateway is two intentional layers, both wired up. The active gate is the NGINX bearer-token sidecar in the alloy-gateway Pod; it validates Authorization: Bearer <token>, strips the header, and proxies to Alloy's loopback receivers. The token is a single shared value at AWS Secrets Manager percona-ci-platform/alloy-gateway/bearer, synced into the cluster by External Secrets Operator. The SecretString value is JSON {"bearer_token":"..."} (not a plain string) — every consumer (master-side /usr/local/bin/alloy-fetch-token, ESO dataFrom: extract, scripts/verify-observability.sh) JSON-parses .bearer_token before use. The second layer, the ALB CIDR allowlist (alb.ingress.kubernetes.io/inbound-cidrs), is also valued: it is empty by default in resources/addons/alloy-gateway/values.yaml. The original populate-from-master-EIPs plan died with the EIP removal (masters egress from dynamic public IPv4s); an allowlist needs a stable-egress design first. See ADR 0013 and jenkins-fleet-scrape.md for the master-side push config.

Memberlist isolation

Mimir, Loki, and Tempo all use Hashicorp memberlist for ring gossip and all default to cluster_label = "". Without explicit labels, three co-tenant LGTM stacks in the same cluster (or in the same VPC) would gossip into each other's rings on handshake, log noise at best and cross-stack ring pollution at worst. Each stack now carries a unique cluster_label (added 2026-05-08, follow-up ADR forthcoming):

mimir   memberlist.cluster_label = "mimir-percona-ci"
loki    memberlist.cluster_label = "loki-percona-ci"
tempo   memberlist.cluster_label = "tempo-percona-ci"

cluster_label_verification_disabled: false on all three so unlabelled gossip from a future neighbour stack is rejected at handshake time.

Grafana auth

Browser sign-in is OIDC against Authentik, which is the SAML SP to JumpCloud (see authentication.md). The local login form is disabled. Role mapping via the groups claim: grafana_cd_admins → GrafanaAdmin, percona → Viewer (the planned grafana_cd_users group was never provisioned). The local admin password is ESO-pinned and serves API and break-glass use only, see the auth comments in resources/addons/grafana/values.yaml.

The direct Grafana SAML path (var.grafana_saml_enabled) is retired, its runbook runbooks/grafana-saml-cutover.md is kept for history only.

Capacity sizing (initial)

The replicas above are start-points sized for ten Jenkins masters' typical metric/log/trace volume. Scale knobs (per-component HPA) are deferred until usage signal arrives. Right-sizing checkpoints:

  • Mimir ingester memory: bump if cortex_ingester_memory_series exceeds 2 M / replica
  • Loki ingester memory: bump if loki_ingester_memory_streams exceeds 200k / replica
  • Tempo ingester memory: bump if tempo_ingester_blocks_flushed_total rate spikes
  • Prometheus WAL: bump PVC if prometheus_remote_storage_samples_pending accumulates

Restore + cutover runbooks

Verifying ingest

  • just check-master-alloy — every-active-master Mimir-via-Alloy freshness gate; enumerates the master set dynamically from repo source-of-truth.
  • scripts/check-master-ingest.sh — per-master Mimir + Loki detail (series, freshness, cardinality, log lines); hardcoded master list.
  • scripts/verify-observability.sh [<inst>] — full push-pipeline walk for one master (Alloy systemd, ALB + bearer, gateway, Mimir/Loki, Grafana).

Log liveness

Every master writes one INFO heartbeat line per minute to jenkins.log (logHeartbeat.groovy in init.groovy.d, delivered through the S3 init buckets for the EC2 masters and the boot-time init ConfigMap for ps3-k8s). The Loki ruler counts the lines that reach Loki per master (jenkins:master_log_lines:count15m, from the PrometheusRule labelled percona.com/ruler: loki in the jenkins-uptime addon) and remote-writes the samples to Mimir. There jenkins:master_logs_fresh turns a missing sample into 0, the Jenkins / Uptime dashboard shows it per master, and JenkinsMasterLogsSilent fires after five more minutes when a master still pushes metrics but no line landed for 15 minutes. Reasoning in ADR 0045.

When it fires for <inst>.cd:

  1. Confirm the file still grows. A stale mtime means the JVM stopped writing (step 2). A fresh mtime means the tail or the push died (step 3).

    just ssm-run <inst> 'stat -c %y /var/log/jenkins/jenkins.log; tail -n 2 /var/log/jenkins/jenkins.log'
  2. Read the JUL state before touching anything. Expect INFO with the winstone, hudson.WebAppMain and WeakLogHandler handlers present. Manage Jenkins > System Log > Log Levels resets a lowered level without a restart. Record level, handlers and the last log line first: the 2026-05-14 restart on ps80 cured the symptom and destroyed the evidence.

    jenkins -i <inst> admin groovy -e 'def root = java.util.logging.Logger.getLogger(""); println root.level; root.handlers.each { println it }'
  3. Check the master-side tail and push. The position must track the file size, and the journal must be free of 4xx from loki-push.

    just ssm-run <inst> 'journalctl -u alloy --since -30m --no-pager | tail -n 20; cat /var/lib/alloy/data/loki.source.file.jenkins/positions.yml'
    scripts/verify-observability.sh <inst>
  4. For ps3-k8s the stream is the controller's stdout, tailed through the Kubernetes API by the Alloy DaemonSet pod that owns the target (clustered, not node-bound). Only the jenkins container counts, the sidecars in the namespace are excluded. Check that the stream carries master="ps3-k8s" and that exactly one Alloy pod has the tailer open.

    kubectl -n loki port-forward svc/loki-query-frontend 3100 &
    curl -sG localhost:3100/loki/api/v1/query \
      --data-urlencode 'query=sum(count_over_time({master="ps3-k8s", container="jenkins"} |= "heartbeat" [15m]))'
    for p in $(kubectl -n alloy get pods -o name); do kubectl -n alloy logs "$p" -c alloy --since=1h | grep -c 'opened log stream.*jenkins-ps3-k8s-0' | sed "s|^|$p |"; done

Rule-path checks: the Loki ruler lists jenkins-logs.rules, and Mimir holds jenkins:master_logs_fresh with one series per master.

kubectl -n loki port-forward svc/loki-ruler 3100 &
curl -s localhost:3100/loki/api/v1/rules
scripts/check-uptime-queries.py

Engineer keys sync

Every EC2 master runs engineer-keys-sync.sh through a per-master SSM association every 30 minutes (ADR 0046). Each run writes /var/lib/alloy/textfile/engineer_keys_sync.prom, which the master-side Alloy unix exporter scrapes through its textfile collector, so the metrics carry the usual master label:

Metric Meaning
engineer_keys_sync_last_run_timestamp_seconds When the reconciler last ran, whatever the outcome
engineer_keys_sync_last_run_success 1 when the run applied the roster in full, 0 when it failed before publishing (nothing changed), ran degraded, or failed after publishing (sshd drop-in, prune)
engineer_keys_sync_last_success_timestamp_seconds When the roster was last applied in full, survives failed runs
engineer_keys_sync_roster_version SSM parameter version last applied in full, never the version last read
engineer_keys_sync_keys Public keys in the managed roster file
engineer_keys_sync_degraded_slugs Slugs whose feed failed transiently on the last run and kept their previous keys
engineer_keys_sync_slugs_missing Slugs the feed answers 404 for (IT no longer publishes them), installed with no key
engineer_keys_sync_legacy_pruned 1 once the one-time prune of ~ec2-user/.ssh/authorized_keys is done on this master
engineer_keys_sync_keyset_info{keyset_sha256} Digest of the installed key file, one series per key set

Alerts in the jenkins-uptime addon, all warning unless noted:

Alert Fires when Means
EngineerKeysSyncFailing last_run_success == 0 for 1h The run did not apply the roster in full, read the association output for the stage word (result=, sshd=, prune=)
EngineerKeysSyncStale no full success for 2h Four scheduled runs failed, the association stopped, or SSM and percona.com are unreachable
EngineerKeysSyncMissing host metrics arrive, sync metric never did, 2h Association missing for this master, or Alloy has no textfile collector (a master rebuilt before the user-data pin of the observability script moved past the collector)
EngineerKeysSyncDegraded degraded_slugs > 0 for 1h A slug's feed keeps failing, that slug runs on its previous keys, everybody else converged
EngineerKeysSlugMissing slugs_missing > 0 for 24h The roster names a slug percona.com no longer publishes, remove it with just engineers-set
EngineerKeysVersionSkew a master lags the fleet's applied version for 1h A revocation may not have landed on that master, trigger the association
EngineerKeysLegacyPrunePending legacy_pruned == 0 for 2h Legacy keys may still grant access, see the prune notes below
EngineerKeysRosterChanged (info) roster version changed in the last hour Expect a matching PutParameter in CloudTrail
EngineerKeysFeedChanged (info) the key set changed with no roster change in 6h IT rotated or removed a key upstream, confirm it is expected

A failing sync never removes access, so the pressure is a possibly pending revocation, not an outage. The Alertmanager has no receiver yet (ADR 0031), so these show on the dashboards and in Alertmanager and page nobody.

To act on one:

just engineers-status                                  # roster version, per-master status and applied version
just ssm-run <inst> 'journalctl -t engineer-keys-sync --no-pager -o cat | tail -5'

The association output holds the same lines. Each run ends with one summary line, result=ok or result=degraded, followed by parameter_version, applied_version, degraded_slugs, missing_slugs, file=, sshd= and prune=.

Fixes are roster edits through just engineers-set, never host edits: the roster file is rewritten from the parameter every run, so a key removed from it by hand is back within 30 minutes. Two cases need a decision on the host:

  • prune blocked, ... holds a key the roster does not serve names a key in ~ec2-user/.ssh/authorized_keys that is neither the EC2 key pair nor served by the roster. The roster file is live regardless. Either add its owner to the roster, or remove that line by hand, and the next run prunes.
  • prune=deferred on a degraded run is normal: the prune waits for a run that applied every slug, so the degraded engineer does not lose the legacy key before the roster key arrived. It resolves itself when the feed recovers.

Related decisions