Skip to content

Commit 6a93bfe

Browse files
committed
Cleanup proto use in tests
Switch tests over to new proto libary, eliminating the direct dependency on the old proto library. Note the indirect requirement is still needed due to upstream use by the client_model package. Related: #1175 Signed-off-by: SuperQ <[email protected]>
1 parent 671a2f0 commit 6a93bfe

File tree

3 files changed

+18
-283
lines changed

3 files changed

+18
-283
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/beorn7/perks v1.0.1
77
github.com/cespare/xxhash/v2 v2.2.0
88
github.com/davecgh/go-spew v1.1.1
9-
github.com/golang/protobuf v1.5.3
109
github.com/json-iterator/go v1.1.12
1110
github.com/prometheus/client_model v0.3.0
1211
github.com/prometheus/common v0.42.0
@@ -16,6 +15,7 @@ require (
1615
)
1716

1817
require (
18+
github.com/golang/protobuf v1.5.3 // indirect
1919
github.com/jpillora/backoff v1.0.0 // indirect
2020
github.com/kr/pretty v0.3.1 // indirect
2121
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect

prometheus/example_metricvec_test.go

+3-32
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ package prometheus_test
1616
import (
1717
"fmt"
1818

19-
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
20-
"github.com/golang/protobuf/proto"
19+
"google.golang.org/protobuf/proto"
2120

2221
dto "github.com/prometheus/client_model/go"
2322

@@ -127,36 +126,8 @@ func ExampleMetricVec() {
127126
if err != nil || len(metricFamilies) != 1 {
128127
panic("unexpected behavior of custom test registry")
129128
}
130-
fmt.Println(proto.MarshalTextString(metricFamilies[0]))
129+
fmt.Println(metricFamilies[0].String())
131130

132131
// Output:
133-
// name: "library_version_info"
134-
// help: "Versions of the libraries used in this binary."
135-
// type: GAUGE
136-
// metric: <
137-
// label: <
138-
// name: "library"
139-
// value: "k8s.io/client-go"
140-
// >
141-
// label: <
142-
// name: "version"
143-
// value: "0.18.8"
144-
// >
145-
// gauge: <
146-
// value: 1
147-
// >
148-
// >
149-
// metric: <
150-
// label: <
151-
// name: "library"
152-
// value: "prometheus/client_golang"
153-
// >
154-
// label: <
155-
// name: "version"
156-
// value: "1.7.1"
157-
// >
158-
// gauge: <
159-
// value: 1
160-
// >
161-
// >
132+
// name:"library_version_info" help:"Versions of the libraries used in this binary." type:GAUGE metric:<label:<name:"library" value:"k8s.io/client-go" > label:<name:"version" value:"0.18.8" > gauge:<value:1 > > metric:<label:<name:"library" value:"prometheus/client_golang" > label:<name:"version" value:"1.7.1" > gauge:<value:1 > >
162133
}

prometheus/examples_test.go

+14-250
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"strings"
2424
"time"
2525

26-
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
27-
"github.com/golang/protobuf/proto"
2826
dto "github.com/prometheus/client_model/go"
2927
"github.com/prometheus/common/expfmt"
3028

@@ -321,25 +319,10 @@ func ExampleSummary() {
321319
// internally).
322320
metric := &dto.Metric{}
323321
temps.Write(metric)
324-
fmt.Println(proto.MarshalTextString(metric))
322+
fmt.Println(metric.String())
325323

326324
// Output:
327-
// summary: <
328-
// sample_count: 1000
329-
// sample_sum: 29969.50000000001
330-
// quantile: <
331-
// quantile: 0.5
332-
// value: 31.1
333-
// >
334-
// quantile: <
335-
// quantile: 0.9
336-
// value: 41.3
337-
// >
338-
// quantile: <
339-
// quantile: 0.99
340-
// value: 41.9
341-
// >
342-
// >
325+
// summary:<sample_count:1000 sample_sum:29969.50000000001 quantile:<quantile:0.5 value:31.1 > quantile:<quantile:0.9 value:41.3 > quantile:<quantile:0.99 value:41.9 > >
343326
}
344327

345328
func ExampleSummaryVec() {
@@ -371,78 +354,10 @@ func ExampleSummaryVec() {
371354
if err != nil || len(metricFamilies) != 1 {
372355
panic("unexpected behavior of custom test registry")
373356
}
374-
fmt.Println(proto.MarshalTextString(metricFamilies[0]))
357+
fmt.Println(metricFamilies[0].String())
375358

376359
// Output:
377-
// name: "pond_temperature_celsius"
378-
// help: "The temperature of the frog pond."
379-
// type: SUMMARY
380-
// metric: <
381-
// label: <
382-
// name: "species"
383-
// value: "leiopelma-hochstetteri"
384-
// >
385-
// summary: <
386-
// sample_count: 0
387-
// sample_sum: 0
388-
// quantile: <
389-
// quantile: 0.5
390-
// value: nan
391-
// >
392-
// quantile: <
393-
// quantile: 0.9
394-
// value: nan
395-
// >
396-
// quantile: <
397-
// quantile: 0.99
398-
// value: nan
399-
// >
400-
// >
401-
// >
402-
// metric: <
403-
// label: <
404-
// name: "species"
405-
// value: "lithobates-catesbeianus"
406-
// >
407-
// summary: <
408-
// sample_count: 1000
409-
// sample_sum: 31956.100000000017
410-
// quantile: <
411-
// quantile: 0.5
412-
// value: 32.4
413-
// >
414-
// quantile: <
415-
// quantile: 0.9
416-
// value: 41.4
417-
// >
418-
// quantile: <
419-
// quantile: 0.99
420-
// value: 41.9
421-
// >
422-
// >
423-
// >
424-
// metric: <
425-
// label: <
426-
// name: "species"
427-
// value: "litoria-caerulea"
428-
// >
429-
// summary: <
430-
// sample_count: 1000
431-
// sample_sum: 29969.50000000001
432-
// quantile: <
433-
// quantile: 0.5
434-
// value: 31.1
435-
// >
436-
// quantile: <
437-
// quantile: 0.9
438-
// value: 41.3
439-
// >
440-
// quantile: <
441-
// quantile: 0.99
442-
// value: 41.9
443-
// >
444-
// >
445-
// >
360+
// name:"pond_temperature_celsius" help:"The temperature of the frog pond." type:SUMMARY metric:<label:<name:"species" value:"leiopelma-hochstetteri" > summary:<sample_count:0 sample_sum:0 quantile:<quantile:0.5 value:nan > quantile:<quantile:0.9 value:nan > quantile:<quantile:0.99 value:nan > > > metric:<label:<name:"species" value:"lithobates-catesbeianus" > summary:<sample_count:1000 sample_sum:31956.100000000017 quantile:<quantile:0.5 value:32.4 > quantile:<quantile:0.9 value:41.4 > quantile:<quantile:0.99 value:41.9 > > > metric:<label:<name:"species" value:"litoria-caerulea" > summary:<sample_count:1000 sample_sum:29969.50000000001 quantile:<quantile:0.5 value:31.1 > quantile:<quantile:0.9 value:41.3 > quantile:<quantile:0.99 value:41.9 > > >
446361
}
447362

448363
func ExampleNewConstSummary() {
@@ -466,33 +381,10 @@ func ExampleNewConstSummary() {
466381
// internally).
467382
metric := &dto.Metric{}
468383
s.Write(metric)
469-
fmt.Println(proto.MarshalTextString(metric))
384+
fmt.Println(metric.String())
470385

471386
// Output:
472-
// label: <
473-
// name: "code"
474-
// value: "200"
475-
// >
476-
// label: <
477-
// name: "method"
478-
// value: "get"
479-
// >
480-
// label: <
481-
// name: "owner"
482-
// value: "example"
483-
// >
484-
// summary: <
485-
// sample_count: 4711
486-
// sample_sum: 403.34
487-
// quantile: <
488-
// quantile: 0.5
489-
// value: 42.3
490-
// >
491-
// quantile: <
492-
// quantile: 0.9
493-
// value: 323.3
494-
// >
495-
// >
387+
// label:<name:"code" value:"200" > label:<name:"method" value:"get" > label:<name:"owner" value:"example" > summary:<sample_count:4711 sample_sum:403.34 quantile:<quantile:0.5 value:42.3 > quantile:<quantile:0.9 value:323.3 > >
496388
}
497389

498390
func ExampleHistogram() {
@@ -512,33 +404,10 @@ func ExampleHistogram() {
512404
// internally).
513405
metric := &dto.Metric{}
514406
temps.Write(metric)
515-
fmt.Println(proto.MarshalTextString(metric))
407+
fmt.Println(metric.String())
516408

517409
// Output:
518-
// histogram: <
519-
// sample_count: 1000
520-
// sample_sum: 29969.50000000001
521-
// bucket: <
522-
// cumulative_count: 192
523-
// upper_bound: 20
524-
// >
525-
// bucket: <
526-
// cumulative_count: 366
527-
// upper_bound: 25
528-
// >
529-
// bucket: <
530-
// cumulative_count: 501
531-
// upper_bound: 30
532-
// >
533-
// bucket: <
534-
// cumulative_count: 638
535-
// upper_bound: 35
536-
// >
537-
// bucket: <
538-
// cumulative_count: 816
539-
// upper_bound: 40
540-
// >
541-
// >
410+
// histogram:<sample_count:1000 sample_sum:29969.50000000001 bucket:<cumulative_count:192 upper_bound:20 > bucket:<cumulative_count:366 upper_bound:25 > bucket:<cumulative_count:501 upper_bound:30 > bucket:<cumulative_count:638 upper_bound:35 > bucket:<cumulative_count:816 upper_bound:40 > >
542411
}
543412

544413
func ExampleNewConstHistogram() {
@@ -562,41 +431,10 @@ func ExampleNewConstHistogram() {
562431
// internally).
563432
metric := &dto.Metric{}
564433
h.Write(metric)
565-
fmt.Println(proto.MarshalTextString(metric))
434+
fmt.Println(metric.String())
566435

567436
// Output:
568-
// label: <
569-
// name: "code"
570-
// value: "200"
571-
// >
572-
// label: <
573-
// name: "method"
574-
// value: "get"
575-
// >
576-
// label: <
577-
// name: "owner"
578-
// value: "example"
579-
// >
580-
// histogram: <
581-
// sample_count: 4711
582-
// sample_sum: 403.34
583-
// bucket: <
584-
// cumulative_count: 121
585-
// upper_bound: 25
586-
// >
587-
// bucket: <
588-
// cumulative_count: 2403
589-
// upper_bound: 50
590-
// >
591-
// bucket: <
592-
// cumulative_count: 3221
593-
// upper_bound: 100
594-
// >
595-
// bucket: <
596-
// cumulative_count: 4233
597-
// upper_bound: 200
598-
// >
599-
// >
437+
// label:<name:"code" value:"200" > label:<name:"method" value:"get" > label:<name:"owner" value:"example" > histogram:<sample_count:4711 sample_sum:403.34 bucket:<cumulative_count:121 upper_bound:25 > bucket:<cumulative_count:2403 upper_bound:50 > bucket:<cumulative_count:3221 upper_bound:100 > bucket:<cumulative_count:4233 upper_bound:200 > >
600438
}
601439

602440
func ExampleNewConstHistogram_WithExemplar() {
@@ -631,81 +469,10 @@ func ExampleNewConstHistogram_WithExemplar() {
631469
// internally).
632470
metric := &dto.Metric{}
633471
h.Write(metric)
634-
fmt.Println(proto.MarshalTextString(metric))
472+
fmt.Println(metric.String())
635473

636474
// Output:
637-
// label: <
638-
// name: "code"
639-
// value: "200"
640-
// >
641-
// label: <
642-
// name: "method"
643-
// value: "get"
644-
// >
645-
// label: <
646-
// name: "owner"
647-
// value: "example"
648-
// >
649-
// histogram: <
650-
// sample_count: 4711
651-
// sample_sum: 403.34
652-
// bucket: <
653-
// cumulative_count: 121
654-
// upper_bound: 25
655-
// exemplar: <
656-
// label: <
657-
// name: "testName"
658-
// value: "testVal"
659-
// >
660-
// value: 24
661-
// timestamp: <
662-
// seconds: 1136214245
663-
// >
664-
// >
665-
// >
666-
// bucket: <
667-
// cumulative_count: 2403
668-
// upper_bound: 50
669-
// exemplar: <
670-
// label: <
671-
// name: "testName"
672-
// value: "testVal"
673-
// >
674-
// value: 42
675-
// timestamp: <
676-
// seconds: 1136214245
677-
// >
678-
// >
679-
// >
680-
// bucket: <
681-
// cumulative_count: 3221
682-
// upper_bound: 100
683-
// exemplar: <
684-
// label: <
685-
// name: "testName"
686-
// value: "testVal"
687-
// >
688-
// value: 89
689-
// timestamp: <
690-
// seconds: 1136214245
691-
// >
692-
// >
693-
// >
694-
// bucket: <
695-
// cumulative_count: 4233
696-
// upper_bound: 200
697-
// exemplar: <
698-
// label: <
699-
// name: "testName"
700-
// value: "testVal"
701-
// >
702-
// value: 157
703-
// timestamp: <
704-
// seconds: 1136214245
705-
// >
706-
// >
707-
// >
708-
// >
475+
// label:<name:"code" value:"200" > label:<name:"method" value:"get" > label:<name:"owner" value:"example" > histogram:<sample_count:4711 sample_sum:403.34 bucket:<cumulative_count:121 upper_bound:25 exemplar:<label:<name:"testName" value:"testVal" > value:24 timestamp:<seconds:1136214245 > > > bucket:<cumulative_count:2403 upper_bound:50 exemplar:<label:<name:"testName" value:"testVal" > value:42 timestamp:<seconds:1136214245 > > > bucket:<cumulative_count:3221 upper_bound:100 exemplar:<label:<name:"testName" value:"testVal" > value:89 timestamp:<seconds:1136214245 > > > bucket:<cumulative_count:4233 upper_bound:200 exemplar:<label:<name:"testName" value:"testVal" > value:157 timestamp:<seconds:1136214245 > > > >
709476
}
710477

711478
func ExampleAlreadyRegisteredError() {
@@ -858,11 +625,8 @@ func ExampleNewMetricWithTimestamp() {
858625
// internally).
859626
metric := &dto.Metric{}
860627
s.Write(metric)
861-
fmt.Println(proto.MarshalTextString(metric))
628+
fmt.Println(metric.String())
862629

863630
// Output:
864-
// gauge: <
865-
// value: 298.15
866-
// >
867-
// timestamp_ms: 1257894000012
631+
// gauge:<value:298.15 > timestamp_ms:1257894000012
868632
}

0 commit comments

Comments
 (0)