-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Alarmist for current alarms in default health report #263
base: main
Are you sure you want to change the base?
Use Alarmist for current alarms in default health report #263
Conversation
4425a10
to
afe5c89
Compare
try do | ||
module = String.to_existing_atom("Elixir.Alarmist") | ||
alarms = apply(module, :get_alarms, []) | ||
|
||
for {id, description} <- alarms, into: %{} do | ||
try do | ||
{inspect(id), inspect(description)} | ||
catch | ||
_, _ -> | ||
{"bad alarm term", ""} | ||
end | ||
end | ||
rescue | ||
_ -> %{} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like these nested try
, have to cover for cases when Alarmist
is not available. Any other takes on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this is better:
@impl Report
def alarms() do
# Currently, only Alarmist is supported as alarm handler.
# Send empty map if Alarmist isn't loaded.
alarms =
try do
apply(Alarmist, :get_alarms)
rescue
_ -> %{}
end
for {id, description} <- alarms, into: %{} do
try do
{inspect(id), inspect(description)}
catch
_, _ ->
{"bad alarm term", ""}
end
end
end
Credo is complaining on using apply
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use some compile-time power here:
if Code.ensure_loaded?(Alarmist) do
def alarms() do
# .. the things
end
else
def alarms() do
%{}
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'll give it a try
No description provided.