Skip to content

Conversation

@thampiotr
Copy link
Contributor

@thampiotr thampiotr commented Aug 1, 2025

I have encountered an issue that is blocking me from upgrading Prometheus to 3.x where despite receiving a content type header of "application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores" I get . in metric and label names.

I've noticed there is possibly a missing call to EscapeMetricFamily for delimited proto.

I also noticed the test TestEscapedEncode did not assert that actual escaping is done, so fixed that too.

@thampiotr thampiotr force-pushed the fix-escape-delim-proto branch from 5dc7746 to d57ec2e Compare August 1, 2025 13:20
@thampiotr thampiotr force-pushed the fix-escape-delim-proto branch 3 times, most recently from 986af83 to 61b386b Compare August 1, 2025 13:27
@ywwg ywwg requested review from bwplotka and ywwg August 1, 2025 14:22
Comment on lines 339 to 344
verifyCorrectlyEscaped := func(t *testing.T, out string, format Format) {
require.NotContainsf(t, out, `"foo.metric"`, "format incorrectly escaped: %s", format)
require.Containsf(t, out, `foo_metric`, "format incorrectly escaped: %s", format)
require.NotContainsf(t, out, `"dotted.label.name"`, "format incorrectly escaped: %s", format)
require.Containsf(t, out, `dotted_label_name`, "format incorrectly escaped: %s", format)
require.Containsf(t, out, `my.label.value`, "format incorrectly escaped: %s", format)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we test the actual output (parsed proto, etc) instead of grepping the strings, but this is ok for now. Can you add a todo to make the test more robust? We will also want to test the other escaping methods, round tripping, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can convert this into a table test and verify the entire output if that works :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the tests, PTAL.

@thampiotr thampiotr force-pushed the fix-escape-delim-proto branch 2 times, most recently from 35ae92a to 3976c4e Compare August 1, 2025 15:34
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ywwg
Copy link
Member

ywwg commented Aug 1, 2025

I was getting this weird tab/space problem when I was working on my own PR and could not figure out where it was coming from. I ended up just changing the test to not get tripped up on it. I think there is some bizarre nondeterminism in the prototext output

Copy link
Member

@ywwg ywwg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks!

Signed-off-by: Piotr <17101802+thampiotr@users.noreply.github.com>
@thampiotr thampiotr force-pushed the fix-escape-delim-proto branch from 3976c4e to 96a9730 Compare August 4, 2025 11:23
@thampiotr
Copy link
Contributor Author

I was getting this weird tab/space problem when I was working on my own PR and could not figure out where it was coming from. I ended up just changing the test to not get tripped up on it. I think there is some bizarre nondeterminism in the prototext output

The protobuf text representation is intentionally nondeterministic as per protocolbuffers/protobuf-go@582ab3d, there is some context and workarounds here: golang/protobuf#1082

In case of this one test, we're really interested in escaping, so I can achieve this by looking at strings in the output, which I reverted to now.

More broadly the common module may want to have a strategy for verifying stability of the outputs. The issue linked above has some workarounds that could be used, but this is out of scope of this PR.

@ywwg ywwg merged commit 0ad974f into prometheus:main Aug 4, 2025
8 checks passed
@ywwg
Copy link
Member

ywwg commented Aug 4, 2025

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.

3 participants