Skip to content

Conversation

@Litarnus
Copy link
Contributor

This PR changes the flush_interval to Duration in order to allow sub-second flushing

@Litarnus Litarnus self-assigned this Jan 20, 2025
@Litarnus Litarnus marked this pull request as ready for review January 20, 2025 12:45
Litarnus added a commit to getsentry/relay that referenced this pull request Jan 20, 2025
This PR uses a fixed commit for `statsdproxy` that takes a `Duration`
instead of u64 seconds as `flush_interval` so we can see if reducing the
`flush_interval` helps with the metrics problem.

This is meant as a proof of concept, if it works we will update the
`statsdproxy` crate to support it regulary.

statsdproxy PR: getsentry/statsdproxy#55
pub aggregate_gauges: bool,
#[cfg_attr(feature = "cli", serde(default = "default_flush_interval"))]
pub flush_interval: u64,
pub flush_interval: Duration,
Copy link
Member

Choose a reason for hiding this comment

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

Should this have a custom deserializer so we can still parse e.g. 1 into seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that makes a lot of sense. I added the custom deserializer which defaults plain numbers to seconds (for backwards compatibility) while parsing numbers with unit suffixes using https://docs.rs/humantime/latest/humantime/index.html

Copy link
Member

Choose a reason for hiding this comment

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

I think humantime is too complicated here. why do we want it? does it just happen to align with how Relay represents duration in its config format? we use plain numbers in snuba, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that we have backwards compatibility by assuming that plain numbers are seconds while providing a possibility to have sub-second intervals.
I added humantime because I didn't want to roll time string parsing myself, but I can also simplify it by allowing seconds or milliseconds only and write the parsing code myself, what do you thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Relay configures this only in code, so the main concern was backwards compatibility

Copy link
Contributor Author

@Litarnus Litarnus Jan 23, 2025

Choose a reason for hiding this comment

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

I guess we could to get rid of the units entirely, although I'm not too happy to use floats when it's possible to represent it with integers

Copy link
Member

@untitaker untitaker Jan 23, 2025

Choose a reason for hiding this comment

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

We don't use "humantime" for any configuration parameters at all, in any YAML file in {snuba, sentry}. rather we use a numeric value and specify the unit as part of the name of the configuration parameter, such as flush_interval_ms: 1000.

I think preserving backwards compat can be done purely with serde primitives and custom deserializers + alias, but I would also be OK with just making that breaking change. Snuba does not make this kind of thing configurable in the first place, so there are no config files for us to migrate. I don't know about Relay.

Copy link
Contributor Author

@Litarnus Litarnus Jan 23, 2025

Choose a reason for hiding this comment

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

so can we just make this a float then? instead of pulling in a new dep

Fair point with the new dep, I would still suggest to allow plain numbers (= seconds) or using the ms suffix to treat it as milliseconds. This should give us enough flexibility without having more dependencies while keeping the parsing code fairly easy. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use "humantime" for any configuration parameters at all, in any YAML file in {snuba, sentry}. rather we use a numeric value and specify the unit as part of the name of the configuration parameter, such as flush_interval_ms: 1000.

I think preserving backwards compat can be done purely with serde primitives and custom deserializers + alias, but I would also be OK with just making that breaking change. Snuba does not make this kind of thing configurable in the first place, so there are no config files for us to migrate. I don't know about Relay.

Thanks for the write up, I will look into adding support for an additional parameter that represents ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After giving it a bit more thought I decided to introduce the breaking change for the sake of simplicity

@Litarnus Litarnus requested a review from untitaker January 23, 2025 08:38
@Dav1dde
Copy link
Member

Dav1dde commented Mar 5, 2025

@Litarnus what's the status on this? Relay is still on this fork/branch.

@Litarnus Litarnus merged commit 6fe9fa0 into main Apr 3, 2025
5 checks passed
@Litarnus Litarnus deleted the martinl/sub-second-flush branch April 3, 2025 12:57
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.

5 participants