Skip to content

Commit c29b986

Browse files
authored
Merge pull request #1618 from prometheus/owilliams/utf8-testing
Set allow-utf-8 in Format during tests to avoid escaping.
2 parents 89f21b2 + 4d20de5 commit c29b986

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

Diff for: go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/klauspost/compress v1.17.9
1111
github.com/kylelemons/godebug v1.1.0
1212
github.com/prometheus/client_model v0.6.1
13-
github.com/prometheus/common v0.57.0
13+
github.com/prometheus/common v0.59.1
1414
github.com/prometheus/procfs v0.15.1
1515
golang.org/x/sys v0.24.0
1616
google.golang.org/protobuf v1.34.2
@@ -23,9 +23,9 @@ require (
2323
github.com/modern-go/reflect2 v1.0.2 // indirect
2424
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2525
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
26-
golang.org/x/net v0.27.0 // indirect
27-
golang.org/x/oauth2 v0.21.0 // indirect
28-
golang.org/x/text v0.16.0 // indirect
26+
golang.org/x/net v0.28.0 // indirect
27+
golang.org/x/oauth2 v0.22.0 // indirect
28+
golang.org/x/text v0.17.0 // indirect
2929
gopkg.in/yaml.v2 v2.4.0 // indirect
3030
)
3131

Diff for: go.sum

+10-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p
3737
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
3838
github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY=
3939
github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI=
40+
github.com/prometheus/common v0.59.0 h1:o2eVCLbhf3sgisnD5e0/twUt25r8gNmMHNzTOAuY9bs=
41+
github.com/prometheus/common v0.59.0/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
42+
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
43+
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
4044
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
4145
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
4246
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+
4650
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4751
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4852
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
49-
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
50-
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
51-
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
52-
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
53+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
54+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
55+
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
56+
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
5357
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
5458
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
55-
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
56-
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
59+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
60+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
5761
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
5862
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
5963
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

Diff for: prometheus/registry_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
361361
},
362362
out: output{
363363
headers: map[string]string{
364-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
364+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
365365
},
366366
body: []byte{},
367367
},
@@ -372,7 +372,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
372372
},
373373
out: output{
374374
headers: map[string]string{
375-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
375+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
376376
},
377377
body: []byte{},
378378
},
@@ -383,7 +383,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
383383
},
384384
out: output{
385385
headers: map[string]string{
386-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
386+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
387387
},
388388
body: []byte{},
389389
},
@@ -394,7 +394,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
394394
},
395395
out: output{
396396
headers: map[string]string{
397-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
397+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
398398
},
399399
body: []byte{},
400400
},
@@ -405,7 +405,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
405405
},
406406
out: output{
407407
headers: map[string]string{
408-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
408+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
409409
},
410410
body: expectedMetricFamilyAsText,
411411
},
@@ -417,7 +417,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
417417
},
418418
out: output{
419419
headers: map[string]string{
420-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
420+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
421421
},
422422
body: expectedMetricFamilyAsBytes,
423423
},
@@ -429,7 +429,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
429429
},
430430
out: output{
431431
headers: map[string]string{
432-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
432+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
433433
},
434434
body: externalMetricFamilyAsText,
435435
},
@@ -441,7 +441,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
441441
},
442442
out: output{
443443
headers: map[string]string{
444-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
444+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
445445
},
446446
body: externalMetricFamilyAsBytes,
447447
},
@@ -453,7 +453,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
453453
},
454454
out: output{
455455
headers: map[string]string{
456-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
456+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
457457
},
458458
body: bytes.Join(
459459
[][]byte{
@@ -472,7 +472,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
472472
},
473473
out: output{
474474
headers: map[string]string{
475-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
475+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
476476
},
477477
body: []byte{},
478478
},
@@ -483,7 +483,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
483483
},
484484
out: output{
485485
headers: map[string]string{
486-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
486+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
487487
},
488488
body: expectedMetricFamilyAsText,
489489
},
@@ -495,7 +495,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
495495
},
496496
out: output{
497497
headers: map[string]string{
498-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
498+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
499499
},
500500
body: bytes.Join(
501501
[][]byte{
@@ -514,7 +514,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
514514
},
515515
out: output{
516516
headers: map[string]string{
517-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
517+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=underscores`,
518518
},
519519
body: bytes.Join(
520520
[][]byte{
@@ -533,7 +533,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
533533
},
534534
out: output{
535535
headers: map[string]string{
536-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=values`,
536+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=underscores`,
537537
},
538538
body: bytes.Join(
539539
[][]byte{
@@ -552,7 +552,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
552552
},
553553
out: output{
554554
headers: map[string]string{
555-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
555+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=underscores`,
556556
},
557557
body: bytes.Join(
558558
[][]byte{
@@ -571,7 +571,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
571571
},
572572
out: output{
573573
headers: map[string]string{
574-
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
574+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=underscores`,
575575
},
576576
body: bytes.Join(
577577
[][]byte{
@@ -609,7 +609,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
609609
},
610610
out: output{
611611
headers: map[string]string{
612-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
612+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
613613
},
614614
body: expectedMetricFamilyAsText,
615615
},
@@ -666,7 +666,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
666666
},
667667
out: output{
668668
headers: map[string]string{
669-
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
669+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=underscores`,
670670
},
671671
body: bytes.Join(
672672
[][]byte{

Diff for: prometheus/testutil/testutil.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/kylelemons/godebug/diff"
4848
dto "github.com/prometheus/client_model/go"
4949
"github.com/prometheus/common/expfmt"
50+
"github.com/prometheus/common/model"
5051
"google.golang.org/protobuf/proto"
5152

5253
"github.com/prometheus/client_golang/prometheus"
@@ -298,13 +299,13 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
298299
// result.
299300
func compare(got, want []*dto.MetricFamily) error {
300301
var gotBuf, wantBuf bytes.Buffer
301-
enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
302+
enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain).WithEscapingScheme(model.NoEscaping))
302303
for _, mf := range got {
303304
if err := enc.Encode(mf); err != nil {
304305
return fmt.Errorf("encoding gathered metrics failed: %w", err)
305306
}
306307
}
307-
enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
308+
enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain).WithEscapingScheme(model.NoEscaping))
308309
for _, mf := range want {
309310
if err := enc.Encode(mf); err != nil {
310311
return fmt.Errorf("encoding expected metrics failed: %w", err)

0 commit comments

Comments
 (0)