SkyeYoung commented on code in PR #12383: URL: https://github.com/apache/apisix/pull/12383#discussion_r2224482257
########## apisix/plugins/prometheus/exporter.lua: ########## @@ -498,10 +533,105 @@ local function collect(ctx, stream_only) end end + return core.table.concat(prometheus:metric_data()) +end + + +local function exporter_timer(premature, yieldable, cache_exptime) + if premature then + return + end + + if not prometheus then + return + end + + if exporter_timer_running then + core.log.warn("Previous calculation still running, skipping") + return + end + + exporter_timer_running = true + + local ok, res = pcall(collect, yieldable) + if not ok then + core.log.error("Failed to collect metrics: ", res) + exporter_timer_running = false + return + end + + -- Clear the cached data after cache_exptime to prevent stale data in case of an error. + local _, err, forcible = shdict_prometheus_cache:set(CACHED_METRICS_KEY, res, cache_exptime) + Review Comment: ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org