Skip to content

Commit

Permalink
DB connection details logging (#2274)
Browse files Browse the repository at this point in the history
* feat: log some information on RDS token

* feat: report for max_connections

* feat: report for authentication_timeout

* feat: log token hash
  • Loading branch information
lemald authored Nov 8, 2023
1 parent f8fc4c4 commit 3472ae9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defmodule Report do
Report.UserNamesAndUuids,
Report.UserConfigurations,
Report.NotificationsCountEstimate,
Report.NotificationsUsersCountEstimate
Report.NotificationsUsersCountEstimate,
Report.MaxConnections,
Report.AuthenticationTimeout
]

@callback run() :: {:ok, [map()]} | :error
Expand Down
21 changes: 21 additions & 0 deletions lib/report/authentication_timeout.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Report.AuthenticationTimeout do
@moduledoc """
Report Postgres' configured authentication_timeout
"""

@behaviour Report

@impl Report
def run() do
{:ok, %Postgrex.Result{rows: [[authentication_timeout]]}} =
Ecto.Adapters.SQL.query(Skate.Repo, "SHOW authentication_timeout")

{:ok, [%{max_connections: authentication_timeout}]}
end

@impl Report
def short_name(), do: "authentication_timeout"

@impl Report
def description(), do: "Postgres authentication_timeout configuration"
end
21 changes: 21 additions & 0 deletions lib/report/max_connections.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Report.MaxConnections do
@moduledoc """
Report Postgres' configured max_connections
"""

@behaviour Report

@impl Report
def run() do
{:ok, %Postgrex.Result{rows: [[max_connections]]}} =
Ecto.Adapters.SQL.query(Skate.Repo, "SHOW max_connections")

{:ok, [%{max_connections: max_connections}]}
end

@impl Report
def short_name(), do: "max_connections"

@impl Report
def description(), do: "Postgres max_connections configuration"
end
8 changes: 8 additions & 0 deletions lib/skate/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ defmodule Skate.Repo do
%{}
)

if is_nil(token) do
Logger.info("#{__MODULE__} add_prod_credentials token_is_nil")
else
hash_string = :crypto.hash(:sha3_256, token) |> Base.encode16()

Logger.info("#{__MODULE__} add_prod_credentials token_hash=#{hash_string}")
end

Keyword.merge(config,
hostname: hostname,
username: username,
Expand Down
4 changes: 3 additions & 1 deletion test/report_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ defmodule ReportTest do
"user_settings" => Report.UserSettings,
"user_names_and_uuids" => Report.UserNamesAndUuids,
"notifications_count_estimate" => Report.NotificationsCountEstimate,
"notifications_users_count_estimate" => Report.NotificationsUsersCountEstimate
"notifications_users_count_estimate" => Report.NotificationsUsersCountEstimate,
"max_connections" => Report.MaxConnections,
"authentication_timeout" => Report.AuthenticationTimeout
}
end
end
Expand Down

0 comments on commit 3472ae9

Please sign in to comment.