-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This prevents memory bloat form creating all intermediate binaries that are later dropped. Instead we try to reuse as much of binaries as possible and then let the VM do the concatenation if needed.
- Loading branch information
Showing
8 changed files
with
192 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.6 | ||
2.1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
defmodule Supavisor.Monitoring.PromExTest do | ||
use Supavisor.DataCase, async: true | ||
use ExUnitProperties | ||
|
||
@subject Supavisor.Monitoring.PromEx | ||
|
||
@tenant "prom_tenant" | ||
|
||
setup do | ||
db_conf = Application.get_env(:supavisor, Repo) | ||
|
||
{:ok, proxy} = | ||
Postgrex.start_link( | ||
hostname: db_conf[:hostname], | ||
port: Application.get_env(:supavisor, :proxy_port_transaction), | ||
database: db_conf[:database], | ||
password: db_conf[:password], | ||
username: db_conf[:username] <> "." <> @tenant, | ||
socket_dir: nil, | ||
show_sensitive_data_on_connection_error: true | ||
) | ||
|
||
assert :idle == DBConnection.status(proxy) | ||
|
||
%{proxy: proxy, user: db_conf[:username], db_name: db_conf[:database]} | ||
end | ||
|
||
describe "get_metrics/1" do | ||
@sources %{ | ||
{:darwin, :aarch64} => { | ||
"https://github.com/prometheus/prom2json/releases/download/v1.4.1/prom2json-1.4.1.darwin-arm64.tar.gz", | ||
"prom2json-1.4.1.darwin-arm64/prom2json" | ||
} | ||
} | ||
setup do | ||
{:ok, prom2json: Supavisor.Downloader.ensure("prom2json", @sources)} | ||
end | ||
|
||
@tag :tmp_dir | ||
test "returned metrics are parseable", %{tmp_dir: dir, prom2json: exe} do | ||
metrics = @subject.get_metrics() | ||
file = Path.join(dir, "prom.out") | ||
File.write!(file, metrics) | ||
|
||
assert {_, 0} = System.cmd(exe, [file]) | ||
end | ||
|
||
@tag :tmp_dir | ||
property "non-standard DB names do not cause parsing issues", %{tmp_dir: dir, prom2json: exe} do | ||
tenant = "tenant" | ||
user = "user" | ||
|
||
check all db_name <- string(:printable, min_length: 1, max_length: 63) do | ||
Supavisor.Monitoring.Telem.client_join( | ||
:ok, | ||
{{:single, tenant}, user, :session, db_name, nil} | ||
) | ||
|
||
metrics = @subject.get_metrics() | ||
file = Path.join(dir, "prom.out") | ||
File.write!(file, metrics) | ||
|
||
assert {out, 0} = System.cmd(exe, [file]) | ||
assert {:ok, measurements} = Jason.decode(out) | ||
|
||
assert %{"metrics" => metrics} = | ||
Enum.find(measurements, &(&1["name"] == "supavisor_client_joins_ok")) | ||
|
||
assert Enum.find(metrics, &(&1["labels"]["db_name"] == db_name)) | ||
end | ||
end | ||
|
||
@tag :tmp_dir | ||
property "non-standard user names do not cause parsing issues", %{ | ||
tmp_dir: dir, | ||
prom2json: exe | ||
} do | ||
tenant = "tenant" | ||
db_name = "db_name" | ||
|
||
check all user <- string(:printable, min_length: 1, max_length: 63) do | ||
Supavisor.Monitoring.Telem.client_join( | ||
:ok, | ||
{{:single, tenant}, user, :session, db_name, nil} | ||
) | ||
|
||
metrics = @subject.get_metrics() | ||
file = Path.join(dir, "prom.out") | ||
File.write!(file, metrics) | ||
|
||
assert {out, 0} = System.cmd(exe, [file]) | ||
assert {:ok, measurements} = Jason.decode(out) | ||
|
||
assert %{"metrics" => metrics} = | ||
Enum.find(measurements, &(&1["name"] == "supavisor_client_joins_ok")) | ||
|
||
assert Enum.find(metrics, &(&1["labels"]["db_name"] == db_name)) | ||
end | ||
end | ||
|
||
@tag :tmp_dir | ||
property "non-standard tenant names do not cause parsing issues", %{tmp_dir: dir} do | ||
db_name = "db_name" | ||
user = "user" | ||
|
||
check all tenant <- string(:printable, min_length: 1) do | ||
Supavisor.Monitoring.Telem.client_join( | ||
:ok, | ||
{{:single, tenant}, user, :session, db_name, nil} | ||
) | ||
|
||
metrics = @subject.get_metrics() | ||
file = Path.join(dir, "prom.out") | ||
File.write!(file, metrics) | ||
|
||
assert {out, 0} = System.cmd("prom2json", [file]) | ||
assert {:ok, measurements} = Jason.decode(out) | ||
|
||
assert %{"metrics" => metrics} = | ||
Enum.find(measurements, &(&1["name"] == "supavisor_client_joins_ok")) | ||
|
||
assert Enum.find(metrics, &(&1["labels"]["db_name"] == db_name)) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule Supavisor.Downloader do | ||
Check warning on line 1 in test/support/downloader.ex
|
||
def ensure(name, sources) do | ||
case System.find_executable(name) do | ||
nil -> do_download(name, sources) | ||
path -> path | ||
end | ||
end | ||
|
||
def do_download(name, sources) do | ||
path = System.tmp_dir!() | ||
arch = os_arch() | ||
|
||
source = | ||
case Map.fetch(sources, arch) do | ||
{:ok, src} -> src | ||
:error -> raise "Cannot find source for #{inspect(arch)}" | ||
end | ||
|
||
{url, file} = | ||
case source do | ||
{url, file} -> {url, file} | ||
url when is_binary(url) -> {url, name} | ||
end | ||
|
||
out = Path.join(path, file) | ||
|
||
if not File.exists?(out) do | ||
%Req.Response{status: 200, body: body} = Req.get!(url) | ||
|
||
:ok = | ||
:erl_tar.extract({:binary, body}, [ | ||
:compressed, | ||
cwd: to_charlist(path), | ||
files: [to_charlist(file)] | ||
]) | ||
end | ||
|
||
out | ||
end | ||
|
||
defp os_arch do | ||
{_, name} = :os.type() | ||
|
||
arch = | ||
:erlang.system_info(:system_architecture) | ||
|> List.to_string() | ||
|> String.split("-", parts: 2) | ||
|> hd() | ||
|> String.to_atom() | ||
|
||
{name, arch} | ||
end | ||
end |