Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: occasional 500 error when being scraped for metrics #81

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/collector/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ func (m *metricEntry) init(prefix string, spec *public.MetricSpec, flushInterval
}

func (m *metricEntry) Collect(ch chan<- prometheus.Metric) {
m.metrics.Range(func(item *ttlcache.Item[string, prometheus.Counter]) bool {
// we don't use the Range function on the cache as it doesn't seem to be
// very thread-safe, ie it emits the same value more than once which
// results in 500 errors when being scraped. So instead we take a copy...
for _, item := range m.metrics.Items() {
ch <- item.Value()
return true
})
}
}

func (m *metricEntry) Describe(ch chan<- *prometheus.Desc) {
Expand Down
Loading