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(server): Forward metrics in proxy mode #3106

Merged
merged 28 commits into from
Feb 19, 2024
Merged

fix(server): Forward metrics in proxy mode #3106

merged 28 commits into from
Feb 19, 2024

Conversation

TBS1996
Copy link
Contributor

@TBS1996 TBS1996 commented Feb 14, 2024

should fix: #3042

Problem was we're not able to send metrics through without scoping from the projectstate, but in proxy mode the projectstate isn't available for non-static projects.

This PR simply skips the aggregation pipeline for metrics in proxy mode and send it to processing instead, which for metric groups does nothing and simply forwards it to upstream.

@TBS1996 TBS1996 changed the title fix(server): Use projectstate::allowed in proxy mode. fix(server): Forward metrics unconditionally in proxy mode. Feb 14, 2024
@TBS1996 TBS1996 changed the title fix(server): Forward metrics unconditionally in proxy mode. fix(server): Forward metrics with partial scoping Feb 14, 2024
if let Some(scoping) = self.partial_scoping() {
let mut bucket_map = HashMap::new();
bucket_map.insert(scoping.project_key, buckets);
project_cache.send(FlushBuckets {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

skipped the aggregator for simplicity because it checks for scoping from projectstate and also features in rate_limit_and_merge_buckets.

i wasnt sure if we should also skip handle_flush_buckets? it checks if it's ratelimited, do we care about ratelimiting in proxy mode?

@TBS1996 TBS1996 marked this pull request as ready for review February 14, 2024 22:24
@TBS1996 TBS1996 requested a review from a team as a code owner February 14, 2024 22:24
@TBS1996 TBS1996 self-assigned this Feb 14, 2024
@@ -62,6 +62,52 @@ def metrics_by_name_group_by_project(metrics_consumer, timeout=None):
return metrics_by_project


def test_metrics_proxy_mode(mini_sentry, relay):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test fails without the changes in this PR

@TBS1996 TBS1996 changed the title fix(server): Forward metrics with partial scoping fix(server): Forward metrics in proxy mode Feb 16, 2024
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Nice! See comment about missing condition.

CHANGELOG.md Outdated Show resolved Hide resolved
relay-server/src/endpoints/common.rs Show resolved Hide resolved
@@ -234,6 +234,15 @@ impl ProcessingGroup {
))
}

let is_metric = |i: &Item| matches!(i.ty(), ItemType::Statsd | ItemType::MetricBuckets);
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth adding metrics meta to the integration test as well:

Suggested change
let is_metric = |i: &Item| matches!(i.ty(), ItemType::Statsd | ItemType::MetricBuckets);
let is_metric = |i: &Item| matches!(i.ty(), ItemType::Statsd | ItemType::MetricBuckets | ItemType::MetricMeta);

We could add a is_metrics() method to ItemType and use it in queue_envelope and here.

project_id = 42

timestamp = int(datetime.now(tz=timezone.utc).timestamp())
metrics_payload = f"transactions/foo:42|c\ntransactions/bar:17|c|T{timestamp}"
Copy link
Member

Choose a reason for hiding this comment

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

Please also add a buckets payload and a metrics meta payload.

project_key: envelope.meta().public_key(),
})
// Remove metric meta from the envelope and send them directly to processing.
let metric_meta = envelope.take_items_by(|item| matches!(item.ty(), ItemType::MetricMeta));
Copy link
Member

Choose a reason for hiding this comment

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

Nice! We didn't forget about metric meta.

@TBS1996 TBS1996 requested review from jjbayer and Dav1dde February 19, 2024 08:04
@TBS1996 TBS1996 merged commit 0f10358 into master Feb 19, 2024
20 checks passed
@TBS1996 TBS1996 deleted the proxmet branch February 19, 2024 11:12
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.

Proxy Relay drops Metrics because of missing feature flags
3 participants