-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(metrics): Add metrics buffering and sampling #821
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.
Looks good. IIRC queued means that cadence starts a new thread and runs the udp sending code there?
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.
For a more generic solution it would be great to eventually flush the queued metrics automatically. I agree that this is not a blocker for Relay at the moment.
@@ -75,6 +83,8 @@ pub struct MetricsClient { | |||
pub statsd_client: StatsdClient, | |||
/// Default tags to apply to every metric | |||
pub default_tags: BTreeMap<String, String>, | |||
/// Global sample rate | |||
pub sample_rate: f32, |
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.
Note: After merging, this needs to be added to docs as well.
@@ -16,7 +16,7 @@ clean: | |||
# Builds | |||
|
|||
build: setup-git | |||
@cargo +stable build --all-features | |||
cargo +stable build --all-features |
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.
This change is unrelated, can we revert?
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 found it useful to see what we're actually building, it's the same behavior we have for test
and lint
targets.
@@ -140,15 +177,51 @@ pub fn configure_statsd<A: ToSocketAddrs>( | |||
prefix: &str, | |||
host: A, | |||
default_tags: BTreeMap<String, String>, | |||
buffering: bool, | |||
sample_rate: f32, |
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.
This function is now sufficiently complex to become a builder. I'm happy to make the changes in a follow-up, since I'd like to move all metrics and logging related concerns from relay-common into a separate crate anyway.
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.
Thanks, @tonyo! Let's follow up with a PR to sentry-docs introducing the new configuration options.
This PR adds the following features:
metrics.buffering
). If enabled, metrics will be queued and buffered in a separate thread. Set totrue
by default.Caveat:
BufferedUdpMetricSink
doesn't flush until the buffer is full, so theoretically, if relay doesn't emit any metrics for a while (or if the sampling rate is set to something low), there could be delays in sending the metrics. But some metrics relay sends (e.g. about open/reused connections) are emitted regularly, so it shouldn't be an issue.metrics.sample_rate
). Set to 1.0 by default.Note: the sampling implementation is pretty naive now, so for example we might simply ignore some calls to counters without scaling it back.