Skip to content

Conversation

karampok
Copy link
Contributor

@karampok karampok commented Oct 1, 2019

This PR brings the propagator/registrar/originator metrics under the standard metric pattern.
All metrics are under bs_beaconing prefix (namespace=bs, subsystem=beaconing)

Prometheus metrics can be observed by curling the metrics endpoint of a BS
$ curl -sS 127.0.0.179:30452/metrics |grep bs_beaconing

Contributes #3104


This change is Reviewable

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch from cbd5071 to 3cb3e3b Compare October 1, 2019 12:46
@karampok karampok requested review from oncilla and kormat October 1, 2019 12:58
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @karampok and @kormat)


go/beacon_srv/internal/beaconing/propagator.go, line 261 at r1 (raw file):

		}
		defer func() {
			metrics.Beaconing.PropagatorIntfTime(labels).Add(time.Since(time.Now()).Seconds())

that does not work
before it worked because the arguments are evaluated here and the counter was increased after the method has finished.


go/beacon_srv/internal/beaconing/propagator.go, line 290 at r1 (raw file):

			p.logger.Error("[beaconing.Propagator] Unable to send packet",
				"egIfid", egIfid, "err", err)
			metrics.Beaconing.PropagatorTotalBeacons(labels).Inc()

this should be ErrSend


go/beacon_srv/internal/metrics/beaconing.go, line 97 at r1 (raw file):

}

func (e *beaconing) PropagatorTotalRunTime() prometheus.Counter {

hmm, having a lot of Propagator* smells like you want to split that one out into a new struct.

soon you will have {Propagator,Originator,Registrar}* for a most of the counters.

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch 3 times, most recently from ebc550d to e2e49b2 Compare October 2, 2019 08:39
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 8 files reviewed, 3 unresolved discussions (waiting on @kormat and @oncilla)


go/beacon_srv/internal/beaconing/propagator.go, line 261 at r1 (raw file):

Previously, Oncilla wrote…

that does not work
before it worked because the arguments are evaluated here and the counter was increased after the method has finished.

Done.


go/beacon_srv/internal/beaconing/propagator.go, line 290 at r1 (raw file):

Previously, Oncilla wrote…

this should be ErrSend

Done.


go/beacon_srv/internal/metrics/beaconing.go, line 97 at r1 (raw file):

Previously, Oncilla wrote…

hmm, having a lot of Propagator* smells like you want to split that one out into a new struct.

soon you will have {Propagator,Originator,Registrar}* for a most of the counters.

I was not able to find a common name pattern, so split files is done

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 5 of 5 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kormat)

@karampok karampok changed the title bs: refactor propagator metric bs: refactor propagator/registrar metrics Oct 2, 2019
@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch 3 times, most recently from d589ceb to 9683d06 Compare October 3, 2019 06:37
@karampok karampok changed the title bs: refactor propagator/registrar metrics bs: refactor propagator/registrar/originator metrics Oct 3, 2019
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 10 of 11 files at r3.
Reviewable status: 13 of 14 files reviewed, 10 unresolved discussions (waiting on @karampok and @kormat)


