Skip to content

Commit

Permalink
Change the default escape method to UnderscoreEscaping
Browse files Browse the repository at this point in the history
fixes #689

Signed-off-by: Owen Williams <[email protected]>
  • Loading branch information
ywwg committed Sep 4, 2024
1 parent 4f8e8f4 commit 01da226
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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
// 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

0 comments on commit 01da226

Please sign in to comment.