Skip to content

Commit

Permalink
Ignore empty metrics map in health report (#1694)
Browse files Browse the repository at this point in the history
Solves #1662.

Also, the deprecated broadcast topic for health checks is replaced with the correct one.
  • Loading branch information
elinol authored Dec 17, 2024
1 parent 8616309 commit 3057064
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/nerves_hub/devices/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ defmodule NervesHub.Devices.Metrics do
@doc """
Saves map of metrics.
"""
def save_metrics(_device_id, metrics) when metrics == %{}, do: {:ok, 0}

def save_metrics(device_id, metrics) do
entries =
Enum.map(metrics, fn {key, val} ->
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/devices/device_health.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ defmodule NervesHubWeb.Live.Devices.DeviceHealth do
timer_ref = Process.send_after(self(), :check_health_interval, @check_health_interval)

topic = "device:#{socket.assigns.device.id}:extensions"
NervesHubWeb.DeviceEndpoint.broadcast(topic, "health:check", %{})
socket.endpoint.broadcast(topic, "health:check", %{})

socket
|> assign(:health_check_timer, timer_ref)
Expand Down
7 changes: 5 additions & 2 deletions lib/nerves_hub_web/live/devices/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ defmodule NervesHubWeb.Live.Devices.Show do
def handle_info(:check_health_interval, socket) do
timer_ref = Process.send_after(self(), :check_health_interval, 65_000)

socket.endpoint.broadcast("device:#{socket.assigns.device.id}", "check_health", %{})
topic = "device:#{socket.assigns.device.id}:extensions"
socket.endpoint.broadcast(topic, "health:check", %{})

{:noreply, assign(socket, :health_check_timer, timer_ref)}
socket
|> assign(:health_check_timer, timer_ref)
|> noreply()
end

def handle_info(%Broadcast{event: "location:updated"}, socket) do
Expand Down

0 comments on commit 3057064

Please sign in to comment.