Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 740f72f

Browse files
authoredJun 15, 2023
Update Prometheus libraries (#891)
* Update Prometheus libraries. * Update fixtures for new proto rendering. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 25e116c commit 740f72f

File tree

3 files changed

+66
-68
lines changed

3 files changed

+66
-68
lines changed
 

‎collector/collector_test.go

+38-37
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"errors"
1818
"reflect"
1919
"regexp"
20+
"strings"
2021
"testing"
2122

2223
kingpin "github.com/alecthomas/kingpin/v2"
@@ -60,7 +61,7 @@ func TestPduToSample(t *testing.T) {
6061
},
6162
oidToPdu: make(map[string]gosnmp.SnmpPDU),
6263
expectedMetrics: []string{
63-
`Desc{fqName: "TestMetricNameExtension", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:<value:5 > `,
64+
`Desc{fqName: "TestMetricNameExtension", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:{value:5}`,
6465
},
6566
},
6667
{
@@ -131,7 +132,7 @@ func TestPduToSample(t *testing.T) {
131132
},
132133
},
133134
expectedMetrics: []string{
134-
`Desc{fqName: "TestMetricNameStatus", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:<value:5 > `,
135+
`Desc{fqName: "TestMetricNameStatus", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:{value:5}`,
135136
},
136137
},
137138
{
@@ -193,9 +194,9 @@ func TestPduToSample(t *testing.T) {
193194
},
194195
oidToPdu: make(map[string]gosnmp.SnmpPDU),
195196
expectedMetrics: []string{
196-
`Desc{fqName: "TestMetricNameExtension", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:<value:5 > `,
197-
`Desc{fqName: "TestMetricNameMultipleRegexes", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:<value:999 > `,
198-
`Desc{fqName: "TestMetricNameTemplate", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:<value:4.42 > `,
197+
`Desc{fqName: "TestMetricNameExtension", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:{value:5}`,
198+
`Desc{fqName: "TestMetricNameMultipleRegexes", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:{value:999}`,
199+
`Desc{fqName: "TestMetricNameTemplate", help: "HelpText (regex extracted)", constLabels: {}, variableLabels: []} gauge:{value:4.42}`,
199200
},
200201
},
201202
{
@@ -212,7 +213,7 @@ func TestPduToSample(t *testing.T) {
212213
Help: "Help string",
213214
},
214215
oidToPdu: make(map[string]gosnmp.SnmpPDU),
215-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} counter:<value:2 > `},
216+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} counter:{value:2}`},
216217
},
217218
{
218219
pdu: &gosnmp.SnmpPDU{
@@ -228,7 +229,7 @@ func TestPduToSample(t *testing.T) {
228229
Help: "Help string",
229230
},
230231
oidToPdu: make(map[string]gosnmp.SnmpPDU),
231-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:<value:2 > `},
232+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:{value:2}`},
232233
},
233234
{
234235
pdu: &gosnmp.SnmpPDU{
@@ -243,7 +244,7 @@ func TestPduToSample(t *testing.T) {
243244
Help: "Help string",
244245
},
245246
oidToPdu: make(map[string]gosnmp.SnmpPDU),
246-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"-2" > gauge:<value:1 > `},
247+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"-2"} gauge:{value:1}`},
247248
},
248249
{
249250
pdu: &gosnmp.SnmpPDU{
@@ -259,7 +260,7 @@ func TestPduToSample(t *testing.T) {
259260
Help: "Help string",
260261
},
261262
oidToPdu: make(map[string]gosnmp.SnmpPDU),
262-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:<value:3 > `},
263+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:{value:3}`},
263264
},
264265
{
265266
pdu: &gosnmp.SnmpPDU{
@@ -275,7 +276,7 @@ func TestPduToSample(t *testing.T) {
275276
Help: "Help string",
276277
},
277278
oidToPdu: make(map[string]gosnmp.SnmpPDU),
278-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:<value:3 > `},
279+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: []} gauge:{value:3}`},
279280
},
280281
{
281282
pdu: &gosnmp.SnmpPDU{
@@ -292,7 +293,7 @@ func TestPduToSample(t *testing.T) {
292293
Indexes: []*config.Index{{Labelname: "foo", Type: "DisplayString"}},
293294
},
294295
oidToPdu: make(map[string]gosnmp.SnmpPDU),
295-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [foo]} label:<name:"foo" value:"AA" > gauge:<value:3 > `},
296+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{foo <nil>}]} label:{name:"foo" value:"AA"} gauge:{value:3}`},
296297
},
297298
{
298299
pdu: &gosnmp.SnmpPDU{
@@ -344,7 +345,7 @@ func TestPduToSample(t *testing.T) {
344345
Help: "Help string",
345346
},
346347
oidToPdu: map[string]gosnmp.SnmpPDU{"1.41.2": gosnmp.SnmpPDU{Value: 1}},
347-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"4.5.6.7" > gauge:<value:1 > `},
348+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"4.5.6.7"} gauge:{value:1}`},
348349
},
349350
{
350351
pdu: &gosnmp.SnmpPDU{
@@ -359,7 +360,7 @@ func TestPduToSample(t *testing.T) {
359360
Help: "Help string",
360361
},
361362
oidToPdu: map[string]gosnmp.SnmpPDU{"1.41.2": gosnmp.SnmpPDU{Value: 1}},
362-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"4.5.6.7" > gauge:<value:1 > `},
363+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"4.5.6.7"} gauge:{value:1}`},
363364
},
364365
{
365366
pdu: &gosnmp.SnmpPDU{
@@ -374,7 +375,7 @@ func TestPduToSample(t *testing.T) {
374375
Help: "Help string",
375376
},
376377
oidToPdu: map[string]gosnmp.SnmpPDU{"1.41.2": gosnmp.SnmpPDU{Value: 2}},
377-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"0405:0607:0809:0A0B:0C0D:0E0F:1011:1213" > gauge:<value:1 > `},
378+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"0405:0607:0809:0A0B:0C0D:0E0F:1011:1213"} gauge:{value:1}`},
378379
},
379380
{
380381
pdu: &gosnmp.SnmpPDU{
@@ -389,7 +390,7 @@ func TestPduToSample(t *testing.T) {
389390
Help: "Help string",
390391
},
391392
oidToPdu: map[string]gosnmp.SnmpPDU{"1.41.2": gosnmp.SnmpPDU{Value: 3}},
392-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"0x0405060708" > gauge:<value:1 > `},
393+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"0x0405060708"} gauge:{value:1}`},
393394
},
394395
{
395396
pdu: &gosnmp.SnmpPDU{
@@ -404,7 +405,7 @@ func TestPduToSample(t *testing.T) {
404405
Help: "Help string",
405406
},
406407
oidToPdu: make(map[string]gosnmp.SnmpPDU),
407-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"0x04050607" > gauge:<value:1 > `},
408+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"0x04050607"} gauge:{value:1}`},
408409
},
409410
{
410411
pdu: &gosnmp.SnmpPDU{
@@ -419,7 +420,7 @@ func TestPduToSample(t *testing.T) {
419420
Help: "Help string",
420421
},
421422
oidToPdu: map[string]gosnmp.SnmpPDU{"1.41.2": gosnmp.SnmpPDU{Value: 3}},
422-
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"04:05:06:07:08:09" > gauge:<value:1 > `},
423+
expectedMetrics: []string{`Desc{fqName: "test_metric", help: "Help string", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"04:05:06:07:08:09"} gauge:{value:1}`},
423424
},
424425
{
425426
pdu: &gosnmp.SnmpPDU{
@@ -434,7 +435,7 @@ func TestPduToSample(t *testing.T) {
434435
Help: "Help string",
435436
EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"},
436437
},
437-
expectedMetrics: []string{`Desc{fqName: "test_metric_info", help: "Help string (EnumAsInfo)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"baz" > gauge:<value:1 > `},
438+
expectedMetrics: []string{`Desc{fqName: "test_metric_info", help: "Help string (EnumAsInfo)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"baz"} gauge:{value:1}`},
438439
},
439440
{
440441
pdu: &gosnmp.SnmpPDU{
@@ -449,7 +450,7 @@ func TestPduToSample(t *testing.T) {
449450
Help: "Help string",
450451
EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"},
451452
},
452-
expectedMetrics: []string{`Desc{fqName: "test_metric_info", help: "Help string (EnumAsInfo)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"3" > gauge:<value:1 > `},
453+
expectedMetrics: []string{`Desc{fqName: "test_metric_info", help: "Help string (EnumAsInfo)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"3"} gauge:{value:1}`},
453454
},
454455
{
455456
pdu: &gosnmp.SnmpPDU{
@@ -465,9 +466,9 @@ func TestPduToSample(t *testing.T) {
465466
EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"},
466467
},
467468
expectedMetrics: []string{
468-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"foo" > gauge:<value:0 > `,
469-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"bar" > gauge:<value:0 > `,
470-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"baz" > gauge:<value:1 > `,
469+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"foo"} gauge:{value:0}`,
470+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"bar"} gauge:{value:0}`,
471+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"baz"} gauge:{value:1}`,
471472
},
472473
},
473474
{
@@ -484,10 +485,10 @@ func TestPduToSample(t *testing.T) {
484485
EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"},
485486
},
486487
expectedMetrics: []string{
487-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"foo" > gauge:<value:0 > `,
488-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"bar" > gauge:<value:0 > `,
489-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"baz" > gauge:<value:0 > `,
490-
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"3" > gauge:<value:1 > `,
488+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"foo"} gauge:{value:0}`,
489+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"bar"} gauge:{value:0}`,
490+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"baz"} gauge:{value:0}`,
491+
`Desc{fqName: "test_metric", help: "Help string (EnumAsStateSet)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"3"} gauge:{value:1}`,
491492
},
492493
},
493494
{
@@ -504,14 +505,14 @@ func TestPduToSample(t *testing.T) {
504505
EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz", 8: "byte2msb", 15: "byte2lsb", 16: "byte3msb", 23: "byte3lsb", 24: "missing"},
505506
},
506507
expectedMetrics: []string{
507-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"foo" > gauge:<value:1 > `,
508-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"bar" > gauge:<value:1 > `,
509-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"baz" > gauge:<value:0 > `,
510-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"byte2msb" > gauge:<value:1 > `,
511-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"byte2lsb" > gauge:<value:0 > `,
512-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"byte3msb" > gauge:<value:0 > `,
513-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"byte3lsb" > gauge:<value:1 > `,
514-
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [test_metric]} label:<name:"test_metric" value:"missing" > gauge:<value:0 > `,
508+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"foo"} gauge:{value:1}`,
509+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"bar"} gauge:{value:1}`,
510+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"baz"} gauge:{value:0}`,
511+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"byte2msb"} gauge:{value:1}`,
512+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"byte2lsb"} gauge:{value:0}`,
513+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"byte3msb"} gauge:{value:0}`,
514+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"byte3lsb"} gauge:{value:1}`,
515+
`Desc{fqName: "test_metric", help: "Help string (Bits)", constLabels: {}, variableLabels: [{test_metric <nil>}]} label:{name:"test_metric" value:"missing"} gauge:{value:0}`,
515516
},
516517
},
517518
}
@@ -534,15 +535,15 @@ func TestPduToSample(t *testing.T) {
534535
t.Fatalf("Error writing metric: %v", err)
535536
}
536537
}
537-
got := m.Desc().String() + " " + metric.String()
538+
got := strings.ReplaceAll(m.Desc().String()+" "+metric.String(), " ", " ")
538539
if _, ok := expected[got]; !ok {
539-
t.Errorf("Unexpected metric: got %v", got)
540+
t.Errorf("Got metric: %v", got)
540541
} else {
541542
delete(expected, got)
542543
}
543544
}
544545
for e := range expected {
545-
t.Errorf("Expected metric %v, but was not returned.", e)
546+
t.Errorf("Expected metric: %v, but was not returned.", e)
546547
}
547548
if !errHappened && c.shouldErr {
548549
t.Fatalf("Was expecting error, but none returned.")

‎go.mod

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,32 @@ require (
66
github.com/alecthomas/kingpin/v2 v2.3.2
77
github.com/go-kit/log v0.2.1
88
github.com/gosnmp/gosnmp v1.35.0
9-
github.com/prometheus/client_golang v1.14.0
10-
github.com/prometheus/client_model v0.3.0
11-
github.com/prometheus/common v0.42.0
9+
github.com/prometheus/client_golang v1.15.1
10+
github.com/prometheus/client_model v0.4.0
11+
github.com/prometheus/common v0.44.0
1212
github.com/prometheus/exporter-toolkit v0.10.0
1313
gopkg.in/yaml.v2 v2.4.0
1414
)
1515

1616
require (
1717
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
1818
github.com/beorn7/perks v1.0.1 // indirect
19-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
19+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2020
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
2121
github.com/go-logfmt/logfmt v0.5.1 // indirect
22-
github.com/golang/protobuf v1.5.2 // indirect
22+
github.com/golang/protobuf v1.5.3 // indirect
2323
github.com/jpillora/backoff v1.0.0 // indirect
2424
github.com/kr/text v0.2.0 // indirect
2525
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
2626
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
2727
github.com/prometheus/procfs v0.9.0 // indirect
28-
github.com/rogpeppe/go-internal v1.9.0 // indirect
2928
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
3029
golang.org/x/crypto v0.8.0 // indirect
31-
golang.org/x/net v0.9.0 // indirect
32-
golang.org/x/oauth2 v0.6.0 // indirect
30+
golang.org/x/net v0.10.0 // indirect
31+
golang.org/x/oauth2 v0.8.0 // indirect
3332
golang.org/x/sync v0.1.0 // indirect
34-
golang.org/x/sys v0.7.0 // indirect
33+
golang.org/x/sys v0.8.0 // indirect
3534
golang.org/x/text v0.9.0 // indirect
3635
google.golang.org/appengine v1.6.7 // indirect
37-
google.golang.org/protobuf v1.28.1 // indirect
36+
google.golang.org/protobuf v1.30.0 // indirect
3837
)
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.