Skip to content

Commit

Permalink
Fix diagnose null index check (#35)
Browse files Browse the repository at this point in the history
* Remove leading zeros from null_frac

* Log diagnose error

* Update test
  • Loading branch information
ericmj committed Nov 23, 2022
1 parent 45a4907 commit c297712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions lib/ecto_psql_extras/diagnose_logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule EctoPSQLExtras.DiagnoseLogic do
Diagnose report logic
"""

require Logger

@table_cache_hit_min_expected 0.985
@index_cache_hit_min_expected "0.985"
@unused_indexes_max_scans 20
Expand All @@ -27,12 +29,15 @@ defmodule EctoPSQLExtras.DiagnoseLogic do
ssl_used(repo),
]
}
rescue
_ ->
catch
kind, error ->
stacktrace = System.stacktrace()
Logger.warn("#{__MODULE__}\n#{Exception.format(kind, error, stacktrace)}")

%{
columns: ["ok", "check_name", "message"],
rows: [
[false, "diagnose_error", "There was an error when generating your diagnose report"]
[false, "diagnose_error", "There was an error when generating your diagnose report, see logs"]
]
}
end
Expand Down Expand Up @@ -109,10 +114,10 @@ defmodule EctoPSQLExtras.DiagnoseLogic do
args: [min_relation_size_mb: @null_indexes_min_size_mb]
).rows
|> Enum.filter(fn(el) ->
null_frac = Enum.at(el, 4)
{null_frac, ""} = Enum.at(el, 5)
|> String.replace("%", "")
|> String.trim_leading
|> Float.parse
|> elem(0)
null_frac > @null_min_null_frac_percent
end)

Expand Down
6 changes: 3 additions & 3 deletions test/diagnose_logic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ defmodule DiagnoseLogicTest do
messages: [],
num_rows: 0,
rows: [
["123", "index_plans_on_payer_id", "16 MB", true, "00.00%", "0 kb"],
["321", "index_feedbacks_on_target_id", "80 kB", false, "97.00%", "77 kb"],
["231", "index_channels_on_slack_id", "56 MB", true, "49.99%", "28 MB"]
["123", "index_plans_on_payer_id", "16 MB", true, "payer_id", " 0.00%", "0 kb"],
["321", "index_feedbacks_on_target_id", "80 kB", false, "target_id", "97.00%", "77 kb"],
["231", "index_channels_on_slack_id", "56 MB", true, "slack_id", "49.99%", "28 MB"]
]
}
end,
Expand Down

0 comments on commit c297712

Please sign in to comment.