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

ref(processor): Remove event_fully_normalized from state #4371

Merged
merged 7 commits into from
Dec 12, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Dec 11, 2024

This PR removes the event_fully_normalized from the state of the processor. It's part of a series of PRs that aim to get rid of the shared state, for improving the code quality of the processor.

#skip-changelog

@iambriccardo iambriccardo marked this pull request as ready for review December 11, 2024 15:05
@iambriccardo iambriccardo requested a review from a team as a code owner December 11, 2024 15:05

if_processing!(self.inner.config, {
unreal::process(state)?;
attachment::create_placeholders(state);
if let Some(inner_event_fully_normalized) = unreal::process(state)? {
Copy link
Member Author

Choose a reason for hiding this comment

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

Very ugly, but we have to have a tristate, since we need to represent the fact of not updating the event normalization boolean.

Copy link
Member

Choose a reason for hiding this comment

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

This would be less awkward with an enum that encodes the tristate. Then you could do something like event_fully_normalized.update(unreal::process(state)?);

Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

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

Can you add some more context to why you are doing this? Is the aim to remove the ProcessEnvelopeState struct entirely so we don't pass mutable state around?

@@ -1174,6 +1174,14 @@ impl Envelope {
}
}

/// Returns `true` whether the event is fully normalized, `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns `true` whether the event is fully normalized, `false`.
/// Returns `true` if the event is fully normalized.

@@ -1461,20 +1448,21 @@ impl EnvelopeProcessorService {
fn normalize_event<G: EventProcessing>(
&self,
state: &mut ProcessEnvelopeState<G>,
) -> Result<(), ProcessingError> {
mut event_fully_normalized: bool,
) -> Result<Option<bool>, ProcessingError> {
Copy link
Member

Choose a reason for hiding this comment

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

We should not pass this around as a boolean, it's too easy to have multiple bools mix. Let's make a newtype, it can be as simple as struct InsertNameHere(pub bool).

Copy link
Member

Choose a reason for hiding this comment

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

Or an enum!

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not opt for the enum since I want the type to represent the two possible states and then the Option refers to whether the calculation should change the value.

I could create a small macro to set the variables automatically, it could make the code nicer but it feels a bit overkill for now.

@@ -1174,6 +1174,14 @@ impl Envelope {
}
}

/// Returns `true` whether the event is fully normalized, `false`.
pub fn event_fully_normalized(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

I would not put normalization concerns and business logic on the envelope.

If we have a newtype, we also have a place to put it.

Copy link
Member

Choose a reason for hiding this comment

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

The fully_normalized flag is already on the envelope, so IMO it's fine to have this getter.

@iambriccardo
Copy link
Member Author

Can you add some more context to why you are doing this? Is the aim to remove the ProcessEnvelopeState struct entirely so we don't pass mutable state around?

Yes, this is specified in the PR description.

@iambriccardo iambriccardo merged commit e43aae9 into master Dec 12, 2024
23 checks passed
@iambriccardo iambriccardo deleted the riccardo/ref/remove-state-field branch December 12, 2024 11:46
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.

4 participants