Repository navigation
[#699] Hold the metrics cache lock while the history worker scrapes - #700
lookslikeameya wants to merge 1 commit into
Conversation
|
@jesperpedersen PTAL. The Debug test failures also happen on main (#691). |
b92659f to
5c2a30a
Compare
5c2a30a to
a43489f
Compare
|
@Pranav-error Thanks, rebased on main (801d41c). All CI jobs pass now. PTAL |
Pranav-error
left a comment
There was a problem hiding this comment.
Reproduced #699 on 801d41c with history_interval = 1s and /metrics in a loop for 60s (macOS, PG 14, ASan): 2/205 scrapes had pgexporter_postgresql_active 0 and ~2 KB bodies. On a43489f: 0/200, and no history scrape overlapped a /metrics scrape. When I reverted only the local_history.c call, both symptoms came back: an active 0 scrape, and in a second run pg_monitor role check failed FATAL x3.
One thing to look at: metrics_page() jumps to error: without releasing cache->lock, so a client that drops mid-response leaves the lock held (#325, #725). With this PR the history worker waits on that lock too. After 5 aborted clients, the next /metrics on a43489f failed after 30s, and the log showed history: failed to scrape metrics 5 times. On 801d41c the same steps logged 0, because the worker doesn't take the lock there. Can #725 go in first?
There is no test. The race is timing-dependent, so I didn't ask for one. Not run: test/check.sh suite and Linux; CI is green.
|
@Pranav-error Thanks for testing! Agreed, #725 should go in first since #700 makes the history worker depend on that lock. Once #725 is merged I'll rebase. |
closes #699
The history timer worker scraped without the lock that
/metricsholds, so the two could use the sharedservers[]connection at the same time and reset each other'sfd. The worker now takes the same lock just for the scrape, and writes the snapshot after releasing it.A
/metricsrequest that arrives during a history scrape now waits for it, the same way two/metricsrequests already wait for each other. If the lock isn't free withinblocking_timeout, the worker skips that snapshot.Tested on macOS (arm64) with the setup from #699 (
history_interval = 1s, back-to-back/metricsscrapes for 60s):pgexporter_postgresql_active 0fdin 62 history scrapes running alongside 121/metricsscrapes