go/beacon_srv/internal/beaconing/originator.go, line 161 at r3 (raw file):

	intf := o.cfg.Intfs.Get(o.ifID)
	if intf == nil {
		l := metrics.OriginatorLabels{EgIfID: 0, Result: metrics.ErrCreate}

This should probably be it's own error result

Here you can use EgIfID because it comes from the BS configuration, and not some outside input.


go/beacon_srv/internal/beaconing/originator.go, line 162 at r3 (raw file):

	if intf == nil {
		l := metrics.OriginatorLabels{EgIfID: 0, Result: metrics.ErrCreate}
		metrics.Originator.Beacons(l)

.Inc()?


go/beacon_srv/internal/beaconing/originator.go, line 171 at r3 (raw file):

	if err != nil {
		l := metrics.OriginatorLabels{EgIfID: o.ifID, Result: metrics.ErrCreate}
		metrics.Originator.Beacons(l)

ditto


go/beacon_srv/internal/beaconing/originator.go, line 185 at r3 (raw file):

	if err != nil {
		l := metrics.OriginatorLabels{EgIfID: o.ifID, Result: metrics.ErrSend}
		metrics.Originator.Beacons(l)

ditto


go/beacon_srv/internal/beaconing/originator.go, line 190 at r3 (raw file):

	o.onSuccess(intf)
	l := metrics.OriginatorLabels{EgIfID: o.ifID, Result: metrics.Success}
	metrics.Originator.Beacons(l)

ditto


go/beacon_srv/internal/metrics/originator.go, line 41 at r3 (raw file):

type originator struct {
	originatedBeacons prometheus.CounterVec

should be *prometheus.CounterVec


go/beacon_srv/internal/metrics/originator.go, line 48 at r3 (raw file):

	ns, sub := Namespace, "beaconing"
	return originator{
		originatedBeacons: *prom.NewCounterVec(ns, sub, "originated_beacons_total",

do not dereference pointer here


go/beacon_srv/internal/metrics/originator.go, line 50 at r3 (raw file):

		originatedBeacons: *prom.NewCounterVec(ns, sub, "originated_beacons_total",
			"Number of beacons originated", OriginatorLabels{}.Labels()),
		runtime: prom.NewCounter(ns, sub, "originator_run_durations_seconds_total",

s/durations/duration


go/beacon_srv/internal/metrics/registrar.go, line 77 at r3 (raw file):

func (e *registrar) Beacons(l RegistrarLabels) prometheus.Counter {
	return e.registeredBeacons.WithLabelValues(l.Values()...)
}

missing newline


go/beacon_srv/internal/metrics/registrar.go, line 81 at r3 (raw file):

	l := TypeOnlyLabel{SegType: s}
	return e.runtime.WithLabelValues(l.Values()...)
}

ditto

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 11 files at r3.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @karampok and @kormat)


go/beacon_srv/internal/metrics/originator.go, line 57 at r3 (raw file):

func (e *originator) Runtime() prometheus.Counter {
	return e.runtime
}

missing new line

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch from 9683d06 to 30df274 Compare October 3, 2019 14:20
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 11 of 14 files reviewed, 11 unresolved discussions (waiting on @kormat and @oncilla)


go/beacon_srv/internal/beaconing/originator.go, line 161 at r3 (raw file):

Previously, Oncilla wrote…

This should probably be it's own error result

Here you can use EgIfID because it comes from the BS configuration, and not some outside input.

Done.


go/beacon_srv/internal/beaconing/originator.go, line 162 at r3 (raw file):

Previously, Oncilla wrote…

.Inc()?

Done.


go/beacon_srv/internal/beaconing/originator.go, line 171 at r3 (raw file):

Previously, Oncilla wrote…

ditto

Done.


go/beacon_srv/internal/beaconing/originator.go, line 185 at r3 (raw file):

Previously, Oncilla wrote…

ditto

Done.


go/beacon_srv/internal/beaconing/originator.go, line 190 at r3 (raw file):

Previously, Oncilla wrote…

ditto

Done.


go/beacon_srv/internal/metrics/originator.go, line 41 at r3 (raw file):

Previously, Oncilla wrote…

should be *prometheus.CounterVec

why, is not everything the same?
https://github.com/scionproto/scion/blob/master/go/beacon_srv/internal/beaconing/metrics/metrics.go#L178

or
https://github.com/scionproto/scion/blob/master/go/beacon_srv/internal/metrics/revocation.go#L38


go/beacon_srv/internal/metrics/originator.go, line 48 at r3 (raw file):

Previously, Oncilla wrote…

do not dereference pointer here

same as above


go/beacon_srv/internal/metrics/originator.go, line 50 at r3 (raw file):

Previously, Oncilla wrote…

s/durations/duration

Done.


go/beacon_srv/internal/metrics/originator.go, line 57 at r3 (raw file):

Previously, Oncilla wrote…

missing new line

Done.


go/beacon_srv/internal/metrics/registrar.go, line 77 at r3 (raw file):

Previously, Oncilla wrote…

missing newline

Done.


go/beacon_srv/internal/metrics/registrar.go, line 81 at r3 (raw file):

Previously, Oncilla wrote…

ditto

Done.

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch 6 times, most recently from 086b916 to 34d2e28 Compare October 4, 2019 07:53
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 9 of 14 files reviewed, 11 unresolved discussions (waiting on @kormat and @oncilla)


go/beacon_srv/internal/metrics/originator.go, line 41 at r3 (raw file):

Previously, karampok (Konstantinos) wrote…

why, is not everything the same?
https://github.com/scionproto/scion/blob/master/go/beacon_srv/internal/beaconing/metrics/metrics.go#L178

or
https://github.com/scionproto/scion/blob/master/go/beacon_srv/internal/metrics/revocation.go#L38

Done.


go/beacon_srv/internal/metrics/originator.go, line 48 at r3 (raw file):

Previously, karampok (Konstantinos) wrote…

same as above

Done.

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch 2 times, most recently from 64d52c5 to 7263a78 Compare October 4, 2019 08:04
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @karampok and @kormat)


go/beacon_srv/internal/beaconing/originator.go, line 159 at r4 (raw file):

// originateBeacon originates a beacon on the given ifid.
func (o *beaconOriginator) originateBeacon(ctx context.Context) error {
	labels := metrics.OriginatorLabels{EgIfID: o.ifID, Result: metrics.ErrVerify}

should be metrics.Success, no?


go/beacon_srv/internal/beaconing/propagator.go, line 268 at r4 (raw file):

				"beacon", bseg, "err", err)
			labels.Result = metrics.ErrCreate
			metrics.Propagator.Beacons(labels).Inc()

I like WithResults more, but this is fine too.


go/beacon_srv/internal/metrics/originator.go, line 41 at r3 (raw file):

Previously, karampok (Konstantinos) wrote…

Done.

because of past mistakes :sad:

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch from 7263a78 to df2ef68 Compare October 4, 2019 08:28
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 13 of 14 files reviewed, 1 unresolved discussion (waiting on @kormat and @oncilla)


go/beacon_srv/internal/beaconing/originator.go, line 159 at r4 (raw file):

Previously, Oncilla wrote…

should be metrics.Success, no?

Done.


go/beacon_srv/internal/beaconing/propagator.go, line 268 at r4 (raw file):

Previously, Oncilla wrote…

I like WithResults more, but this is fine too.

The label is being used in the defer. So I need to modify that field.


go/beacon_srv/internal/metrics/originator.go, line 41 at r3 (raw file):

Previously, Oncilla wrote…

because of past mistakes :sad:

it's okay, you have saved many mistakes of me ;)

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @karampok and @kormat)


go/beacon_srv/internal/beaconing/propagator.go, line 268 at r4 (raw file):

Previously, karampok (Konstantinos) wrote…

The label is being used in the defer. So I need to modify that field.

ah, I didn't realize.

Maybe add a comment inside the deferred function:

// This captures the labels variable such that it can be modified in the code below.

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch 2 times, most recently from dd673a5 to 36823b9 Compare October 7, 2019 06:59
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 13 of 14 files reviewed, 1 unresolved discussion (waiting on @karampok, @kormat, and @oncilla)


go/beacon_srv/internal/beaconing/propagator.go, line 268 at r4 (raw file):

Previously, Oncilla wrote…

ah, I didn't realize.

Maybe add a comment inside the deferred function:

// This captures the labels variable such that it can be modified in the code below.

roar as loud as you can 🦁

s/bellow/below , also add period at the end.

@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch from 36823b9 to d15c196 Compare October 7, 2019 07:27
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r6.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kormat)

This commit brings the propagator metrics under the standard
metric pattern.

The following metrics should be seen at prometheus

```
bs_beaconing_propagated_beacons_total{eg_if_id="1",in_if_id="2",result="ok_success",start_ia="1-ff00:0:130"} 3
bs_beaconing_propagator_errors_total 0
bs_beaconing_propagator_interface_duration_seconds_total{eg_if_id="1",in_if_id="2",result="ok_success",start_ia="1-ff00:0:130"} 0.234
bs_beaconing_propagator_run_duration_seconds_total 0.30425184999999993
```

Because the code is inside the `internal/beaconing`, the subsystem of
the metrics changed to `beaconing`.

Also, metrics are not optional anymore.

Contributes scionproto#3104
This commit refactors the registrar metrics to fit the standard pattern.

```
bs_beaconing_registered_beacons_total{in_if_id="2",result="ok_success",seg_type="down",start_ia="1-ff00:0:130"} 8
bs_beaconing_registered_beacons_total{in_if_id="2",result="ok_success",seg_type="up",start_ia="1-ff00:0:130"} 7
bs_beaconing_registrar_run_durations_seconds_total{seg_type="down"} 0.381366876
bs_beaconing_registrar_run_durations_seconds_total{seg_type="up"} 0.663474004

```

Contributes scionproto#3104
This commit refactors the originator metrics to fit the standard pattern.

These are the metrics

```
bs_beaconing_originated_beacons_total{eg_if_id="1",result="ok_success"} 3
bs_beaconing_originated_beacons_total{eg_if_id="2",result="ok_success"} 3
bs_beaconing_originated_beacons_total{eg_if_id="3",result="ok_success"} 3
bs_beaconing_originator_run_durations_seconds_total 2.6630264029999995
```

* Internal error counter was merged with the result within beacon

Contributes scionproto#3104
@karampok karampok force-pushed the pub-refactor-bs-beaconing-metrics branch from d15c196 to a543e32 Compare October 8, 2019 10:44
Copy link
Contributor

@oncilla oncilla left a 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 r7.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kormat)

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kormat)

@karampok karampok merged commit 47f8afd into scionproto:master Oct 8, 2019
@karampok karampok deleted the pub-refactor-bs-beaconing-metrics branch October 17, 2019 12:01
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

Successfully merging this pull request may close these issues.

2 participants