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

Allow configuring metrics collection #518

Open
hifi opened this issue Nov 9, 2023 · 1 comment
Open

Allow configuring metrics collection #518

hifi opened this issue Nov 9, 2023 · 1 comment

Comments

@hifi
Copy link
Collaborator

hifi commented Nov 9, 2023

When using Litestream as a library we found out that since litestream.NewDB exposes new promauto metrics there are a couple of issues. For one we can't disable metrics collection while we use Prometheus metrics within the main program so we're currently forced to expose per-database metrics.

Other is that we hit an unexpected deadlock as it seems the go Prometheus module holds a global lock while scraping and if the scraper is locked out and new metrics are being added it will deadlock as it will access the same lock. Making it easier to configure metrics collection and not explicitly adding them in NewDB would be a good start.

goroutine 1 [sync.RWMutex.Lock, 13 minutes]:
sync.runtime_SemacquireRWMutex(0x1?, 0x90?, 0xc000a06730?)
	/usr/local/go/src/runtime/sema.go:87 +0x25
sync.(*RWMutex).Lock(0x0?)
	/usr/local/go/src/sync/rwmutex.go:152 +0x6a
github.com/prometheus/client_golang/prometheus.(*metricMap).getOrCreateMetricWithLabelValues(0xc000824240, 0xc001f84f30?, {0xc001f84f30?, 0x1, 0x1}, {0x0?, 0x0, 0x0})
	/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/vec.go:513 +0x145
github.com/prometheus/client_golang/prometheus.(*MetricVec).GetMetricWithLabelValues(0xc000824210, {0xc001f84f20?, 0xc000a06840?, 0x413005?})
	/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/vec.go:233 +0x9c
github.com/prometheus/client_golang/prometheus.(*GaugeVec).GetMetricWithLabelValues(0xc000a06920?, {0xc001f84f20?, 0x46ec8e?, 0xc002c7632b?})
	/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/gauge.go:203 +0x1b
github.com/prometheus/client_golang/prometheus.(*GaugeVec).WithLabelValues(...)
	/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/gauge.go:236
github.com/benbjohnson/litestream.NewDB({0xc002c76300, 0x38})
	/go/pkg/mod/github.com/beeper/[email protected]/db.go:133 +0x35c
github.com/beeper/liteserv/internal/state.(*Database).Open(0xc0004f9130, 0xc000556b00)
	/build/internal/state/database.go:153 +0x93
github.com/beeper/liteserv/internal/state.(*State).tryStartReplicate(0xc0000e1600, {0x1f7e310, 0x2cdad40}, {{0x1f69ef0, 0xc00057e260}, 0x0, {0x0, 0x0}, {0xc00525f400, 0x5a, ...}, ...}, ...)
	/build/internal/state/state.go:258 +0x1ba
github.com/beeper/liteserv/internal/state.(*State).Start(0xc0000e1600, {0x1f7e310, 0x2cdad40})
	/build/internal/state/state.go:349 +0x103b
main.main()
	/build/cmd/liteserv/main.go:69 +0x445
@hifi
Copy link
Collaborator Author

hifi commented Nov 15, 2023

I haven't really figured out any neat way. The per-database metrics are what I'd want to disable but keep the replica ones as they are aggregates. Promauto is very handy but it's also an anti-pattern for libraries when you want to control what metrics are being exported.

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

No branches or pull requests

1 participant