Skip to content

Commit 3dffe36

Browse files
committed
test fixes
1 parent a5a635b commit 3dffe36

File tree

6 files changed

+25
-30
lines changed

6 files changed

+25
-30
lines changed

prometheus/promhttp/http.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,11 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
160160
}
161161

162162
var contentType expfmt.Format
163-
if req.Header != nil {
164-
fmt.Println("NEGOTIATE content type received: ", req.Header)
165-
}
166163
if opts.EnableOpenMetrics {
167164
contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header)
168165
} else {
169166
contentType = expfmt.Negotiate(req.Header)
170167
}
171-
fmt.Println("NEGOTIATE deduced content type: ", contentType)
172168
header := rsp.Header()
173169
header.Set(contentTypeHeader, string(contentType))
174170

@@ -211,7 +207,6 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
211207
}
212208

213209
for _, mf := range mfs {
214-
// This is the place where the metric family is getting escaped on the receive side.
215210
if handleError(enc.Encode(mf)) {
216211
return
217212
}

prometheus/push/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func New(url, job string) *Pusher {
109109
gatherers: prometheus.Gatherers{reg},
110110
registerer: reg,
111111
client: &http.Client{},
112-
expfmt: expfmt.FmtProtoDelim,
112+
expfmt: expfmt.NewFormat(expfmt.TypeProtoDelim),
113113
}
114114
}
115115

prometheus/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestPush(t *testing.T) {
8484
}
8585

8686
buf := &bytes.Buffer{}
87-
enc := expfmt.NewEncoder(buf, expfmt.FmtProtoDelim)
87+
enc := expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeProtoDelim))
8888

8989
for _, mf := range mfs {
9090
if err := enc.Encode(mf); err != nil {

prometheus/registry_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func testHandler(t testing.TB) {
9292
},
9393
}
9494
externalBuf := &bytes.Buffer{}
95-
enc := expfmt.NewEncoder(externalBuf, expfmt.FmtProtoDelim)
95+
enc := expfmt.NewEncoder(externalBuf, expfmt.NewFormat(expfmt.TypeProtoDelim))
9696
if err := enc.Encode(externalMetricFamily); err != nil {
9797
t.Fatal(err)
9898
}
@@ -162,7 +162,7 @@ metric: <
162162
},
163163
}
164164
buf := &bytes.Buffer{}
165-
enc = expfmt.NewEncoder(buf, expfmt.FmtProtoDelim)
165+
enc = expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeProtoDelim))
166166
if err := enc.Encode(expectedMetricFamily); err != nil {
167167
t.Fatal(err)
168168
}
@@ -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`,
364+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
375+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
386+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
397+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
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`,
408+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
420+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
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`,
432+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
444+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
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`,
456+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
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`,
475+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
486+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
498+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
517+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
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`,
536+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=values`,
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`,
555+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
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`,
574+
"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
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`,
612+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
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`,
669+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
670670
},
671671
body: bytes.Join(
672672
[][]byte{

prometheus/testutil/promlint/promlint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (l *Linter) Lint() ([]Problem, error) {
6868
var problems []Problem
6969

7070
if l.r != nil {
71-
d := expfmt.NewDecoder(l.r, expfmt.FmtText_1_0_0)
71+
d := expfmt.NewDecoder(l.r, expfmt.NewFormat(expfmt.TypeTextPlain))
7272

7373
mf := &dto.MetricFamily{}
7474
for {

prometheus/testutil/testutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,13 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
265265
// result.
266266
func compare(got, want []*dto.MetricFamily) error {
267267
var gotBuf, wantBuf bytes.Buffer
268-
enc := expfmt.NewEncoder(&gotBuf, expfmt.FmtText_1_0_0)
268+
enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
269269
for _, mf := range got {
270270
if err := enc.Encode(mf); err != nil {
271271
return fmt.Errorf("encoding gathered metrics failed: %w", err)
272272
}
273273
}
274-
enc = expfmt.NewEncoder(&wantBuf, expfmt.FmtText_1_0_0)
274+
enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
275275
for _, mf := range want {
276276
if err := enc.Encode(mf); err != nil {
277277
return fmt.Errorf("encoding expected metrics failed: %w", err)

0 commit comments

Comments
 (0)