Skip to content

Conversation

@abhijeetsharma200
Copy link

Fixes #1136.

Will add the test as part of the PR to add tests to prometheus.go

return
}

snapshot := promAsyncMetricCache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have a longer lock rather than duplicating metric cache that might be huge on high loaded systems

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a deep copy; just a pointer swap (O(1), which is 8/4 bytes depending on OS). The map data stays in place, we just change which pointer the global variable holds. After processing, the old map gets garbage collected. New writes go to the fresh map and get picked up on the next scrape. There shouldn't be any data loss because prometheus is scraping periodically

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I noticed promAsyncMetricCache is a package-level global rather than a field on the PrometheusWriter struct. Is there a specific reason for that design? Just curious if multiple writer instances are expected to share the cache intentionally

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.

Data race in PrometheusWriter(concurrent map iteration/write)

2 participants