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
Use Promauto.With() where possible #3263
Conversation
d462aff
to
7c89441
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. The primary goal of #2204 was to get rid of using global registry. I don't think adding dependency on prometheus.Registrerer
to types implementing prometheus.Collector
is a way to go here.
@@ -47,8 +47,8 @@ type alertmanagerMetrics struct { | |||
silencesPropagatedMessagesTotal *prometheus.Desc | |||
} | |||
|
|||
func newAlertmanagerMetrics() *alertmanagerMetrics { | |||
return &alertmanagerMetrics{ | |||
func newAlertmanagerMetrics(r prometheus.Registerer) *alertmanagerMetrics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alertmanagerMetrics
implements prometheus.Collector
interface. Collectors
typically don't register into registry themselves, but are registered by client code using them. I think we should keep that, and not pass registerer
into newAlertmanagerMetrics
.
pkg/util/metrics_helper.go
Outdated
@@ -465,11 +465,15 @@ func (d *HistogramData) Metric(desc *prometheus.Desc, labelValues ...string) pro | |||
} | |||
|
|||
// Creates new histogram data collector. | |||
func NewHistogramDataCollector(desc *prometheus.Desc) *HistogramDataCollector { | |||
return &HistogramDataCollector{ | |||
func NewHistogramDataCollector(r prometheus.Registerer, desc *prometheus.Desc) *HistogramDataCollector { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented earleir, collectors should not require registrerer.
In general, I don't think object should register itself anywhere in its "new" method. (I'm sure you will find many counter-examples in Cortex codebase). |
pkg/ruler/manager.go
Outdated
if reg != nil { | ||
reg.MustRegister(userManagerMetrics) | ||
} | ||
userManagerMetrics := NewManagerMetrics(reg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can now initialise it directly below:
userManagerMetrics: NewManagerMetrics(reg),
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this New(reg) pattern or not? @pstibrany says no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @roidelapluie for the long reply. Me and Peter had a discussion offline. We have a different opinion here. I commit to Peter's take: given ManagerMetrics
is a Collector
, and a Collector
shouldn't take the registerer, let's not pass the registerer to NewManagerMetrics()
.
Same applies to alertmanager metrics.
7c89441
to
85b04bd
Compare
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
85b04bd
to
57b9f20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Also ensures that other standalone objects are registered by adding a
registerer to their New() function.
Signed-off-by: Julien Pivotto roidelapluie@inuits.eu
What this PR does:
Which issue(s) this PR fixes:
Partially #2204 (still miss the default registry metrics)
Checklist
Tests updatedthere are existing tests covering thisDocumentation addedCHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]