Skip to content

Enable promlinter in golangci-lint #4171

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

Closed
yeya24 opened this issue May 10, 2021 · 3 comments
Closed

Enable promlinter in golangci-lint #4171

yeya24 opened this issue May 10, 2021 · 3 comments
Labels

Comments

@yeya24
Copy link
Contributor

yeya24 commented May 10, 2021

Hi, promlinter is a metric name static linter based on the Prometheus metrics naming best practice. It was added to golangci-lint recently and I want to introduce it to Cortex.

As it is only a static linter, it can only detect partial metrics naming problems. But I still feel it useful to have it as part of CI.

From what I tried on the Cortex repo, it detects some metrics naming problems listed below:

pkg/chunk/cache/instrumented.go:39:46: Metric: cortex_cache_fetched_keys Error: counter metrics should have "_total" suffix (promlinter)
		fetchedKeys: promauto.With(reg).NewCounter(prometheus.CounterOpts{
		                                           ^
pkg/chunk/cache/instrumented.go:46:39: Metric: cortex_cache_hits Error: counter metrics should have "_total" suffix (promlinter)
		hits: promauto.With(reg).NewCounter(prometheus.CounterOpts{
		                                    ^
pkg/compactor/blocks_cleaner.go:101:48: Metric: cortex_bucket_blocks_count Error: non-histogram and non-summary metrics should not have "_count" suffix (promlinter)
		tenantBlocks: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
		                                             ^
pkg/compactor/blocks_cleaner.go:105:54: Metric: cortex_bucket_blocks_marked_for_deletion_count Error: non-histogram and non-summary metrics should not have "_count" suffix (promlinter)
		tenantMarkedBlocks: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
		                                                   ^
pkg/compactor/blocks_cleaner.go:109:55: Metric: cortex_bucket_blocks_partials_count Error: non-histogram and non-summary metrics should not have "_count" suffix (promlinter)
		tenantPartialBlocks: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
		                                                    ^
pkg/ruler/manager.go:69:46: Metric: cortex_ruler_managers_total Error: non-counter metrics should not have "_total" suffix (promlinter)
		managersTotal: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
		                                           ^
pkg/ingester/metrics.go:162:43: Metric: cortex_ingester_sent_chunks Error: counter metrics should have "_total" suffix (promlinter)
		sentChunks: promauto.With(r).NewCounter(prometheus.CounterOpts{
		                                        ^
pkg/ingester/metrics.go:166:47: Metric: cortex_ingester_received_chunks Error: counter metrics should have "_total" suffix (promlinter)
		receivedChunks: promauto.With(r).NewCounter(prometheus.CounterOpts{
		                                            ^
pkg/chunk/purger/purger.go:74:59: Metric: cortex_purger_pending_delete_requests_count Error: non-histogram and non-summary metrics should not have "_count" suffix (promlinter)
	m.pendingDeleteRequestsCount = promauto.With(r).NewGauge(prometheus.GaugeOpts{

Please let me know what should I do to these metrics, whether I should rename them or not. If I need to rename them, what else should I do? (Like rename these metrics in the Grafana dashboards as well) Thanks!

@pracucci
Copy link
Contributor

Thanks @yeya24 for raising this! Renaming metrics, despite correct, tends to be a bit annoying for Cortex users cause this will have an impact on dashboards and alerts. My suggestion is to add the linter and a lint ignore comment for these cases, so that at least we'll be covered for new metrics we'll add.

@gliptak
Copy link
Contributor

gliptak commented Jun 1, 2021

#4241

@pstibrany pstibrany mentioned this issue Jun 2, 2021
3 tasks
@stale
Copy link

stale bot commented Aug 31, 2021

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 31, 2021
@stale stale bot closed this as completed Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants