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

Change the default escape method to UnderscoreEscaping #690

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions expfmt/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func TestEscapedEncode(t *testing.T) {
t.Errorf("expected the output bytes buffer to be non-empty")
}

expected := `# TYPE U__foo_2e_metric untyped
U__foo_2e_metric 1.234
U__foo_2e_metric{U__dotted_2e_label_2e_name="my.label.value"} 8
expected := `# TYPE foo_metric untyped
foo_metric 1.234
foo_metric{dotted_label_name="my.label.value"} 8
`

if string(out) != expected {
Expand Down
6 changes: 3 additions & 3 deletions expfmt/expfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func TestToEscapingScheme(t *testing.T) {
}{
{
format: FmtProtoCompact,
expected: model.ValueEncodingEscaping,
expected: model.UnderscoreEscaping,
},
{
format: "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=underscores",
expected: model.UnderscoreEscaping,
format: "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=dots",
expected: model.DotsEscaping,
},
{
format: "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=allow-utf-8",
Expand Down
11 changes: 7 additions & 4 deletions model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ var (
// goroutines are started.
NameValidationScheme = LegacyValidation

// NameEscapingScheme defines the default way that names will be
// escaped when presented to systems that do not support UTF-8 names. If the
// Content-Type "escaping" term is specified, that will override this value.
NameEscapingScheme = ValueEncodingEscaping
// NameEscapingScheme defines the default way that names will be escaped when
// presented to systems that do not support UTF-8 names. If the Content-Type
// "escaping" term is specified, that will override this value.
// NameEscapingScheme should not be set to the NoEscaping value. That string
Copy link
Member Author

Choose a reason for hiding this comment

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

@dashpole Hopefully this is clearer than before

Copy link

Choose a reason for hiding this comment

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

Yep, that is helpful. Thanks!

// is used in content negotiation to indicate that a system supports UTF-8 and
// has that feature enabled.
NameEscapingScheme = UnderscoreEscaping
)

// ValidationScheme is a Go enum for determining how metric and label names will
Expand Down