Skip to content

Conversation

@crbelaus
Copy link
Contributor

@crbelaus crbelaus commented Aug 26, 2024

This pull request adds a new ErrorTracker.Plugins.Pruner which automatically prunes resolved errors. This plugin can be used automatically or manually.

ℹ️ I've also added a new priv/repo/seeds.exs script that populates the db with some fake errors and occurrences. May be useful for testing the dashboard, pruning and other features easily.

Automatic use

Register the plugin under the ErrorTracker configuration. The pruner will run in the background every 30 minutes and remove up to 1000 resolved errors older than 5 minutes (this options can be overriden)

config :error_tracker,
  repo: MyApp.Repo,
  otp_app: :my_app,
  plugins: [ErrorTracker.Plugins.Pruner]

Manual use

If you want to have more fine-grained control over when the pruner runs you can use the ErrorTracker.Plugins.Pruner.prune_errors/1 function. In this case you must pass the :limit and :max_age options explicitly.

You may want to call this function from an Oban job to leverage its cron-like capabilities.

defmodule MyApp.ErrorPruner do
  use Oban.Job

  def perform(%Job{}) do
    ErrorTracker.Plugins.Pruner.prune_errors(limit: 10_000, max_age: :timer.minutes(60))
  end
end

Closes #64

@crbelaus crbelaus self-assigned this Aug 26, 2024
@crbelaus crbelaus changed the title WIP: Pruner plugin Pruner plugin Aug 26, 2024
@crbelaus crbelaus changed the title Pruner plugin Plugin for pruning resolved errors Aug 26, 2024
@crbelaus crbelaus changed the title Plugin for pruning resolved errors Prune resolved errors Aug 26, 2024
Copy link
Contributor

@odarriba odarriba left a comment

Choose a reason for hiding this comment

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

I've added some comments. Overall looks good but I'm not sure if it covers all the functionality needed and if the options are the optimal ones.

Let me know what do you think @crbelaus

This column is used by the pruner so having an index improves the query
performance.
@crbelaus crbelaus requested a review from odarriba September 2, 2024 15:04
@crbelaus
Copy link
Contributor Author

crbelaus commented Sep 2, 2024

Should be ready to review again @odarriba

Copy link
Contributor

@odarriba odarriba left a comment

Choose a reason for hiding this comment

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

The only needed change is adding the -1 to calculating the filter timestamp.

Aside from that we could also use some tests of this plugin to ensure its behaviour does not change in the future.

@crbelaus crbelaus requested a review from odarriba September 6, 2024 14:47
Copy link
Contributor

@odarriba odarriba left a comment

Choose a reason for hiding this comment

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

🚢 🇮🇹

@crbelaus crbelaus merged commit cdf8cde into main Sep 8, 2024
@crbelaus crbelaus deleted the 64-prune-resolved-errors branch September 8, 2024 10:09
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.

Delete or prune errors

3 participants