diff --git a/VERSION b/VERSION index 2733a3e7..4f53b327 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.58 +1.1.59 diff --git a/lib/supavisor/monitoring/prom_ex.ex b/lib/supavisor/monitoring/prom_ex.ex index 72f92f9a..96a0eff3 100644 --- a/lib/supavisor/monitoring/prom_ex.ex +++ b/lib/supavisor/monitoring/prom_ex.ex @@ -125,6 +125,8 @@ defmodule Supavisor.Monitoring.PromEx do line [_, key, tags, value] -> + tags = clean_string(tags) + tags = if tags == "" do def_tags @@ -135,4 +137,24 @@ defmodule Supavisor.Monitoring.PromEx do "#{key}{#{tags}} #{value}" end end + + @spec clean_string(String.t()) :: String.t() + def clean_string(metric_string) do + regex = ~r/=\s*"([^"]*?)"/ + + String.replace(metric_string, regex, fn match -> + [_, value] = Regex.run(regex, match) + + cleaned = + value + |> String.replace(~r/\n+/, "") + |> String.trim() + + if value != cleaned do + Logger.error("Tag validation: #{inspect(value)} / #{inspect(cleaned)}") + end + + "=\"#{cleaned}\"" + end) + end end diff --git a/test/supavisor/prom_ex_test.exs b/test/supavisor/prom_ex_test.exs index 8bea1742..d29dc23c 100644 --- a/test/supavisor/prom_ex_test.exs +++ b/test/supavisor/prom_ex_test.exs @@ -35,4 +35,14 @@ defmodule Supavisor.PromExTest do refute PromEx.get_metrics() =~ "tenant=\"#{@tenant}\"" end + + test "clean_string/1 removes extra spaces from metric string" do + input = + "db_name=\"postgres \",mode=\" transaction\",tenant=\"dev_tenant \n\",type=\"\n single\",user=\"\npostgres\n\"" + + expected_output = + "db_name=\"postgres\",mode=\"transaction\",tenant=\"dev_tenant\",type=\"single\",user=\"postgres\"" + + assert expected_output == PromEx.clean_string(input) + end end