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): Block metric tags with glob pattern #2973

Merged
merged 41 commits into from
Jan 24, 2024
Merged

feat(metrics): Block metric tags with glob pattern #2973

merged 41 commits into from
Jan 24, 2024

Conversation

TBS1996
Copy link
Contributor

@TBS1996 TBS1996 commented Jan 19, 2024

#2797

This PR introduces a way of deleting certain tags based on glob pattern matching.

@TBS1996 TBS1996 marked this pull request as ready for review January 23, 2024 12:56
@TBS1996 TBS1996 requested a review from a team as a code owner January 23, 2024 12:56
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.

Could you add an integration test that shows this new config being used? It would be great to get some input from @obostjancic on the usability of this config.

@@ -21,15 +21,29 @@ pub struct Metrics {
/// List of patterns for blocking metrics based on their name.
#[serde(skip_serializing_if = "GlobPatterns::is_empty")]
pub denied_names: GlobPatterns,
/// List of patterns of tags to remove.
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a bit more documentation on what that does? In contrast to the option above, it is worth pointing out that removing tags doesn't drop the overall metric bucket (i.e. the metric is still queryable without the removed tags).

You can also expand the docs on TagBlock, in which case it would be useful to actively refer to the docs on the struct.

relay_log::trace!(mri = bucket.name, "dropping metrics due to block list");
false
} else if Self::metric_namespace_invalid(state, bucket) {
Copy link
Member

Choose a reason for hiding this comment

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

metric_namespace_invalid tracks trace logs internally when it drops the bucket, but metric_name_denied does not. It's easy to miss this difference, so could we align this?

This function actually drops due to two reasons: an MRI that cannot be parsed, or an unknown namespace. If you prefer to have this in sub functions, I'd suggest to split those into two functions that just return booleans, and then log the messages here at the upper level. This would require you to pass the parsed MRI into the namespace function instead of the entire bucket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree thats better! I moved it up to the upper function now.

buckets.retain(|bucket| {
if metrics.denied_names.is_match(&bucket.name) {
metrics.retain_mut(|bucket| {
if Self::metric_name_denied(metrics_config, bucket) {
Copy link
Member

Choose a reason for hiding this comment

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

All of these functions are not associated with the Project struct in any way. Can we make them free functions?

@obostjancic
Copy link
Member

Could you add an integration test that shows this new config being used? It would be great to get some input from @obostjancic on the usability of this config.

cc @iambriccardo since he is implementing blocking endpoint in getsentry/sentry#63598

@TBS1996
Copy link
Contributor Author

TBS1996 commented Jan 24, 2024

Could you add an integration test that shows this new config being used?

Done!

@TBS1996 TBS1996 requested a review from jan-auer January 24, 2024 08:55
@TBS1996 TBS1996 self-assigned this Jan 24, 2024
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.

This reads really well, thank you for applying the suggestions. Good to merge 👍

#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct TagBlock {
/// Name of metric of which we want to remove certain tags.
pub name: GlobPatterns,
Copy link
Member

Choose a reason for hiding this comment

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

cc @obostjancic : If the product now wants to drop a tag for all metrics in the custom namespace, you would configure the glob pattern "?:custom/*".

@TBS1996 TBS1996 merged commit 13696a7 into master Jan 24, 2024
20 checks passed
@TBS1996 TBS1996 deleted the tagblock branch January 24, 2024 13:44
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