Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(metrics): Add bucket width to bucket protocol [INGEST-350] #1103

Merged
merged 11 commits into from
Oct 22, 2021

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Oct 21, 2021

Previously, incoming metrics buckets' timestamps were not checked at all, so it was possible to have overlapping buckets in the aggregator. This PR:

  • Adds a width field to the bucket protocol, so the upstream relay can decide what to do with bucket widths different than its own.
  • Adds logic to merge incoming buckets of any form into the target bucket corresponding to its center.
  • Adds sanity checks to the timestamps of both incoming raw metrics and incoming metrics buckets.

See also https://www.notion.so/sentry/Extension-to-the-bucket-protocol-6e7eb432e73f44eba868b6007d711b6c.

Copy link
Member Author

@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.

Metrics buckets are also parsed in store.rs, not sure if we have to do any error handling here:

https://github.com/getsentry/relay/blob/master/relay-server/src/actors/store.rs#L327

pub timestamp: UnixTimestamp,
/// The length of the time window in seconds.
pub width: u64,
Copy link
Member Author

Choose a reason for hiding this comment

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

A u32 would give us 136 years, but I decided to stick with u64 to reduce the number of conversions, and because

  • there's no difference in size for the serialized JSON,
  • Bucket objects are not stored in the aggregator (it stores BucketValue objects).

relay-metrics/src/aggregation.rs Outdated Show resolved Hide resolved
relay-metrics/src/aggregation.rs Outdated Show resolved Hide resolved
relay-server/src/actors/envelopes.rs Show resolved Hide resolved
relay-server/src/actors/envelopes.rs Show resolved Hide resolved
relay-server/src/statsd.rs Show resolved Hide resolved
@jjbayer jjbayer marked this pull request as ready for review October 21, 2021 08:24
@jjbayer jjbayer requested review from a team, jan-auer, RaduW and untitaker October 21, 2021 08:24
Copy link
Contributor

@RaduW RaduW left a comment

Choose a reason for hiding this comment

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

looks ok

@@ -54,8 +54,8 @@ def test_metrics(mini_sentry, relay):
received_metrics = json.loads(metrics_item.get_bytes().decode())
received_metrics = sorted(received_metrics, key=lambda x: x["name"])
assert received_metrics == [
{"timestamp": timestamp, "name": "bar", "value": 17.0, "type": "c"},
{"timestamp": timestamp, "name": "foo", "value": 42.0, "type": "c"},
{"timestamp": timestamp, "width": 1, "name": "bar", "value": 17.0, "type": "c"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a realistic test?

Don't we have min width 10s ( will this test need to change when we enforce/merge buckets)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. I think we used a one second bucket interval (and a delay of zero) in the integration test to make everything flush as quickly as possible. But we will have to change that once we enforce a min. bucket width.

relay-server/src/statsd.rs Outdated Show resolved Hide resolved
jjbayer and others added 2 commits October 22, 2021 12:30
Co-authored-by: Radu Woinaroski <5281987+RaduW@users.noreply.github.com>
@jjbayer jjbayer merged commit 541f6db into master Oct 22, 2021
@jjbayer jjbayer deleted the feat/metrics-bucket-width branch October 22, 2021 12:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants