Skip to content

Commit

Permalink
feat: footer improvements (#429)
Browse files Browse the repository at this point in the history
* 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](json5/json5@v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* 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] <support@github.com>
Co-authored-by: abc3 <sts@abc3.dev>
Co-authored-by: Wen Bo Xie <wenbo.xie3@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com>
  • Loading branch information
5 people committed Jan 16, 2023
1 parent 4791803 commit 798538d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
29 changes: 19 additions & 10 deletions lib/realtime/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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>>, 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)

Expand All @@ -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>>, to_add)
end

defp unpad(data) do
to_remove = :binary.last(data)
:binary.part(data, 0, byte_size(data) - to_remove)
end
end
12 changes: 3 additions & 9 deletions lib/realtime/monitoring/prom_ex.ex
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions lib/realtime_web/templates/layout/live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
</div>
</main>
<footer class="fixed bottom-0 left-0 z-20 p-4 w-full bg-white border-t border-zinc-100 md:flex md:items-center md:justify-between md:p-6">
<span class="text-sm text-gray-900 sm:text-center">© <a href="https://supabase.com/" class="hover:underline">Supabase Inc</a>
</span>
<ul class="flex flex-wrap items-center mt-3 text-sm text-gray-900 sm:mt-0">
<li><span class="mr-4 md:mr-6">Apache 2.0 License</span></li>
<li><span class="font-mono mr-4 md:mr-6"><%= Node.self() %></span></li>
<li><span class="font-mono mr-4 md:mr-6"><%= System.get_env("FLY_REGION") %></span></li>
<div>
<span class="font-mono mr-4 text-sm text-gray-900 sm:text-center">v<%= Mix.Project.config[:version] %></span>
<span class="text-sm text-gray-900 sm:text-center">© <a href="https://supabase.com/" class="hover:underline">Supabase Inc</a></span>
</div>
<ul class="flex flex-wrap items-center mt-3 text-sm text-gray-900">
<li><span class="mr-4">Apache 2.0 License</span></li>
<li><span class="font-mono mr-4"><%= Realtime.Helpers.short_node_id() %></span></li>
<li><span class="font-mono mr-4"><%= System.get_env("FLY_REGION") %></span></li>
<li><%= live_render(@socket, RealtimeWeb.PingLive, id: "ping") %></li>
</ul>
</footer>
</footer>

0 comments on commit 798538d

Please sign in to comment.