-
-
Notifications
You must be signed in to change notification settings - Fork 61
feat(metrics): Add UDS support, migrate to metrics-exporter-dogstatsd, and propagate runtime global tags #7796
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
Open
phacops
wants to merge
25
commits into
master
Choose a base branch
from
feat/dogstatsd-uds-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d68f883
feat(metrics): Add Unix domain socket support for DogStatsd
phacops c90c6f9
ref(metrics): DRY up statsd backend initialization in consumer
phacops c217abc
ref(metrics): Use cadence BufferedUnixMetricSink instead of custom Un…
phacops bb6f308
fix(metrics): Restore global tags for UDS statsd backend
phacops 63f5ffc
ref(metrics): Replace cadence and statsdproxy with metrics-exporter-d…
phacops 8451a89
Merge remote-tracking branch 'origin/master' into feat/dogstatsd-uds-…
phacops 198adfa
fix(metrics): Remove double prefix in DogStatsDBackend
phacops 981759b
fix(metrics): Default DOGSTATSD_SOCKET_PATH to None
phacops d52c39a
fix(metrics): Send histograms as DogStatsD histograms, not distributions
phacops 2dc615f
fix(deps): Resolve sentry-core version split in Cargo.lock
phacops 30cc6ef
build(rust): Use latest stable Rust toolchain
phacops 11d0129
ci: Install libcurl-dev for rdkafka-sys compilation
phacops 76d6792
fix(eap): Handle ProcessingError variant in TraceItemType match
phacops c3bf5da
fix(rust): Address new clippy lints from stable Rust 1.94
phacops 258a665
fix(build): Upgrade rdkafka-sys to 4.10.0 and fix CI build failures
phacops 7bf2c70
test(rust): Update schema snapshots for new kafka schema fields
phacops 9434bef
fix(deps): Deduplicate sentry_protos to single 0.8.2 version
phacops a6593d4
fix(metrics): Guard UDS path against None socket path
phacops 02dde3b
chore(deps): Align Cargo.toml versions with lockfile resolutions
phacops 431aab5
feat(metrics): Propagate runtime global tags to DogStatsD metrics
phacops 52b5cde
test(metrics): Add tests for runtime global tags
phacops 4aa3be3
Merge branch 'master' into feat/dogstatsd-uds-support
phacops 89f7802
fix(ci): Add libcurl-dev to docs and bump-version jobs, restore Sentr…
phacops a7ce0a7
Merge remote-tracking branch 'origin/master' into feat/dogstatsd-uds-…
phacops 61a2e18
fix: Update accepted_outcomes_consumer to use DogStatsDBackend
phacops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,125 +1,6 @@ | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use parking_lot::RwLock; | ||
| use statsdproxy::middleware::Middleware; | ||
| use statsdproxy::types::Metric; | ||
|
|
||
| static GLOBAL_TAGS: RwLock<BTreeMap<String, String>> = RwLock::new(BTreeMap::new()); | ||
|
|
||
| /// Sets a tag on the current Sentry scope. | ||
| pub fn set_global_tag(key: String, value: String) { | ||
| sentry::configure_scope(|scope| { | ||
| scope.set_tag(&key, &value); | ||
| }); | ||
| GLOBAL_TAGS.write().insert(key, value); | ||
| } | ||
|
|
||
| pub struct AddGlobalTags<'a, M> { | ||
| next: M, | ||
| global_tags: &'a RwLock<BTreeMap<String, String>>, | ||
| } | ||
|
|
||
| impl<M> AddGlobalTags<'static, M> | ||
| where | ||
| M: Middleware, | ||
| { | ||
| pub fn new(next: M) -> Self { | ||
| Self::new_with_tagmap(next, &GLOBAL_TAGS) | ||
| } | ||
| } | ||
|
|
||
| impl<'a, M> AddGlobalTags<'a, M> | ||
| where | ||
| M: Middleware, | ||
| { | ||
| fn new_with_tagmap(next: M, global_tags: &'a RwLock<BTreeMap<String, String>>) -> Self { | ||
| AddGlobalTags { next, global_tags } | ||
| } | ||
| } | ||
|
|
||
| impl<M> Middleware for AddGlobalTags<'_, M> | ||
| where | ||
| M: Middleware, | ||
| { | ||
| fn poll(&mut self) { | ||
| self.next.poll() | ||
| } | ||
|
|
||
| fn submit(&mut self, metric: &mut Metric) { | ||
| let global_tags = self.global_tags.read(); | ||
|
|
||
| if global_tags.is_empty() { | ||
| return self.next.submit(metric); | ||
| } | ||
|
|
||
| let mut tag_buffer: Vec<u8> = Vec::new(); | ||
| let mut add_comma = false; | ||
| match metric.tags() { | ||
| Some(tags) if !tags.is_empty() => { | ||
| tag_buffer.extend(tags); | ||
| add_comma = true; | ||
| } | ||
| _ => (), | ||
| } | ||
| for (k, v) in global_tags.iter() { | ||
| if add_comma { | ||
| tag_buffer.push(b','); | ||
| } | ||
| tag_buffer.extend(k.as_bytes()); | ||
| tag_buffer.push(b':'); | ||
| tag_buffer.extend(v.as_bytes()); | ||
| add_comma = true; | ||
| } | ||
|
|
||
| metric.set_tags(&tag_buffer); | ||
|
|
||
| self.next.submit(metric) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| use std::cell::RefCell; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use statsdproxy::{middleware::Middleware, types::Metric}; | ||
|
|
||
| struct FnStep<F>(pub F); | ||
|
|
||
| impl<F> Middleware for FnStep<F> | ||
| where | ||
| F: FnMut(&mut Metric), | ||
| { | ||
| fn submit(&mut self, metric: &mut Metric) { | ||
| (self.0)(metric) | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_basic() { | ||
| let test_cases = [ | ||
| // Without tags | ||
| ("users.online:1|c", "users.online:1|c|#env:prod"), | ||
| // With tags | ||
| ( | ||
| "users.online:1|c|#tag1:a", | ||
| "users.online:1|c|#tag1:a,env:prod", | ||
| ), | ||
| ]; | ||
|
|
||
| for test_case in test_cases { | ||
| let results = RefCell::new(vec![]); | ||
| let global_tags = RwLock::new(BTreeMap::from([("env".to_owned(), "prod".to_owned())])); | ||
|
|
||
| let step = FnStep(|metric: &mut Metric| results.borrow_mut().push(metric.clone())); | ||
| let mut middleware = AddGlobalTags::new_with_tagmap(step, &global_tags); | ||
|
|
||
| let mut metric = Metric::new(test_case.0.as_bytes().to_vec()); | ||
| middleware.submit(&mut metric); | ||
| assert_eq!(results.borrow().len(), 1); | ||
| let updated_metric = Metric::new(results.borrow_mut()[0].raw.clone()); | ||
| assert_eq!(updated_metric.raw, test_case.1.as_bytes()); | ||
| } | ||
| } | ||
| } | ||
sentry[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.