-
Notifications
You must be signed in to change notification settings - Fork 173
bs: initialise metrics #3268
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
bs: initialise metrics #3268
Conversation
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.
Reviewed 3 of 3 files at r1.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @karampok)
doc/Metrics.md, line 139 at r1 (raw file):
func newOriginator() originator { ns, sub := Namespace, "beaconing"
What's the advantage of using an additional variable for Namespace?
doc/Metrics.md, line 144 at r1 (raw file):
b := prom.NewCounterVec(ns, sub, "originated_beacons_total", "Number of beacons originated", lab.Labels()) b.WithLabelValues(lab.Values()...).Inc()
As pointed out in chat Inc
should not be needed.
doc/Metrics.md, line 144 at r1 (raw file):
b := prom.NewCounterVec(ns, sub, "originated_beacons_total", "Number of beacons originated", lab.Labels()) b.WithLabelValues(lab.Values()...).Inc()
Optimally we would use label values that will be used afterwards. Otherwise maybe we should define some default placeholders?
doc/Metrics.md, line 148 at r1 (raw file):
r := prom.NewCounter(ns, sub, "originator_run_duration_seconds_total", "Originator total time spent on every periodic run") r.Inc()
That should not be needed.
go/beacon_srv/internal/metrics/originator.go, line 57 at r1 (raw file):
b := prom.NewCounterVec(ns, sub, "originated_beacons_total", "Number of beacons originated", lab.Labels()) b.WithLabelValues(lab.Values()...).Inc()
without Inc
go/beacon_srv/internal/metrics/originator.go, line 61 at r1 (raw file):
r := prom.NewCounter(ns, sub, "originator_run_duration_seconds_total", "Originator total time spent on every periodic run") r.Inc()
not needed
go/beacon_srv/internal/metrics/revocation.go, line 47 at r1 (raw file):
i := prom.NewCounterVec(ns, sub, "received_revocations_total", "Total number of received revocation msgs.", lab.Labels()) i.WithLabelValues(lab.Values()...).Inc()
Without Inc
a592d09
to
29d4755
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.
Reviewable status: 0 of 14 files reviewed, 8 unresolved discussions (waiting on @lukedirtwalker)
doc/Metrics.md, line 139 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
What's the advantage of using an additional variable for Namespace?
there is times where the ns,sub is coming from the arguments. In that case the code base looks more uniform overall.
But no strong reason.
doc/Metrics.md, line 144 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
As pointed out in chat
Inc
should not be needed.
Done.
doc/Metrics.md, line 144 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
Optimally we would use label values that will be used afterwards. Otherwise maybe we should define some default placeholders?
Done.
doc/Metrics.md, line 148 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
That should not be needed.
Done.
go/beacon_srv/internal/metrics/originator.go, line 57 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
without Inc
Done.
go/beacon_srv/internal/metrics/originator.go, line 61 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
not needed
Done.
go/beacon_srv/internal/metrics/revocation.go, line 47 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
Without Inc
Done.
go/lib/prom/prom.go, line 134 at r2 (raw file):
} c := prometheus.NewCounterVec(opts, labelNames) SafeRegister(c)
I am not sure if this safe.
In theory nobody should depend on the fact that prometheus will panic if duplicate metric in a normal workflow.
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.
Reviewed 14 of 14 files at r3.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @karampok)
doc/Metrics.md, line 139 at r3 (raw file):
func newOriginator() originator { sub := "originator"
Subsystem is beaconing
in the code?
doc/Metrics.md, line 310 at r3 (raw file):
nitialize always
Always initialize ...
go/beacon_srv/internal/metrics/beaconing.go, line 57 at r3 (raw file):
return beaconing{ receivedBeacons: prom.NewCounterVecWithLabels(ns, sub, "received_beacons_total", "Total number of received beacons.", BeaconingLabels{}),
Here you could simply use the old version? Or is the plan to migrate everything towards VecWithLabels?
go/lib/prom/prom.go, line 134 at r2 (raw file):
Previously, karampok (Konstantinos) wrote…
I am not sure if this safe.
In theory nobody should depend on the fact that prometheus will panic if duplicate metric in a normal workflow.
I think you need to use the return value of SafeRegister
otherwise you might return a countervec that isn't registered.
go/lib/prom/prom.go, line 140 at r3 (raw file):
} c := prometheus.NewCounterVec(opts, label.Labels()) SafeRegister(c)
c := SafeRegister(c).(*prometheus.CounterVec)
29d4755
to
fab63fa
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.
Reviewable status: 12 of 14 files reviewed, 4 unresolved discussions (waiting on @lukedirtwalker)
doc/Metrics.md, line 139 at r3 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
Subsystem is
beaconing
in the code?
Done.
doc/Metrics.md, line 310 at r3 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
nitialize always
Always initialize ...
Done.
go/beacon_srv/internal/metrics/beaconing.go, line 57 at r3 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
Here you could simply use the old version? Or is the plan to migrate everything towards VecWithLabels?
The VecWithLabels
will enable to insert default label values that will create in prometheus a timestamp that later will be re-used. So yes, my plan would be to change the components that can make use of that.
What do you think? does it make sense? Does that make sense to try to replace all with VecWithLabels
I was thinking to create an issue replace all with VecWithLabels
and add a comment in the old function not to be re-used again in a new code.
go/lib/prom/prom.go, line 140 at r3 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
c := SafeRegister(c).(*prometheus.CounterVec)
Done.
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.
Reviewed 2 of 2 files at r4.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @karampok)
go/beacon_srv/internal/metrics/beaconing.go, line 57 at r3 (raw file):
Previously, karampok (Konstantinos) wrote…
The
VecWithLabels
will enable to insert default label values that will create in prometheus a timestamp that later will be re-used. So yes, my plan would be to change the components that can make use of that.What do you think? does it make sense? Does that make sense to try to replace all with
VecWithLabels
I was thinking to create an issue
replace all with VecWithLabels
and add a comment in the old function not to be re-used again in a new code.
I think we should replace all, and we could do it as part of this PR.
go/lib/prom/prom.go, line 142 at r4 (raw file):
ret, ok := SafeRegister(c).(*prometheus.CounterVec) if !ok { panic("Should never happen")
Isn't that the default behavior if you don't have the , ok
? I would just leave it away, i.e. really just use:
c = SafeRegister(c).(*prometheus.CounterVec)
801d536
to
f97e635
Compare
Also it changes the implementation not to panic when a duplicate metrics is registered. Fixes scionproto#3265
f97e635
to
3aa47b1
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.
Reviewed 16 of 16 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @karampok)
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.
Reviewable status:
complete! all files reviewed, all discussions resolved
This change is