Debian Codegraph @

exporter/clients_test.go

raw symbols SCIP
1 package exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
5 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
6 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
7 "timescip-go gomod github.com/golang/go/src go1.25.0 time/"
8
9 "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/"
10 )
11
12 func TestDurationFieldToTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestDurationFieldToTimestamp().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
13 nowTs := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Unix().()
14 for _, tst := range []struct {
15 in string
16 expectedOk bool
17 expectedVal int64
18 }{
19 {
20 in: "123",
21 expectedOk: true,
22 expectedVal: nowTs - 123,
23 },
24 {
25 in: "0",
26 expectedOk: true,
27 expectedVal: nowTs - 0,
28 },
29 {
30 in: "abc",
31 expectedOk: false,
32 },
33 } {
34 res, err := durationFieldToTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/durationFieldToTimestamp().(tst.in)
35 if err == nil && !tst.expectedOk {
36 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected not ok, but got no error, input: [%s]", tst.in)
37 } else if err != nil && tst.expectedOk {
38 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected ok, but got error: %s, input: [%s]", err, tst.in)
39 }
40 if tst.expectedOk {
41 if res != tst.expectedVal {
42 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected %d, but got: %d", tst.expectedVal, res)
43 }
44 }
45 }
46 }
47
48 func TestParseClientListStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestParseClientListString().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
49 convertDurationToTimestampInt64 := func(duration string) int64 {
50 ts, err := durationFieldToTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/durationFieldToTimestamp().(duration)
51 if err != nil {
52 panic(err)
53 }
54 return ts
55 }
56
57 tsts := []struct {
58 in string
59 expectedOk bool
60 expectedInfo ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#
61 }{
62 {
63 in: "id=11 addr=127.0.0.1:63508 fd=8 name= age=6321 idle=6320 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=3 oll=8 omem=0 tot-mem=0 events=r cmd=setex",
64 expectedOk: true,
65 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "11", CreatedAtscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#CreatedAt.: convertDurationToTimestampInt64("6321"), IdleSincescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#IdleSince.: convertDurationToTimestampInt64("6320"), Flagsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Flags.: "N", Dbscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Db.: "0", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Oblscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Obl.: 3, Ollscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Oll.: 8, OMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#OMem.: 0, TotMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#TotMem.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "63508"},
66 }, {
67 in: "id=14 addr=127.0.0.1:64958 fd=9 name=foo age=5 idle=0 flags=N db=1 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 tot-mem=0 events=r cmd=client",
68 expectedOk: true,
69 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Name.: "foo", CreatedAtscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#CreatedAt.: convertDurationToTimestampInt64("5"), IdleSincescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#IdleSince.: convertDurationToTimestampInt64("0"), Flagsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Flags.: "N", Dbscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Db.: "1", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Qbufscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Qbuf.: 26, QbufFreescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#QbufFree.: 32742, OMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#OMem.: 0, TotMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#TotMem.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
70 }, {
71 in: "id=14 addr=127.0.0.1:64959 fd=9 name= age=5 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 tot-mem=0 events=r cmd=client user=default resp=3",
72 expectedOk: true,
73 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", CreatedAtscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#CreatedAt.: convertDurationToTimestampInt64("5"), IdleSincescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#IdleSince.: convertDurationToTimestampInt64("0"), Flagsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Flags.: "N", Dbscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Db.: "0", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Qbufscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Qbuf.: 26, QbufFreescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#QbufFree.: 32742, OMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#OMem.: 0, TotMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#TotMem.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64959", Userscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#User.: "default", Respscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Resp.: "3"},
74 }, {
75 in: "id=40253233 addr=fd40:1481:21:dbe0:7021:300:a03:1a06:44426 fd=19 name= age=782 idle=0 flags=N db=0 sub=896 psub=18 ssub=17 watch=3 multi=-1 qbuf=26 qbuf-free=32742 argv-mem=10 obl=0 oll=555 omem=0 tot-mem=61466 ow=0 owmem=0 events=r cmd=client user=default lib-name=redis-py lib-ver=5.0.1 numops=9",
76 expectedOk: true,
77 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "40253233", CreatedAtscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#CreatedAt.: convertDurationToTimestampInt64("782"), IdleSincescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#IdleSince.: convertDurationToTimestampInt64("0"), Flagsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Flags.: "N", Dbscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Db.: "0", Subscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Sub.: 896, Psubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Psub.: 18, Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: 17, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: 3, Qbufscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Qbuf.: 26, QbufFreescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#QbufFree.: 32742, Ollscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Oll.: 555, OMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#OMem.: 0, TotMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#TotMem.: 61466, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "fd40:1481:21:dbe0:7021:300:a03:1a06", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "44426", Userscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#User.: "default"},
78 }, {
79 in: "id=14 addr=127.0.0.1:64958 fd=9 name=foo age=ABCDE idle=0 flags=N db=1 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 tot-mem=0 events=r cmd=client",
80 expectedOk: false,
81 }, {
82 in: "id=14 addr=127.0.0.1:64958 fd=9 name=foo age=5 idle=NOPE flags=N db=1 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 tot-mem=0 events=r cmd=client",
83 expectedOk: false,
84 }, {
85 in: "id=14 addr=127.0.0.1:64958 sub=ERR",
86 expectedOk: true,
87 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Subscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Sub.: 0, Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
88 }, {
89 in: "id=14 addr=127.0.0.1:64958 psub=ERR",
90 expectedOk: true,
91 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Psubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Psub.: 0, Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
92 }, {
93 in: "id=14 addr=127.0.0.1:64958 ssub=ERR",
94 expectedOk: true,
95 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: 0, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
96 }, {
97 in: "id=14 addr=127.0.0.1:64958 watch=ERR",
98 expectedOk: true,
99 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
100 }, {
101 in: "id=14 addr=127.0.0.1:64958 qbuf=ERR",
102 expectedOk: true,
103 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Qbufscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Qbuf.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
104 }, {
105 in: "id=14 addr=127.0.0.1:64958 qbuf-free=ERR",
106 expectedOk: true,
107 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, QbufFreescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#QbufFree.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
108 }, {
109 in: "id=14 addr=127.0.0.1:64958 obl=ERR",
110 expectedOk: true,
111 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Oblscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Obl.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
112 }, {
113 in: "id=14 addr=127.0.0.1:64958 oll=ERR",
114 expectedOk: true,
115 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, Ollscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Oll.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
116 }, {
117 in: "id=14 addr=127.0.0.1:64958 omem=ERR",
118 expectedOk: true,
119 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, OMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#OMem.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
120 }, {
121 in: "id=14 addr=127.0.0.1:64958 tot-mem=ERR",
122 expectedOk: true,
123 expectedInfo: ClientInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#{Idscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Id.: "14", Ssubscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Ssub.: -1, Watchscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Watch.: -1, TotMemscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#TotMem.: 0, Hostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Host.: "127.0.0.1", Portscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ClientInfo#Port.: "64958"},
124 }, {
125 in: "",
126 expectedOk: false,
127 },
128 }
129
130 for _, tst := range tsts {
131 info, ok := parseClientListStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseClientListString().(tst.in)
132 if !tst.expectedOk {
133 if ok {
134 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected NOT ok, but got ok, input: %s", tst.in)
135 }
136 continue
137 }
138
139 if *info != tst.expectedInfo {
140 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TestParseClientListString( %s ) error. Given: %#v Wanted: %#v", tst.in, info, tst.expectedInfo)
141 }
142 }
143 }
144
145 func TestExportClientListscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestExportClientList().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
146 for _, isExportClientList := range []bool{true, false} {
147 e := getTestExporterWithOptionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/getTestExporterWithOptions().(Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{
148 Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test",
149 ExportClientListscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#ExportClientList.: isExportClientList,
150 })
151
152 chM := make(chan prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#)
153 go func() {
154 e.Collectscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#Collect().(chM)
155 close(chM)
156 }()
157
158 tsts := []struct {
159 in string
160 found bool
161 }{
162 {in: "connected_client_info"},
163 {in: "connected_client_output_buffer_memory_usage_bytes"},
164 {in: "connected_client_total_memory_consumed_bytes"},
165 {in: "connected_client_created_at_timestamp"},
166 {in: "connected_client_idle_since_timestamp"},
167 {in: "connected_client_channel_subscriptions_count"},
168 {in: "connected_client_pattern_matching_subscriptions_count"},
169 {in: "connected_client_query_buffer_length_bytes"},
170 {in: "connected_client_query_buffer_free_space_bytes"},
171 {in: "connected_client_output_buffer_length_bytes"},
172 {in: "connected_client_output_list_length"},
173 {in: "connected_client_shard_channel_subscriptions_count"},
174 {in: "connected_client_info"},
175 }
176 for m := range chM {
177 desc := m.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().().Stringscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc#String().()
178 for i := range tsts {
179 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(desc, tsts[i].in) {
180 tsts[i].found = true
181 }
182 }
183 }
184
185 for _, tst := range tsts {
186 if isExportClientList && !tst.found {
187 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s was *not* found in isExportClientList metrics but expected", tst.in)
188 } else if !isExportClientList && tst.found {
189 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s was *found* in isExportClientList metrics but *not* expected", tst.in)
190 }
191 }
192 }
193 }
194
195 /*
196 some metrics are only in redis 7 but not yet in valkey 7.2
197 like "connected_client_shard_channel_watched_keys"
198 */
199 func TestExportClientListRedis7scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestExportClientListRedis7().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
200 redisSevenAddr := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_REDIS7_URI")
201 if redisSevenAddr == "" {
202 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("Skipping TestExportClientListRedis7, env var TEST_REDIS7_URI not set")
203 }
204
205 e := getTestExporterWithAddrAndOptionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/getTestExporterWithAddrAndOptions().(redisSevenAddr, Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{
206 Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test",
207 ExportClientListscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#ExportClientList.: true,
208 })
209
210 chM := make(chan prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#)
211 go func() {
212 e.Collectscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#Collect().(chM)
213 close(chM)
214 }()
215
216 tsts := []struct {
217 in string
218 found bool
219 }{
220 {
221 in: "connected_client_shard_channel_subscriptions_count",
222 }, {
223 in: "connected_client_shard_channel_watched_keys",
224 },
225 }
226 for m := range chM {
227 desc := m.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().().Stringscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc#String().()
228 for i := range tsts {
229 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(desc, tsts[i].in) {
230 tsts[i].found = true
231 }
232 }
233 }
234
235 for _, tst := range tsts {
236 if !tst.found {
237 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(`%s was *not* found in isExportClientList metrics but expected`, tst.in)
238 }
239 }
240 }
241
242 func TestExportClientListInclPortscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestExportClientListInclPort().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
243 for _, inclPort := range []bool{true, false} {
244 e := getTestExporterWithOptionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/getTestExporterWithOptions().(Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{
245 Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test",
246 ExportClientListscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#ExportClientList.: true,
247 ExportClientsInclPortscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#ExportClientsInclPort.: inclPort,
248 })
249
250 chM := make(chan prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#)
251 go func() {
252 e.Collectscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#Collect().(chM)
253 close(chM)
254 }()
255
256 found := false
257 for m := range chM {
258 desc := m.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().().Stringscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc#String().()
259 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(desc, "connected_client_info") {
260 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(desc, "port") {
261 found = true
262 }
263 }
264 }
265
266 if inclPort && !found {
267 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(`connected_client_info did *not* include "port" in isExportClientList metrics but was expected`)
268 } else if !inclPort && found {
269 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(`connected_client_info did *include* "port" in isExportClientList metrics but was *not* expected`)
270 }
271 }
272 }