Skip to content
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

fix forwarded metrics #2273

Merged
merged 1 commit into from
Jul 16, 2024
Merged

fix forwarded metrics #2273

merged 1 commit into from
Jul 16, 2024

Conversation

mlsmaycon
Copy link
Collaborator

Describe your changes

Issue ticket number and link

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

@mlsmaycon mlsmaycon requested a review from lixmal July 15, 2024 22:03
Copy link

//forward the message to the target peer
if err := dstPeer.Stream.Send(msg); err != nil {
log.Errorf("error while forwarding message from peer [%s] to peer [%s] %v", msg.Key, msg.RemoteKey, err)
//todo respond to the sender?

s.metrics.MessageForwardFailures.Add(ctx, 1, metric.WithAttributes(attribute.String(labelType, labelTypeError)))
} else {
s.metrics.MessageForwardLatency.Record(ctx, float64(time.Since(start).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeMessage)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of /1e6 we could use time.Since(start).Milliseconds(), I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you do that we'll lose precision, as Milliseconds returns an int, but we have fractional milliseconds in the histogram buckets:

https://github.com/netbirdio/netbird/blob/main/signal%2Fmetrics%2Fapp.go#L90-L104

But maybe we don't need those small buckets in the first place. We should take a look at the actual data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let's keep them for now

signal/server/signal.go Show resolved Hide resolved
//forward the message to the target peer
if err := dstPeer.Stream.Send(msg); err != nil {
log.Errorf("error while forwarding message from peer [%s] to peer [%s] %v", msg.Key, msg.RemoteKey, err)
//todo respond to the sender?

s.metrics.MessageForwardFailures.Add(ctx, 1, metric.WithAttributes(attribute.String(labelType, labelTypeError)))
} else {
s.metrics.MessageForwardLatency.Record(ctx, float64(time.Since(start).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeMessage)))
Copy link
Contributor

Choose a reason for hiding this comment

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

If you do that we'll lose precision, as Milliseconds returns an int, but we have fractional milliseconds in the histogram buckets:

https://github.com/netbirdio/netbird/blob/main/signal%2Fmetrics%2Fapp.go#L90-L104

But maybe we don't need those small buckets in the first place. We should take a look at the actual data.

@mlsmaycon mlsmaycon merged commit 88d1c5a into main Jul 16, 2024
22 checks passed
@mlsmaycon mlsmaycon deleted the fix/signal-metrics branch July 16, 2024 08:14
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.

3 participants