Skip to content

Scrape the CMS slots by container name, not through the host gateway - #179

Merged
ssavutu merged 1 commit into
mainfrom
fix/prometheus-cms-network
Aug 4, 2026
Merged

Scrape the CMS slots by container name, not through the host gateway#179
ssavutu merged 1 commit into
mainfrom
fix/prometheus-cms-network

Conversation

@ssavutu

@ssavutu ssavutu commented Aug 4, 2026

Copy link
Copy Markdown
Member

Follow-up to #178, found while rolling it out to Delta.

The bug

prometheus.delta.yml targeted host.docker.internal:8081/8082. That cannot work: the CMS slots publish to 127.0.0.1 only, so Prometheus dialling the gateway got:

dial tcp 172.17.0.1:8081: connect: connection refused

Both targets down. My assumption in #178 that the gateway could reach a loopback-published port was simply wrong.

The fix

Attach Prometheus to the CMS project's network and scrape the containers on their internal port 8080. No change to compose.cms.yml, no new host exposure, and both slots stay individually visible.

The network is declared external, so this stack attaches to it and can never create, modify, or remove it — the CMS side stays untouchable from here. The real cost, stated in the compose file and README: an ordering dependency. The CMS stack must be up before this one, or Compose fails with a missing-network error rather than silently scraping nothing. I'd take a loud failure over a quiet one here.

Verified on Delta

slot=blue   triangle-cms-backend-blue-1:8080    health=up
slot=green  triangle-cms-backend-green-1:8080   health=down  404

sum(http_requests_total) returns 126 — real traffic recorded.

Green 404s because it still runs the pre-merge image without /metrics. It resolves the next time a deploy rotates that slot; no action needed.

Also rolled out

The full stack is now live on Delta: Prometheus running, both datasources provisioned with correct UIDs, "CMS Dashboard" loaded.

One snag worth recording: Grafana crash-looped on Datasource provisioning error: data source not found, because its existing volume held a Loki datasource with an auto-generated UID and #178 pins uid: loki. Provisioning cannot reconcile that. Fixed by recreating the volume, which was safe here since that Grafana had no user-created content. Anyone pinning a UID on an established Grafana will hit the same and should expect to delete the old datasource first.

🤖 Generated with Claude Code

The Delta scrape config pointed at host.docker.internal:8081/8082, which cannot
work: the CMS slots publish to 127.0.0.1 only, so Prometheus dialling the
gateway address got connection refused on both targets. Verified on Delta --
both targets down with "dial tcp 172.17.0.1:8081: connect: connection refused".

Attach Prometheus to the CMS project's network instead and scrape the
containers on their internal port 8080. This needs no change to compose.cms.yml
and adds no host exposure. The network is declared external, so this stack
attaches to it and can never create or remove it; the cost is that the CMS
stack must now be up before the observability stack starts.

Blue now scrapes healthy. Green 404s until the next deploy rotates that slot
onto an image containing /metrics, which is expected rather than a fault.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ssavutu
ssavutu merged commit 4047673 into main Aug 4, 2026
6 checks passed
@ssavutu
ssavutu deleted the fix/prometheus-cms-network branch August 4, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant