Skip to content

Commit

Permalink
Add link to live dashboard for runtime node (#2754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Aug 19, 2024
1 parent a1a7dfe commit d7cb831
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
9 changes: 9 additions & 0 deletions lib/livebook_web/helpers/html_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ defmodule LivebookWeb.HTMLHelpers do
@doc """
Returns path to specific process dialog within LiveDashboard.
"""
@spec live_dashboard_process_path(pid) :: String.t()
def live_dashboard_process_path(pid) do
pid_str = Phoenix.LiveDashboard.PageBuilder.encode_pid(pid)
~p"/dashboard/#{node()}/processes?info=#{pid_str}"
end

@doc """
Returns path to specific node within LiveDashboard.
"""
@spec live_dashboard_node_path(String.t()) :: String.t()
def live_dashboard_node_path(node) do
~p"/dashboard/#{node}/home"
end

@doc """
Converts human-readable strings to strings which can be used
as HTML element IDs (compatible with HTML5)
Expand Down
1 change: 1 addition & 0 deletions lib/livebook_web/live/session_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ defmodule LivebookWeb.SessionLive do
dirty: data.dirty,
persistence_warnings: data.persistence_warnings,
runtime: data.runtime,
runtime_metadata: Runtime.describe(data.runtime),
runtime_status: data.runtime_status,
runtime_connect_info: data.runtime_connect_info,
runtime_connected_nodes: Enum.sort(data.runtime_connected_nodes),
Expand Down
32 changes: 23 additions & 9 deletions lib/livebook_web/live/session_live/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule LivebookWeb.SessionLive.Render do
import Livebook.Utils, only: [format_bytes: 1]

alias Livebook.Notebook.Cell
alias Livebook.Runtime

def render(assigns) do
~H"""
Expand Down Expand Up @@ -648,11 +647,7 @@ defmodule LivebookWeb.SessionLive.Render do
</div>
<div class="flex flex-col mt-2">
<div class="flex flex-col space-y-3">
<.labeled_text
:for={{label, value} <- Runtime.describe(@data_view.runtime)}
label={label}
one_line
>
<.labeled_text :for={{label, value} <- @data_view.runtime_metadata} label={label} one_line>
<%= value %>
</.labeled_text>
</div>
Expand Down Expand Up @@ -694,7 +689,10 @@ defmodule LivebookWeb.SessionLive.Render do
</.message_box>
</div>
<.memory_usage_info memory_usage={@session.memory_usage} />
<.memory_usage_info
memory_usage={@session.memory_usage}
runtime_metadata={@data_view.runtime_metadata}
/>
<.runtime_connected_nodes_info runtime_connected_nodes={@data_view.runtime_connected_nodes} />
</div>
Expand All @@ -705,8 +703,20 @@ defmodule LivebookWeb.SessionLive.Render do
defp memory_usage_info(assigns) do
~H"""
<div class="mt-8 flex flex-col gap-2">
<div class="text-sm text-gray-500 font-semibold uppercase">
Memory
<div class="flex items-center justify-between">
<div class="text-sm text-gray-500 font-semibold uppercase">
Memory
</div>
<span class="tooltip left" data-tooltip="See on dashboard">
<.icon_button
:if={node = runtime_node(@runtime_metadata)}
href={LivebookWeb.HTMLHelpers.live_dashboard_node_path(node)}
target="_blank"
aria-label="see on dashboard"
>
<.remix_icon icon="dashboard-2-line" />
</.icon_button>
</span>
</div>
<%= if uses_memory?(@memory_usage) do %>
<.runtime_memory_info memory_usage={@memory_usage} />
Expand All @@ -721,6 +731,10 @@ defmodule LivebookWeb.SessionLive.Render do
"""
end

defp runtime_node(runtime_metadata) do
Enum.find_value(runtime_metadata, fn {key, value} -> key == "Node name" && value end)
end

defp runtime_memory_info(assigns) do
assigns = assign(assigns, :runtime_memory, runtime_memory(assigns.memory_usage))

Expand Down

0 comments on commit d7cb831

Please sign in to comment.