towerops/lib/towerops/error_tracker_ignorer.ex
Graham McIntire a4e08b2aca Major codebase cleanup: DRY schemas, remove dead config, consolidate modules
- Created Towerops.Schema base macro (95+ schemas updated to use it)
- Created Towerops.Snmp.Reading macro (7 reading schemas consolidated)
- Created Towerops.Gaiia.BaseSchema macro (4 Gaiia schemas consolidated)
- Created Towerops.SyncLog shared module (UISP + Preseem merge)
- Created Towerops.LogFilters (3 log filter modules merged into 1)
- Created Towerops.OnCall.ChangesetHelpers (9 on-call schemas simplified)
- Created API v1 ResourceController shared helpers (7 controllers)
- Extracted ConnectionHelpers.format_connection_result (2 LiveViews)
- Removed 5 dead config keys (scopes, mib_dirs, stripe_meter_id, etc.)
- Fixed 2 pre-existing broken tests
- All 13,219 tests pass, Credo clean (0 issues)
2026-06-16 15:29:22 -05:00

43 lines
1.5 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.LogFilters.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