From 798538d949a931f627255d647cf5eb2a7e72378e Mon Sep 17 00:00:00 2001 From: Chase Granberry Date: Mon, 16 Jan 2023 09:14:06 -0700 Subject: [PATCH] feat: footer improvements (#429) * feat: display the count of connected tenants in metrics (#418) * fix: don't try to stop the not alive pid in the resolver (#417) * fix: increase read replica pool size * feat: default realtime-dev JWT secret to API_JWT_SECRET env var value * chore(deps): bump json5 from 1.0.1 to 1.0.2 in /demo Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] * feat: default Repo with_dynamic_repo name to nil and pool_size to 1 (#423) * fix: looks for the PR number after # symbol (#425) * Add defaults to current fields to reflect db schema * Add max_bytes_per_second and max_channels_per_client fields * Add max_joins_per_second to schema * Add db limits to socket * Use db limits in channel * fix: tests * fix: do not block a registration process (#426) * fix: add http checks * feat: stop connection to a tenant's db if there are no connected users for 10 minutes. (#428) * feat: add short_node_id helper * Use new helper in Realtime.PromEx * feat: add version to footer and use short node id Signed-off-by: dependabot[bot] Co-authored-by: abc3 Co-authored-by: Wen Bo Xie Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com> --- lib/realtime/helpers.ex | 29 ++++++++++++------- lib/realtime/monitoring/prom_ex.ex | 12 ++------ .../templates/layout/live.html.heex | 16 +++++----- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/realtime/helpers.ex b/lib/realtime/helpers.ex index 9291e1265..6410f35a3 100644 --- a/lib/realtime/helpers.ex +++ b/lib/realtime/helpers.ex @@ -82,16 +82,6 @@ defmodule Realtime.Helpers do end end - defp pad(data) do - to_add = 16 - rem(byte_size(data), 16) - data <> :binary.copy(<>, to_add) - end - - defp unpad(data) do - to_remove = :binary.last(data) - :binary.part(data, 0, byte_size(data) - to_remove) - end - def decrypt_creds(host, port, name, user, pass) do secure_key = Application.get_env(:realtime, :db_enc_key) @@ -103,4 +93,23 @@ defmodule Realtime.Helpers do decrypt!(pass, secure_key) } end + + def short_node_id() do + fly_alloc_id = Application.get_env(:realtime, :fly_alloc_id) + + case String.split(fly_alloc_id, "-", parts: 2) do + [short_alloc_id, _] -> short_alloc_id + _ -> fly_alloc_id + end + end + + defp pad(data) do + to_add = 16 - rem(byte_size(data), 16) + data <> :binary.copy(<>, to_add) + end + + defp unpad(data) do + to_remove = :binary.last(data) + :binary.part(data, 0, byte_size(data) - to_remove) + end end diff --git a/lib/realtime/monitoring/prom_ex.ex b/lib/realtime/monitoring/prom_ex.ex index 53e44f3d8..8cc27ce0f 100644 --- a/lib/realtime/monitoring/prom_ex.ex +++ b/lib/realtime/monitoring/prom_ex.ex @@ -1,6 +1,8 @@ defmodule Realtime.PromEx do alias Realtime.PromEx.Plugins.{OsMon, Phoenix, Tenants} + import Realtime.Helpers, only: [short_node_id: 0] + @moduledoc """ Be sure to add the following to finish setting up PromEx: @@ -137,18 +139,10 @@ defmodule Realtime.PromEx do def set_metrics_tags() do [_, node_host] = node() |> Atom.to_string() |> String.split("@") - fly_alloc_id = Application.get_env(:realtime, :fly_alloc_id) - - short_alloc_id = - case String.split(fly_alloc_id, "-", parts: 2) do - [short_alloc_id, _] -> short_alloc_id - _ -> fly_alloc_id - end - metrics_tags = %{ region: Application.get_env(:realtime, :fly_region), node_host: node_host, - short_alloc_id: short_alloc_id + short_alloc_id: short_node_id() } Application.put_env(:realtime, :metrics_tags, metrics_tags) diff --git a/lib/realtime_web/templates/layout/live.html.heex b/lib/realtime_web/templates/layout/live.html.heex index d3eda53fd..0de0e29c4 100644 --- a/lib/realtime_web/templates/layout/live.html.heex +++ b/lib/realtime_web/templates/layout/live.html.heex @@ -41,12 +41,14 @@ \ No newline at end of file +