Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect recursive calls when escaping labels' values #30

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

hauleth
Copy link
Contributor

@hauleth hauleth commented Jan 28, 2025

Closes #29

Co-authored-by: Stanislav Muzhyk [email protected]

@hauleth
Copy link
Contributor Author

hauleth commented Jan 28, 2025

cc @abc3 @chasers

@rkallos
Copy link
Owner

rkallos commented Jan 30, 2025

Nice!

I wrote up a regression test, but I'm not sure how to add it to the PR: I don't think I can commit and push to your fork.

diff --git a/test/prometheus_test.exs b/test/prometheus_test.exs
index f384257..f0c6f66 100644
--- a/test/prometheus_test.exs
+++ b/test/prometheus_test.exs
@@ -364,6 +364,38 @@ defmodule PrometheusTest do
 
       assert export(name) == lines_to_string(expected)
     end
+
+    test "#{impl} - regression: label escaping" do
+      name = StorageCounter.fresh_id()
+
+      counter =
+        Metrics.counter(
+          "prometheus.test.counter",
+          description: "a counter"
+        )
+
+      opts = [
+        name: name,
+        metrics: [counter],
+        storage: unquote(impl)
+      ]
+
+      {:ok, _pid} = Peep.start_link(opts)
+
+      Peep.insert_metric(name, counter, 1, %{atom: "\"string\""})
+      Peep.insert_metric(name, counter, 1, %{"\"string\"" => :atom})
+      Peep.insert_metric(name, counter, 1, %{"\"string\"" => "\"string\""})
+
+      expected = [
+        "# HELP prometheus_test_counter a counter",
+        "# TYPE prometheus_test_counter counter",
+        ~s(prometheus_test_counter{atom="\\\"string\\\""} 1),
+        ~s(prometheus_test_counter{\"string\"="atom"} 1),
+        ~s(prometheus_test_counter{\"string\"="\\\"string\\\""} 1)
+      ]
+
+      assert export(name) == lines_to_string(expected)
+    end
   end
 
   defp export(name) do

@hauleth
Copy link
Contributor Author

hauleth commented Jan 30, 2025

I will apply it tomorrow

@hauleth hauleth force-pushed the incorrect-label-escaping branch from 94dd35d to 593eb7f Compare January 31, 2025 11:13
@hauleth
Copy link
Contributor Author

hauleth commented Jan 31, 2025

Applied

@rkallos
Copy link
Owner

rkallos commented Jan 31, 2025

Thank you! <3

@rkallos rkallos merged commit 7eee3a6 into rkallos:main Jan 31, 2025
1 check passed
@hauleth hauleth deleted the incorrect-label-escaping branch January 31, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants