-
Notifications
You must be signed in to change notification settings - Fork 91
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
ref(actix): Migrate Aggregator actor to new tokio runtime [INGEST-1645] #1508
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there's still an lot of actix code left in here? Is that intentional?
relay-metrics/src/aggregation.rs
Outdated
let receiver = TestReceiver::default(); | ||
// Create the new tokio runtime where we start AggregatorService | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
// Run in the old actix system for receiver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really still need the old runtime for this test? Can we not convert TestReceiver to tokio as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but in production we still have project_cache
actor which uses old system and we still have to test it.
Once we convert that actor to the new tokio, we can change all of this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but these tests are to make sure the aggregation actor works i think, not to make sure that the callers/senders mess something up?
relay-metrics/src/aggregation.rs
Outdated
iter::{FromIterator, FusedIterator}, | ||
mem, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
use actix::prelude::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed, should it not?
relay-metrics/src/aggregation.rs
Outdated
@@ -1388,15 +1437,16 @@ impl<T: Iterator<Item = Bucket>> FusedIterator for CappedBucketIter<T> {} | |||
/// all elapsed buckets belonging to the same [`ProjectKey`] are flushed together. | |||
/// | |||
/// Receivers must implement a handler for the [`FlushBuckets`] message. | |||
pub struct Aggregator { | |||
pub struct AggregatorService { | |||
config: AggregatorConfig, | |||
buckets: HashMap<BucketKey, QueuedBucket>, | |||
receiver: Recipient<FlushBuckets>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recipient
is still something actix, why is that still here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This service still interacts with project_cache
actor which runs on the old actix. I wanted to keep these changes to the minimum and then when the project_cache
is converted we can remove this Recipient
and maybe replace it with mpsc
channel?
I can look into it and maybe introduce changes in this PR, if that's better for the progress of migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the approach has been to use compat senders during the transition, I think that makes the most sense here as well. the code here will become easier to grasp if it is fully converted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me in general, just some questions for my own understanding.
pub partition_key: Option<u64>, | ||
/// The buckets to be flushed. | ||
pub buckets: Vec<Bucket>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to reorder these declarations, but it also makes the diff hard to read. What if we keep them where they were, and do the reordering in a separate PR that does not change anything functionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is difficult to parse I can move those structs back. I decided to move all in one place so it either to see how the API of this service looks like and one can see all the messages and impl
s for them in one place.
relay-metrics/benches/aggregator.rs
Outdated
@@ -1,12 +1,11 @@ | |||
use std::collections::BTreeMap; | |||
use std::fmt; | |||
use std::{collections::BTreeMap, fmt}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking, but what makes this stuff gratuitously change like this? is it some tooling? what's wrong with the existing style?
FWIW while it's not explicitly called out in our how to write rust the example suggests the existing style: https://www.notion.so/sentry/HOWTO-Code-Rust-at-Sentry-7b35f165b10b4492bb95ebe1471a9ada#4f8cc9ec744c472ebcc89791400d519c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically VIM setup I did to merge all the imports if they are coming from the same crate. I will revert it to the previous state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, is this vim-specific or some rustfmt or rust-analyzer setting that I don't know about? How does this work? I'm curious :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My config for rustfmt
contains
imports_granularity = "Crate"
and then in vim I run following when I want to auto format the file:
> rustfmt +nightly <path to file>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In VSCode / rust-analyzer, I use this:
{
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.prefix": "crate"
}
Will probably check that in. Unfortunately, that doesn't create separate a import group for all relay_*
crates, but we can consider removing that convention.
Generally, we run with rustfmt defaults and no overrides.
partition_key, | ||
buckets: batch, | ||
}; | ||
compat::send_to_recipient(receiver, flush_buckets); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, i agree this is the right way to do this :)
fn handle_shutdown(&mut self, message: &Option<Shutdown>) { | ||
if let Some(message) = message { | ||
if message.timeout.is_some() { | ||
self.state = AggregatorState::ShuttingDown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there used to be a log message here, not sure if it's important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have another message when the aggregator will stop, I don't see the reason to add more logs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
In tests there are still some broken indentation fixes, if you look at the diff including whitespace you will see them. It would be great to get those reverted before merging this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment on all the indentation stuff - would be great to not pollute the commit history with noise like that
Let's convert Metric Aggregator actor to
tokio
runtime.In this PR:
AggregatorService
which runs ontokio
runtimeSome open questions: