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] ErrorStorage agent calls #98

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joaquinco
Copy link
Contributor

@joaquinco joaquinco commented Sep 18, 2024

  • Improve ErrorStorage.get_error_stats/1 by just fetching the error entry instead of the whole state and then getting the error entry.
  • Change reset logic to ErrorStorage.reset_stats/1 which resets an ErrorStorage entry and returns the previous occurrence.

Comment on lines 45 to 47
timestamp
|> default_error_storage()
|> Map.put(:accumulated_occurrences, 1),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can move this to the top (in line 39) so it's more clear this is the initial value for the Agent.

Something like

initial_error_storage = 
        |> timestamp
        |> default_error_storage()
        |> Map.put(:accumulated_occurrences, 1)

Or instead of calling that function default_error_storage rename it to build_error_storage and have something like this

default_error_storage = 
        |> timestamp
        |> build_error_storage()
        |> Map.put(:accumulated_occurrences, 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea!

@spec reset_accumulated_errors(error_strategy, ErrorInfo.t()) :: :ok
def reset_accumulated_errors(:exponential, error_info) do
%{key: error_hash_key} = error_info
@spec reset(ErrorInfo.t()) :: __MODULE__.t()
Copy link
Member

Choose a reason for hiding this comment

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

Loved the rename of this function 😍

Choose a reason for hiding this comment

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

What about something like ErrorStorage.reset_stats/2 or ErrorStorage.reset_and_get_stats/2

I'm thinking about the notifications_sender reading:

occurrences = ErrorStorage.reset_stats(error_info, notification_trigger)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense to be consistent with other ErrorStorage's functions

|> Map.update!(:__max_storage_capacity__, fn current -> min(current * 2, limit) end)
end)
)
def reset(error_info, strategy) when strategy in [:always, nil] do
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can remove this guard so it always fallbacks here if the strategy doesn't need to update the max_storage value

end

def reset_accumulated_errors(:always, error_info) do
defp reset_state(error_info, nil) do
Copy link
Member

Choose a reason for hiding this comment

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

NIT: defp reset_state(error_info, _limit_updater_function = nil) do

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.

3 participants