Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

elinol
Copy link

@elinol elinol commented Jan 7, 2025

No description provided.

@elinol elinol force-pushed the use-alarmist-in-default-health-report branch from 4425a10 to afe5c89 Compare January 7, 2025 10:57
@elinol elinol marked this pull request as ready for review January 7, 2025 16:21
Comment on lines 27 to 41
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
Copy link
Author

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?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

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

@elinol elinol requested a review from lawik January 23, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants