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

Add support for filtering devices on alarms #1628

Merged
merged 9 commits into from
Nov 14, 2024

Conversation

elinol
Copy link
Contributor

@elinol elinol commented Nov 1, 2024

Adds filtering support for:

  • Devices with alarms / without alarms
  • Devices with specific alarms (list with current alarm types for product)

Also adds alarm counter on product dashboard with link to filtered devices list.

query_current_alarms(product_id)
|> Repo.all()
|> Enum.map(fn %{data: data} ->
Map.keys(data["alarms"])
Copy link
Contributor Author

@elinol elinol Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in this format: Elixir.NervesHubHealth.HealthCheckFailed
We could make them more human friendly perhaps?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using inspect/1 on the alarm name will pretty print without Elixir. - We could also add a helper in DeviceHealth.save/1 to preemptively adjust/cast :alarms keys into the prettier format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we also remove NervesHubHealth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's Elixir.NervesHubHealth.HealthCheckFailed actually so solved it by splitting on dots and using the last item.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be more alarms in the future? We have lots of alarms not explicitly scoped to NervesHubHealth. I'm not sure if that's the only thing expected to be reported here though the name alarms seems to suggest it might

Copy link
Contributor Author

@elinol elinol Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand the alarm functionality will be built out, and separated into it's own context/db table. This function will need an update then :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NervesHubHealth came from the separate library that we won't be shipping. We can go forward with whatever naming we prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with using inspect/1 to get it without the Elixir prefix :)

@elinol
Copy link
Contributor Author

elinol commented Nov 1, 2024

Looks alright in dropdown selector:
image

But not when selected:
image

Worth it to fix now or wait for UI update?

@fhunleth
Copy link
Contributor

fhunleth commented Nov 1, 2024

Does trimming the Elixir. help with fitting? I don't think we want it anyway.

Also, I really like this feature. I'm quite excited about using it.

lib/nerves_hub/devices/alarms.ex Outdated Show resolved Hide resolved
lib/nerves_hub/devices/alarms.ex Outdated Show resolved Hide resolved
query_current_alarms(product_id)
|> Repo.all()
|> Enum.map(fn %{data: data} ->
Map.keys(data["alarms"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we also remove NervesHubHealth?

"""
def query_devices_with_alarms() do
(lr in subquery(latest_row_query()))
|> from()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this from() needed?

Copy link
Contributor Author

@elinol elinol Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise the lr variable is undefined according to compiling errors. It's something with starting the pipes with this lr in.. that I don't like.. that's why the queries aren't pipe-only. But I get why you want them all to be in the same format

Selects latest health per device if alarms is populated and device belongs to product.
"""
def query_current_alarms(product_id) do
from(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please switch these to pipe queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can! I found this way easier to follow somehow

Copy link
Collaborator

@joshk joshk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a solid step forward!

@lawik
Copy link
Contributor

lawik commented Nov 12, 2024

So the NervesHubHealth prefix for the alarm is entirely up to the thing making the alarm. We can decide if we want a different convention in the default alarms for NervesHubLink as we won't be shipping the NervesHubHealth library. It got folded into NervesHubLink's features implementation.

@elinol
Copy link
Contributor Author

elinol commented Nov 12, 2024

image

Copy link
Collaborator

@joshk joshk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Some of the Ecto bits are bending my brain, but I think we can try this out in prod and improve from there.

@elinol
Copy link
Contributor Author

elinol commented Nov 14, 2024

@joshk this should be ready now!

@joshk joshk merged commit 80dd9e9 into nerves-hub:main Nov 14, 2024
2 checks passed
@joshk
Copy link
Collaborator

joshk commented Nov 14, 2024

Awesome work @elinol !

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.

5 participants