-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add MustCollector API for pusher #1067
Conversation
Signed-off-by: kun <oiooj@qq.com>
@oiooj Could you please explain the justification behind this change? It's hard to understand without any context. |
Hi @kakkoyun , We use the |
// | ||
// For convenience, this method returns a pointer to the Pusher itself. | ||
func (p *Pusher) MustCollector(c ...prometheus.Collector) *Pusher { | ||
p.registerer.MustRegister(c...) |
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.
I don't think adding an API that panics to the pusher is the right solution here.
If I'm not mistaken, I understand from you comment that you want to have an API to add multiple collectors. Would a simple for loop not satisfy your needs?
p := push.New("http://example.org/metrics", "my_job").
for _, c := range []prometheus.Collector{myCollector1, myCollector2} {
p.Collector(myCollector1)
}
p.Grouping("zone", "xy").Client(&myHTTPClient).BasicAuth("top", "secret").Add()
If somehow you don't want to use this, I might consider making Collector
method variadic.
func (p *Pusher) Collector(collectors ...prometheus.Collector) *Pusher {
if p.error != nil {
return p
}
for _, c := range collectors {
p.error = p.registerer.Register(c)
if p.error != nil {
return p
}
}
return p
}
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.
Is myCollector1 registered successfully? We want to know the result when the collectors is being registered. Maybe that is why Registerer
has the MustRegister
API.
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.
I see what you mean. We can consider adding a method the obtain the error from outside. I just don't want to add a method that panics in the pusher. None of the other APIs in the package do it. I'd prefer to keep the consistent behaviour.
New API #1075 merged, this PR closed. |
@kakkoyun PTAL