fix(metrics): defer ETS cron flusher on /metrics scrape

Without the deferral the cron-driven ETS flush GenServer fires every
7.5s alongside Prometheus scrapes, calls PromEx.get_metrics in a Task,
and dies with `Task.await ... time out` (hardcoded 10s) under contention.
Mirrors upstream PromEx.Plug, which calls defer_ets_flush after a
successful render specifically to suppress the cron while scraping is
healthy.
This commit is contained in:
Graham McIntire 2026-05-02 10:59:24 -05:00
parent af08e72816
commit 6c5d066121
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -18,6 +18,12 @@ defmodule MicrowavepropWeb.MetricsPlug do
:ok ->
body = PromEx.get_metrics(Microwaveprop.PromEx)
# Defer the ETS cron flusher; otherwise it runs every
# `ets_flush_interval` (7.5s) concurrently with scrapes and its
# `Task.await` (hardcoded 10s) trips under contention, killing
# the GenServer. Upstream `PromEx.Plug` does the same.
PromEx.ETSCronFlusher.defer_ets_flush(Microwaveprop.PromEx.__ets_cron_flusher_name__())
conn
|> put_resp_content_type("text/plain; version=0.0.4")
|> send_resp(200, body)