Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ defmodule Observer.Web.Layouts do
defp asset_path(conn, asset) when asset in [:css, :js] do
hash = Assets.current_hash(asset)

# prefix = conn.private.phoenix_router.__live_dashboard_prefix__()
prefix = "/observer"
{_dash, _routing, meta} = conn.private.phoenix_live_view

prefix = get_in(meta, [:extra, :session, Access.elem(2), Access.at(0)])

Phoenix.VerifiedRoutes.unverified_path(
conn,
Expand All @@ -25,9 +26,12 @@ defmodule Observer.Web.Layouts do
)
end

attr :params, :map, required: true
attr :path, :string, default: nil

def logo(assigns) do
~H"""
<a href={observer_path(:tracing, @params)} class="flex" title="Observer Web">
<a href={@path || observer_path(:tracing, @params)} class="flex" title="Observer Web">
<div>
<Icons.content name={:logo} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/layouts/live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<.flash :if={Phoenix.Flash.get(@flash, :error)} kind={:error} flash={@flash} />
<header class="flex items-center mb-2">
<div class="md:w-84 mr-3">
<.logo params={@params} />
<.logo path={@logo_path} params={@params} />
</div>

<.nav socket={@socket} page={@page.name} params={@params} />
Expand Down
7 changes: 7 additions & 0 deletions lib/web/components/metrics/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ defmodule Observer.Web.Components.Metrics.Common do
|> DateTime.from_unix!(:millisecond)
|> DateTime.to_string()
end

def data_from_streams(inserts) do
Enum.map(inserts, fn
{_id, _index, data, _} -> data
{_id, _index, data, _, _} -> data
end)
end
end
2 changes: 1 addition & 1 deletion lib/web/components/metrics/phx_lv_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Observer.Web.Components.Metrics.PhxLvSocket do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/metrics/vm_limits.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Observer.Web.Components.Metrics.VmLimits do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/metrics/vm_memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Observer.Web.Components.Metrics.VmMemory do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/metrics/vm_port_memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Observer.Web.Components.Metrics.VmPortMemory do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/metrics/vm_process_memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Observer.Web.Components.Metrics.VmProcessMemory do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
2 changes: 1 addition & 1 deletion lib/web/components/metrics/vm_run_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Observer.Web.Components.Metrics.VmRunQueue do
</div>
</div>

<% metrics = Enum.map(@metrics.inserts, fn {_id, _index, data, _} -> data end) %>
<% metrics = Common.data_from_streams(@metrics.inserts) %>
<% normalized_metrics = normalize(metrics) %>
<% echart_config = config(normalized_metrics) %>

Expand Down
3 changes: 2 additions & 1 deletion lib/web/live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Observer.Web.IndexLive do
%{"prefix" => prefix, "resolver" => resolver} = session
%{"live_path" => live_path, "live_transport" => live_transport} = session
%{"user" => user, "access" => access, "csp_nonces" => csp_nonces} = session
%{"logo_path" => logo_path} = session

page = resolve_page(params)
theme = restore_state(socket, "theme", "system")
Expand All @@ -28,7 +29,7 @@ defmodule Observer.Web.IndexLive do
socket =
socket
|> assign(params: params, page: page)
|> assign(live_path: live_path, live_transport: live_transport)
|> assign(live_path: live_path, live_transport: live_transport, logo_path: logo_path)
|> assign(access: access, csp_nonces: csp_nonces, resolver: resolver, user: user)
|> assign(theme: theme, version: version)
|> page.comp.handle_mount()
Expand Down
6 changes: 4 additions & 2 deletions lib/web/pages/tracing/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ defmodule Observer.Web.Tracing.Page do
attention_msg = ~H"""
Incorrect use of the <b>:dbg</b>
tracer in production can lead to performance degradation, latency and crashes.
<b>Observer Web tracing</b> enforces limits on the maximum number of messages and applies a timeout (in seconds)
<b>Observer Web tracing</b>
enforces limits on the maximum number of messages and applies a timeout (in seconds)
to ensure the debugger doesn't remain active unintentionally. Check out the
<a
href="https://www.erlang.org/docs/24/man/dbg"
class="font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline"
>
Erlang Debugger
</a> for more detailed information.
</a>
for more detailed information.
"""

assigns =
Expand Down
26 changes: 20 additions & 6 deletions lib/web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ defmodule Observer.Web.Router do

* `:as` — override the route name; otherwise defaults to `:observer_dashboard`

* `:csp_nonce_assign_key` — CSP (Content Security Policy) keys used to authenticate image,
style, and script assets by pulling a generated nonce out of the connection's `assigns` map. May
be `nil`, a single atom, or a map of atoms. Defaults to `nil`.

* `:logo_path` — a custom path for the logo link in the header, allowing the logo to link to
another page in your application instead of the Oban dashboard root. Defaults to the jobs page.

* `:on_mount` — declares additional module callbacks to be invoked when the dashboard mounts

* `:observer_name` — name of the Observer instance the dashboard will use for configuration and
Expand All @@ -157,10 +164,6 @@ defmodule Observer.Web.Router do
* `:transport` — a phoenix socket transport, either `"websocket"` or `"longpoll"`, defaults to
`"websocket"`.

* `:csp_nonce_assign_key` — CSP (Content Security Policy) keys used to authenticate image,
style, and script assets by pulling a generated nonce out of the connection's `assigns` map. May
be `nil`, a single atom, or a map of atoms. Defaults to `nil`.

## Examples

Mount an `observer` dashboard at the path "/observer":
Expand Down Expand Up @@ -227,7 +230,8 @@ defmodule Observer.Web.Router do
opts[:resolver],
opts[:socket_path],
opts[:transport],
opts[:csp_nonce_assign_key]
opts[:csp_nonce_assign_key],
opts[:logo_path]
]

session_opts = [
Expand All @@ -242,7 +246,7 @@ defmodule Observer.Web.Router do
end

@doc false
def __session__(conn, prefix, observer, resolver, live_path, live_transport, csp_key) do
def __session__(conn, prefix, observer, resolver, live_path, live_transport, csp_key, logo_path) do
user = Resolver.call_with_fallback(resolver, :resolve_user, [conn])

csp_keys = expand_csp_nonce_keys(csp_key)
Expand All @@ -255,6 +259,7 @@ defmodule Observer.Web.Router do
"access" => Resolver.call_with_fallback(resolver, :resolve_access, [user]),
"live_path" => live_path,
"live_transport" => live_transport,
"logo_path" => logo_path,
"csp_nonces" => %{
img: conn.assigns[csp_keys[:img]],
style: conn.assigns[csp_keys[:style]],
Expand All @@ -276,6 +281,15 @@ defmodule Observer.Web.Router do
end
end

defp validate_opt!({:logo_path, path}) do
unless is_nil(path) or (is_binary(path) and byte_size(path) > 0) do
raise ArgumentError, """
invalid :logo_path, expected nil or a non-empty binary path,
got: #{inspect(path)}
"""
end
end

defp validate_opt!({:observer_name, name}) do
unless is_atom(name) do
raise ArgumentError, """
Expand Down
2 changes: 2 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule ObserverWeb.MixProject do
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
listeners: [Phoenix.CodeReloader],
package: package(),
docs: docs(),
deps: deps(),
Expand Down Expand Up @@ -135,6 +136,7 @@ defmodule ObserverWeb.MixProject do
{:mix_audit, "~> 2.1", only: [:dev, :test], runtime: false},
{:mock, "~> 0.3.0", only: :test},
{:igniter, "~> 0.5", only: [:dev, :test]},
{:lazy_html, ">= 0.1.0", only: :test},

# Docs and Publishing
{:ex_doc, "~> 0.34", only: [:dev, :test], runtime: false},
Expand Down
Loading