Set allow-utf-8 in Format during tests to avoid escaping.

For https://github.com/open-telemetry/opentelemetry-go/pull/5755

Signed-off-by: Owen Williams <owen.williams@grafana.com>
This commit is contained in:
Owen Williams 2024-09-04 12:13:01 -04:00
parent 89f21b2cba
commit 4d20de5bfa
4 changed files with 35 additions and 30 deletions

8
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/klauspost/compress v1.17.9 github.com/klauspost/compress v1.17.9
github.com/kylelemons/godebug v1.1.0 github.com/kylelemons/godebug v1.1.0
github.com/prometheus/client_model v0.6.1 github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.57.0 github.com/prometheus/common v0.59.1
github.com/prometheus/procfs v0.15.1 github.com/prometheus/procfs v0.15.1
golang.org/x/sys v0.24.0 golang.org/x/sys v0.24.0
google.golang.org/protobuf v1.34.2 google.golang.org/protobuf v1.34.2
@ -23,9 +23,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
golang.org/x/net v0.27.0 // indirect golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.17.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )

16
go.sum
View File

@ -37,6 +37,10 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY= github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY=
github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI= github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI=
github.com/prometheus/common v0.59.0 h1:o2eVCLbhf3sgisnD5e0/twUt25r8gNmMHNzTOAuY9bs=
github.com/prometheus/common v0.59.0/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
@ -46,14 +50,14 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -361,7 +361,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: []byte{}, body: []byte{},
}, },
@ -372,7 +372,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: []byte{}, body: []byte{},
}, },
@ -383,7 +383,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: []byte{}, body: []byte{},
}, },
@ -394,7 +394,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
}, },
body: []byte{}, body: []byte{},
}, },
@ -405,7 +405,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: expectedMetricFamilyAsText, body: expectedMetricFamilyAsText,
}, },
@ -417,7 +417,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
}, },
body: expectedMetricFamilyAsBytes, body: expectedMetricFamilyAsBytes,
}, },
@ -429,7 +429,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: externalMetricFamilyAsText, body: externalMetricFamilyAsText,
}, },
@ -441,7 +441,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
}, },
body: externalMetricFamilyAsBytes, body: externalMetricFamilyAsBytes,
}, },
@ -453,7 +453,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -472,7 +472,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: []byte{}, body: []byte{},
}, },
@ -483,7 +483,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: expectedMetricFamilyAsText, body: expectedMetricFamilyAsText,
}, },
@ -495,7 +495,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -514,7 +514,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -533,7 +533,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -552,7 +552,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -571,7 +571,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`, "Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{
@ -609,7 +609,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: expectedMetricFamilyAsText, body: expectedMetricFamilyAsText,
}, },
@ -666,7 +666,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
}, },
out: output{ out: output{
headers: map[string]string{ headers: map[string]string{
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`, "Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
}, },
body: bytes.Join( body: bytes.Join(
[][]byte{ [][]byte{

View File

@ -47,6 +47,7 @@ import (
"github.com/kylelemons/godebug/diff" "github.com/kylelemons/godebug/diff"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
"github.com/prometheus/common/model"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -298,13 +299,13 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
// result. // result.
func compare(got, want []*dto.MetricFamily) error { func compare(got, want []*dto.MetricFamily) error {
var gotBuf, wantBuf bytes.Buffer var gotBuf, wantBuf bytes.Buffer
enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain)) enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain).WithEscapingScheme(model.NoEscaping))
for _, mf := range got { for _, mf := range got {
if err := enc.Encode(mf); err != nil { if err := enc.Encode(mf); err != nil {
return fmt.Errorf("encoding gathered metrics failed: %w", err) return fmt.Errorf("encoding gathered metrics failed: %w", err)
} }
} }
enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain)) enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain).WithEscapingScheme(model.NoEscaping))
for _, mf := range want { for _, mf := range want {
if err := enc.Encode(mf); err != nil { if err := enc.Encode(mf); err != nil {
return fmt.Errorf("encoding expected metrics failed: %w", err) return fmt.Errorf("encoding expected metrics failed: %w", err)