From 6c5d066121bc35782e8930ace1a9d02d3f3dfb41 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 2 May 2026 10:59:24 -0500 Subject: [PATCH] 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. --- lib/microwaveprop_web/metrics_plug.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/microwaveprop_web/metrics_plug.ex b/lib/microwaveprop_web/metrics_plug.ex index eaf8a654..440bdaf4 100644 --- a/lib/microwaveprop_web/metrics_plug.ex +++ b/lib/microwaveprop_web/metrics_plug.ex @@ -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)