Removes unreachable catch-all clauses, drops unused `require Logger` lines, adds pin operators to bitstring size patterns, reorders function heads for correct dispatch, and replaces deprecated LoggerBackends calls.
43 lines
1.6 KiB
Elixir
43 lines
1.6 KiB
Elixir
defmodule Towerops.ErrorTrackerIgnorer do
|
|
@moduledoc """
|
|
Drops benign errors from ErrorTracker that occur during K8s pod shutdown
|
|
or transient DB connection cycling.
|
|
|
|
Matches the same patterns as `Towerops.LoggerFilters.drop_shutdown_errors/2`.
|
|
"""
|
|
|
|
@behaviour ErrorTracker.Ignorer
|
|
|
|
@impl true
|
|
def ignore?(%ErrorTracker.Error{reason: reason} = error, _context) do
|
|
shutdown_error?(reason) or transient_db_error?(error)
|
|
end
|
|
|
|
defp shutdown_error?(reason) when is_binary(reason) do
|
|
String.contains?(reason, "port_died") or
|
|
String.contains?(reason, "write_failed") or
|
|
String.contains?(reason, "epipe") or
|
|
String.contains?(reason, "broken pipe")
|
|
end
|
|
|
|
defp shutdown_error?(_), do: false
|
|
|
|
# Transient DB connection drops surface as DBConnection.ConnectionError. The
|
|
# Repo's aggressive idle/queue cycling (queue_target/queue_interval,
|
|
# disconnect_on_error_codes) intentionally tears down stale SSL connections,
|
|
# which can interrupt queries mid-flight. Common reasons we don't want to
|
|
# log: "connection is closed..." and "transaction rolling back". The query
|
|
# is retried by the caller; logging adds noise without value.
|
|
@transient_db_phrases [
|
|
"connection is closed",
|
|
"transaction rolling back"
|
|
]
|
|
|
|
defp transient_db_error?(%ErrorTracker.Error{reason: reason, kind: kind}) do
|
|
binary_reason = to_string(reason || "")
|
|
binary_kind = to_string(kind || "")
|
|
|
|
String.contains?(binary_kind, "DBConnection.ConnectionError") and
|
|
Enum.any?(@transient_db_phrases, &String.contains?(binary_reason, &1))
|
|
end
|
|
end
|