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

feat(metrics): Add metrics buffering and sampling #821

Merged
merged 14 commits into from
Oct 29, 2020

Conversation

tonyo
Copy link
Contributor

@tonyo tonyo commented Oct 27, 2020

This PR adds the following features:

  1. Buffering + queuing option (metrics.buffering). If enabled, metrics will be queued and buffered in a separate thread. Set to true 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.
  2. Global sampling rate (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.

Copy link
Contributor

@flub flub left a 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?

@tonyo tonyo marked this pull request as ready for review October 27, 2020 17:50
@tonyo tonyo requested a review from a team October 27, 2020 17:50
Copy link
Member

@jan-auer jan-auer left a 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,
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Member

@jan-auer jan-auer left a 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.

@tonyo tonyo merged commit 6591568 into master Oct 29, 2020
@tonyo tonyo deleted the feat/cadence-improve-metrics-yess branch October 29, 2020 09:29
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