Debian Codegraph @

exporter/sentinels_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 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/"
6 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
7 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
8 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
9
10 "github.com/gomodule/redigo/redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/"
11 "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/"
12 dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/ "github.com/prometheus/client_model/goscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/"
13 )
14
15 func TestSentinelExtractInfoMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelExtractInfoMetrics().(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#) {
16 if 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_VALKEY_SENTINEL_URI") == "" {
17 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
18 }
19 addr := 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_VALKEY_SENTINEL_URI")
20 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
21 addr,
22 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"},
23 )
24 c, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.DialURLscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/DialURL().(addr)
25 if err != nil {
26 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
27 }
28
29 infoAll, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Stringscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/String().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "INFO", "ALL"))
30 if err != nil {
31 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Redis INFO ALL err: %s", err)
32 infoAll, err = redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Stringscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/String().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "INFO"))
33 if err != nil {
34 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Redis INFO err: %s", err)
35 }
36 }
37
38 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#)
39 go func() {
40 e.extractInfoMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractInfoMetrics().(chM, infoAll, 0)
41 close(chM)
42 }()
43 want := map[string]bool{
44 "sentinel_tilt": false,
45 "sentinel_running_scripts": false,
46 "sentinel_scripts_queue_length": false,
47 "sentinel_simulate_failure_flags": false,
48 "sentinel_masters": false,
49 "sentinel_master_status": false,
50 "sentinel_master_slaves": false,
51 "sentinel_master_sentinels": false,
52 }
53
54 for m := range chM {
55 for k := range want {
56 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().(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().(), k) {
57 want[k] = true
58 }
59 }
60 }
61 for k, found := range want {
62 if !found {
63 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find %s", k)
64 }
65
66 }
67 }
68
69 type sentinelDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData# struct {
70 kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k., vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v. string
71 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#name., statusscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#status., addressscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#address. string
72 slavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#slaves., sentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#sentinels. float64
73 okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok. bool
74 }
75
76 func TestSentinelParseSentinelMasterStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelParseSentinelMasterString().(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#) {
77 tsts := []sentinelDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#{
78 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "master0", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "name=user03,status=sdown,address=192.169.2.52:6381,slaves=1,sentinels=5", namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#name.: "user03", statusscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#status.: "sdown", addressscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#address.: "192.169.2.52:6381", slavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#slaves.: 1, sentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#sentinels.: 5, okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: true},
79 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "master1", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "name=master,status=ok,address=127.0.0.1:6379,slaves=999,sentinels=500", namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#name.: "master", statusscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#status.: "ok", addressscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#address.: "127.0.0.1:6379", slavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#slaves.: 999, sentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#sentinels.: 500, okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: true},
80
81 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "master", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "name=user03", okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: false},
82 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "masterA", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "status=ko", okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: false},
83 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "master0", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "slaves=abc,sentinels=0", okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: false},
84 {kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k.: "master0", vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.: "slaves=0,sentinels=abc", okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok.: false},
85 }
86
87 for _, tst := range tsts {
88 name := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s---%s", tst.kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k., tst.vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.)
89 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(name, func(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#) {
90 if masterName, masterStatus, masterAddress, masterSlaves, masterSentinels, ok := parseSentinelMasterStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseSentinelMasterString().(tst.kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k., tst.vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.); true {
91 if ok != tst.okscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#ok. {
92 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed for: master:%s data:%s", tst.kscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#k., tst.vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v.)
93 return
94 }
95 if masterName != tst.namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#name. || masterStatus != tst.statusscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#status. || masterAddress != tst.addressscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#address. || masterSlaves != tst.slavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#slaves. || masterSentinels != tst.sentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#sentinels. {
96 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("values not matching:\nstring:%s\ngot:%s %s %s %f %f", tst.vscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelData#v., masterName, masterStatus, masterAddress, masterSlaves, masterSentinels)
97 }
98 }
99 })
100 }
101 }
102
103 func TestSentinelExtractSentinelMetricsForRedisscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelExtractSentinelMetricsForRedis().(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#) {
104 if 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_REDIS_URI") == "" {
105 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS_URI not set - skipping")
106 }
107 addr := 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_REDIS_URI")
108 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
109 addr,
110 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"},
111 )
112 c, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.DialURLscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/DialURL().(addr)
113 if err != nil {
114 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
115 }
116 defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
117
118 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#)
119 go func() {
120 e.extractSentinelMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractSentinelMetrics().(chM, c)
121 close(chM)
122 }()
123
124 want := map[string]bool{
125 "sentinel_master_ok_sentinels": false,
126 "sentinel_master_ok_slaves": false,
127 }
128
129 for m := range chM {
130 for k := range want {
131 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().(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().(), k) {
132 want[k] = true
133 }
134 }
135 }
136 for k, found := range want {
137 if found {
138 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Found sentinel metric %s for redis instance", k)
139 }
140 }
141 }
142
143 func TestSentinelExtractSentinelMetricsForSentinelscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelExtractSentinelMetricsForSentinel().(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#) {
144 if 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_VALKEY_SENTINEL_URI") == "" {
145 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
146 }
147 addr := 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_VALKEY_SENTINEL_URI")
148 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
149 addr,
150 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"},
151 )
152 c, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.DialURLscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/DialURL().(addr)
153 if err != nil {
154 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
155 }
156 defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
157
158 infoAll, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Stringscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/String().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "INFO", "ALL"))
159 if err != nil {
160 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Redis INFO ALL err: %s", err)
161 infoAll, err = redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Stringscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/String().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "INFO"))
162 if err != nil {
163 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Redis INFO err: %s", err)
164 }
165 }
166
167 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#)
168 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().(infoAll, "# Sentinel") {
169 go func() {
170 e.extractSentinelMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractSentinelMetrics().(chM, c)
171 close(chM)
172 }()
173 } else {
174 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't find sentinel section in Redis INFO: %s", infoAll)
175 }
176
177 want := map[string]bool{
178 "sentinel_master_ok_sentinels": false,
179 "sentinel_master_ok_slaves": false,
180 "sentinel_master_ckquorum_status": false,
181 "sentinel_master_setting_ckquorum": false,
182 "sentinel_master_setting_failover_timeout": false,
183 "sentinel_master_setting_parallel_syncs": false,
184 "sentinel_master_setting_down_after_milliseconds": false,
185 }
186
187 for m := range chM {
188 for k := range want {
189 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().(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().(), k) {
190 want[k] = true
191 }
192 }
193 }
194 for k, found := range want {
195 if !found {
196 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find metric %s", k)
197 }
198 }
199 }
200
201 type sentinelSentinelsDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData# struct {
202 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#name. string
203 sentinelDetailsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#sentinelDetails. []any
204 labelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#labels. []string
205 expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedMetricValue. map[string]int
206 expectedPeerInfoCountscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedPeerInfoCount. int
207 }
208
209 func TestSentinelProcessSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelProcessSentinels().(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#) {
210 if 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_VALKEY_SENTINEL_URI") == "" {
211 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
212 }
213 addr := 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_VALKEY_SENTINEL_URI")
214 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
215 addr,
216 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test", InclSentinelPeerInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclSentinelPeerInfo.: true},
217 )
218
219 oneOkSentinelExpectedMetricValue := map[string]int{
220 "sentinel_master_ok_sentinels": 1,
221 }
222 twoOkSentinelExpectedMetricValue := map[string]int{
223 "sentinel_master_ok_sentinels": 2,
224 }
225 tsts := []sentinelSentinelsDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#{
226 {"1/1 okay sentinel", []any{[]any{[]byte("")}}, []string{"mymaster", "172.17.0.7:26379"}, oneOkSentinelExpectedMetricValue, 0},
227 {"1/3 okay sentinel", []any{[]any{[]byte("name"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("ip"), []byte("172.17.0.8"), []byte("port"), []byte("26379"), []byte("runid"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("flags"), []byte("o_down,s_down,sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823816"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}, []any{[]byte("name"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("ip"), []byte("172.17.0.7"), []byte("port"), []byte("26379"), []byte("runid"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("flags"), []byte("s_down,sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823815"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}}, []string{"mymaster", "172.17.0.7:26379"}, oneOkSentinelExpectedMetricValue, 2},
228 {"2/3 okay sentinel(string is not byte slice)", []any{[]any{[]byte("name"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("ip"), []byte("172.17.0.8"), []byte("port"), []byte("26379"), []byte("runid"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("flags"), []byte("sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823816"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}, []any{[]byte("name"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("ip"), []byte("172.17.0.7"), []byte("port"), []byte("26379"), []byte("runid"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("flags"), "sentinel", []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823815"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}}, []string{"mymaster", "172.17.0.7:26379"}, twoOkSentinelExpectedMetricValue, 1},
229 {"2/3 okay sentinel", []any{[]any{[]byte("name"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("ip"), []byte("172.17.0.8"), []byte("port"), []byte("26379"), []byte("runid"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("flags"), []byte("sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823816"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}, []any{[]byte("name"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("ip"), []byte("172.17.0.7"), []byte("port"), []byte("26379"), []byte("runid"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("flags"), []byte("s_down,sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823815"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}}, []string{"mymaster", "172.17.0.7:26379"}, twoOkSentinelExpectedMetricValue, 2},
230 {"2/3 okay sentinel(missing flags)", []any{[]any{[]byte("name"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("ip"), []byte("172.17.0.8"), []byte("port"), []byte("26379"), []byte("runid"), []byte("284bc2ef46881bd71e81610152cb96031d211d28"), []byte("flags"), []byte("sentinel"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823816"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}, []any{[]byte("name"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("ip"), []byte("172.17.0.7"), []byte("port"), []byte("26379"), []byte("runid"), []byte("c3ab3cdcaeb193bb49b16d4d3da88def984ab3bf"), []byte("link-pending-commands"), []byte("38"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("11828891"), []byte("last-ok-ping-reply"), []byte("11829539"), []byte("last-ping-reply"), []byte("11829539"), []byte("s-down-time"), []byte("11823815"), []byte("down-after-milliseconds"), []byte("5000"), []byte("last-hello-message"), []byte("11829434"), []byte("voted-leader"), []byte("?"), []byte("voted-leader-epoch"), []byte("0")}}, []string{"mymaster", "172.17.0.7:26379"}, twoOkSentinelExpectedMetricValue, 2},
231 }
232 for _, tst := range tsts {
233 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tst.namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#name., func(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#) {
234 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#)
235 go func() {
236 e.processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(chM, tst.sentinelDetailsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#sentinelDetails., tst.labelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#labels....)
237 close(chM)
238 }()
239 want := map[string]bool{
240 "sentinel_master_ok_sentinels": false,
241 "sentinel_peer_info": false,
242 }
243 peerInfoCount := 0
244
245 for m := range chM {
246 descStr := 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().()
247 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().(descStr, "sentinel_peer_info") {
248 peerInfoCount++
249 want["sentinel_peer_info"] = true
250 }
251 for k := range want {
252 if k == "sentinel_peer_info" {
253 continue
254 }
255 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().(descStr, k) {
256 want[k] = true
257 got := &dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.Metricscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#{}
258 m.Writescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Write().(got)
259
260 val := got.GetGaugescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#GetGauge().().GetValuescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Gauge#GetValue().()
261 if int(val) != tst.expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedMetricValue.[k] {
262 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected metric value %d didn't match to reported value %d for test %s", tst.expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedMetricValue.[k], int(val), tst.namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#name.)
263 }
264 }
265 }
266 }
267 if tst.expectedPeerInfoCountscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedPeerInfoCount. > 0 {
268 if peerInfoCount != tst.expectedPeerInfoCountscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedPeerInfoCount. {
269 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("sentinel_peer_info: expected count %d, got %d", tst.expectedPeerInfoCountscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedPeerInfoCount., peerInfoCount)
270 }
271 }
272 for k, found := range want {
273 if k == "sentinel_peer_info" && tst.expectedPeerInfoCountscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSentinelsData#expectedPeerInfoCount. == 0 {
274 continue
275 }
276 if !found {
277 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find metric %s", k)
278 }
279 }
280 })
281 }
282 }
283
284 type sentinelSlavesDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData# struct {
285 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#name. string
286 slaveDetailsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#slaveDetails. []any
287 labelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#labels. []string
288 expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#expectedMetricValue. map[string]int
289 }
290
291 // TestSentinelPeerInfoMetric verifies sentinel_peer_info is emitted with correct labels (no live Sentinel required).
292 func TestSentinelPeerInfoMetricscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelPeerInfoMetric().(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#) {
293 e, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().("redis://localhost:26379", Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test", InclSentinelPeerInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclSentinelPeerInfo.: true})
294 if err != nil {
295 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("NewRedisExporter: %v", err)
296 }
297 // One peer with all labels; one peer with missing "flags" (tests safe map access).
298 sentinelDetails := []any{
299 []any{
300 []byte("name"), []byte("runid-peer1"),
301 []byte("ip"), []byte("10.0.0.1"),
302 []byte("port"), []byte("26379"),
303 []byte("runid"), []byte("runid-peer1"),
304 []byte("flags"), []byte("sentinel"),
305 },
306 []any{
307 []byte("name"), []byte("runid-peer2"),
308 []byte("ip"), []byte("10.0.0.2"),
309 []byte("port"), []byte("26380"),
310 []byte("runid"), []byte("runid-peer2"),
311 // no "flags" key - must not panic, label should be empty
312 },
313 }
314 labels := []string{"mymaster", "127.0.0.1:6379"}
315
316 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#, 16)
317 go func() {
318 e.processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(chM, sentinelDetails, labels...)
319 close(chM)
320 }()
321
322 var peerInfoMetrics []*dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.Metricscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#
323 for m := range chM {
324 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().(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().(), "sentinel_peer_info") {
325 got := &dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.Metricscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#{}
326 _ = m.Writescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Write().(got)
327 peerInfoMetrics = append(peerInfoMetrics, got)
328 }
329 }
330
331 if len(peerInfoMetrics) != 2 {
332 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected 2 sentinel_peer_info metrics, got %d", len(peerInfoMetrics))
333 }
334
335 labelMap := func(metric *dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.Metricscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#) map[string]string {
336 out := make(map[string]string)
337 for _, lp := range metric.GetLabelscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#GetLabel().() {
338 out[lp.GetNamescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/LabelPair#GetName().()] = lp.GetValuescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/LabelPair#GetValue().()
339 }
340 return out
341 }
342
343 // First peer: all labels set
344 l0 := labelMap(peerInfoMetrics[0])
345 if l0["master_name"] != "mymaster" || l0["master_address"] != "127.0.0.1:6379" {
346 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("first peer: wrong master labels: master_name=%q master_address=%q", l0["master_name"], l0["master_address"])
347 }
348 if l0["name"] != "runid-peer1" || l0["ip"] != "10.0.0.1" || l0["port"] != "26379" || l0["runid"] != "runid-peer1" || l0["flags"] != "sentinel" {
349 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("first peer: wrong peer labels: name=%q ip=%q port=%q runid=%q flags=%q", l0["name"], l0["ip"], l0["port"], l0["runid"], l0["flags"])
350 }
351
352 // Second peer: flags missing in input -> must be empty string (no panic)
353 l1 := labelMap(peerInfoMetrics[1])
354 if l1["name"] != "runid-peer2" || l1["ip"] != "10.0.0.2" || l1["port"] != "26380" || l1["runid"] != "runid-peer2" {
355 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("second peer: wrong labels: name=%q ip=%q port=%q runid=%q", l1["name"], l1["ip"], l1["port"], l1["runid"])
356 }
357 if l1["flags"] != "" {
358 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("second peer: expected empty flags when key missing, got %q", l1["flags"])
359 }
360 }
361
362 func TestInclSentinelPeerInfoDisabledscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestInclSentinelPeerInfoDisabled().(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#) {
363 e, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().("redis://localhost:26379", Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"})
364 if err != nil {
365 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("NewRedisExporter: %v", err)
366 }
367 sentinelDetails := []any{
368 []any{
369 []byte("name"), []byte("peer-a"),
370 []byte("ip"), []byte("10.0.0.1"),
371 []byte("port"), []byte("26379"),
372 []byte("runid"), []byte("rid-a"),
373 []byte("flags"), []byte("sentinel"),
374 },
375 }
376 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#, 8)
377 go func() {
378 e.processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(chM, sentinelDetails, "mymaster", "127.0.0.1:6379")
379 close(chM)
380 }()
381 var peerInfo, okSentinels int
382 for m := range chM {
383 ds := 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().()
384 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().(ds, "sentinel_peer_info") {
385 peerInfo++
386 }
387 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().(ds, "sentinel_master_ok_sentinels") {
388 okSentinels++
389 }
390 }
391 if peerInfo != 0 {
392 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected no sentinel_peer_info when InclSentinelPeerInfo is false, got %d", peerInfo)
393 }
394 if okSentinels != 1 {
395 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected sentinel_master_ok_sentinels, got count %d", okSentinels)
396 }
397 }
398
399 func TestSentinelProcessSentinelsWithoutLabelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelProcessSentinelsWithoutLabels().(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#) {
400 e, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().("redis://localhost:26379", Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test", InclSentinelPeerInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclSentinelPeerInfo.: true})
401 if err != nil {
402 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("NewRedisExporter: %v", err)
403 }
404
405 sentinelDetails := []any{
406 []any{
407 []byte("name"), []byte("peer-a"),
408 []byte("ip"), []byte("10.0.0.1"),
409 []byte("port"), []byte("26379"),
410 []byte("runid"), []byte("rid-a"),
411 []byte("flags"), []byte("sentinel"),
412 },
413 }
414
415 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#, 8)
416 go func() {
417 e.processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(chM, sentinelDetails)
418 close(chM)
419 }()
420
421 gotAny := false
422 for range chM {
423 gotAny = true
424 }
425
426 if gotAny {
427 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected no sentinel metrics when labels are missing")
428 }
429 }
430
431 func TestSentinelProcessSlavesWithoutLabelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelProcessSlavesWithoutLabels().(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#) {
432 e, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().("redis://localhost:26379", Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"})
433 if err != nil {
434 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("NewRedisExporter: %v", err)
435 }
436
437 slaveDetails := []any{
438 []any{
439 []byte("name"), []byte("172.17.0.3:6379"),
440 []byte("ip"), []byte("172.17.0.3"),
441 []byte("port"), []byte("6379"),
442 []byte("runid"), []byte("rid-a"),
443 []byte("flags"), []byte("slave"),
444 },
445 }
446
447 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#, 8)
448 go func() {
449 e.processSentinelSlavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSlaves().(chM, slaveDetails)
450 close(chM)
451 }()
452
453 gotAny := false
454 for range chM {
455 gotAny = true
456 }
457
458 if gotAny {
459 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected no slave metrics when labels are missing")
460 }
461 }
462
463 func TestSentinelProcessSlavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelProcessSlaves().(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#) {
464 if 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_VALKEY_SENTINEL_URI") == "" {
465 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
466 }
467 addr := 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_VALKEY_SENTINEL_URI")
468 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
469 addr,
470 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"},
471 )
472 zeroOkSlaveExpectedMetricValue := map[string]int{
473 "sentinel_master_ok_slaves": 0,
474 }
475 oneOkSlaveExpectedMetricValue := map[string]int{
476 "sentinel_master_ok_slaves": 1,
477 }
478 twoOkSlaveExpectedMetricValue := map[string]int{
479 "sentinel_master_ok_slaves": 2,
480 }
481
482 tsts := []sentinelSlavesDatascip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#{
483 {"0/1 okay slave(string is not byte slice)", []any{[]any{[]string{"name"}, []byte("172.17.0.3:6379"), []byte("ip"), []byte("172.17.0.3"), []byte("port"), []byte("6379"), []byte("runid"), []byte("42ebb784f2bd560903de9fb7d4533263d5db558a"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("0"), []byte("last-ok-ping-reply"), []byte("490"), []byte("last-ping-reply"), []byte("490"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("2636"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("48279581"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("765829")}}, []string{"mymaster", "172.17.0.7:26379"}, zeroOkSlaveExpectedMetricValue},
484 {"1/1 okay slave", []any{[]any{[]byte("name"), []byte("172.17.0.3:6379"), []byte("ip"), []byte("172.17.0.3"), []byte("port"), []byte("6379"), []byte("runid"), []byte("42ebb784f2bd560903de9fb7d4533263d5db558a"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("0"), []byte("last-ok-ping-reply"), []byte("490"), []byte("last-ping-reply"), []byte("490"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("2636"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("48279581"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("765829")}}, []string{"mymaster", "172.17.0.7:26379"}, oneOkSlaveExpectedMetricValue},
485 {"1/3 okay slave", []any{[]any{[]byte("name"), []byte("172.17.0.6:6379"), []byte("ip"), []byte("172.17.0.6"), []byte("port"), []byte("6379"), []byte("runid"), []byte("254576b435fcd73121a6497d3b03f3a464de9a10"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("last-ok-ping-reply"), []byte("1021"), []byte("last-ping-reply"), []byte("1021"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6293"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36490"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.3:6379"), []byte("ip"), []byte("172.17.0.3"), []byte("port"), []byte("6379"), []byte("runid"), []byte("42ebb784f2bd560903de9fb7d4533263d5db558a"), []byte("flags"), []byte("s_down,slave"), []byte("link-pending-commands"), []byte("0"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("0"), []byte("last-ok-ping-reply"), []byte("655"), []byte("last-ping-reply"), []byte("655"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6394"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("56525539"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.5:6379"), []byte("ip"), []byte("172.17.0.5"), []byte("port"), []byte("6379"), []byte("runid"), []byte("8f4b14e820fab7b38cad640208803dfb9fa225ca"), []byte("flags"), []byte("o_down,s_down,slave"), []byte("link-pending-commands"), []byte("100"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("23792"), []byte("last-ok-ping-reply"), []byte("23902"), []byte("last-ping-reply"), []byte("23902"), []byte("s-down-time"), []byte("18785"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("26352"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36493"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("redis-master"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1315493")}}, []string{"mymaster", "172.17.0.7:26379"}, oneOkSlaveExpectedMetricValue},
486 {"2/3 okay slave", []any{[]any{[]byte("name"), []byte("172.17.0.6:6379"), []byte("ip"), []byte("172.17.0.6"), []byte("port"), []byte("6379"), []byte("runid"), []byte("254576b435fcd73121a6497d3b03f3a464de9a10"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("last-ok-ping-reply"), []byte("1021"), []byte("last-ping-reply"), []byte("1021"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6293"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36490"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.3:6379"), []byte("ip"), []byte("172.17.0.3"), []byte("port"), []byte("6379"), []byte("runid"), []byte("42ebb784f2bd560903de9fb7d4533263d5db558a"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("0"), []byte("last-ok-ping-reply"), []byte("655"), []byte("last-ping-reply"), []byte("655"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6394"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("56525539"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.5:6379"), []byte("ip"), []byte("172.17.0.5"), []byte("port"), []byte("6379"), []byte("runid"), []byte("8f4b14e820fab7b38cad640208803dfb9fa225ca"), []byte("flags"), []byte("s_down,slave"), []byte("link-pending-commands"), []byte("100"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("23792"), []byte("last-ok-ping-reply"), []byte("23902"), []byte("last-ping-reply"), []byte("23902"), []byte("s-down-time"), []byte("18785"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("26352"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36493"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("redis-master"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1315493")}}, []string{"mymaster", "172.17.0.7:26379"}, twoOkSlaveExpectedMetricValue},
487 {"2/3 okay slave(missing flags)", []any{[]any{[]byte("name"), []byte("172.17.0.6:6379"), []byte("ip"), []byte("172.17.0.6"), []byte("port"), []byte("6379"), []byte("runid"), []byte("254576b435fcd73121a6497d3b03f3a464de9a10"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("last-ok-ping-reply"), []byte("1021"), []byte("last-ping-reply"), []byte("1021"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6293"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36490"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.3:6379"), []byte("ip"), []byte("172.17.0.3"), []byte("port"), []byte("6379"), []byte("runid"), []byte("42ebb784f2bd560903de9fb7d4533263d5db558a"), []byte("flags"), []byte("slave"), []byte("link-pending-commands"), []byte("0"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("0"), []byte("last-ok-ping-reply"), []byte("655"), []byte("last-ping-reply"), []byte("655"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("6394"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("56525539"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("172.17.0.2"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1316759")}, []any{[]byte("name"), []byte("172.17.0.5:6379"), []byte("ip"), []byte("172.17.0.5"), []byte("port"), []byte("6379"), []byte("runid"), []byte("8f4b14e820fab7b38cad640208803dfb9fa225ca"), []byte("link-pending-commands"), []byte("100"), []byte("link-refcount"), []byte("1"), []byte("last-ping-sent"), []byte("23792"), []byte("last-ok-ping-reply"), []byte("23902"), []byte("last-ping-reply"), []byte("23902"), []byte("s-down-time"), []byte("18785"), []byte("down-after-milliseconds"), []byte("5000"), []byte("info-refresh"), []byte("26352"), []byte("role-reported"), []byte("slave"), []byte("role-reported-time"), []byte("36493"), []byte("master-link-down-time"), []byte("0"), []byte("master-link-status"), []byte("ok"), []byte("master-host"), []byte("redis-master"), []byte("master-port"), []byte("6379"), []byte("slave-priority"), []byte("100"), []byte("slave-repl-offset"), []byte("1315493")}}, []string{"mymaster", "172.17.0.7:26379"}, twoOkSlaveExpectedMetricValue},
488 }
489 for _, tst := range tsts {
490 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tst.namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#name., func(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#) {
491 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#)
492 go func() {
493 e.processSentinelSlavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSlaves().(chM, tst.slaveDetailsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#slaveDetails., tst.labelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#labels....)
494 close(chM)
495 }()
496 want := map[string]bool{
497 "sentinel_master_ok_slaves": false,
498 }
499
500 for m := range chM {
501 for k := range want {
502 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().(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().(), k) {
503 want[k] = true
504 got := &dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.Metricscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#{}
505 m.Writescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Write().(got)
506
507 val := got.GetGaugescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Metric#GetGauge().().GetValuescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/Gauge#GetValue().()
508 if int(val) != tst.expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#expectedMetricValue.[k] {
509 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected metric value %d didn't match to reported value %d for test %s", tst.expectedMetricValuescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#expectedMetricValue.[k], int(val), tst.namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/sentinelSlavesData#name.)
510 }
511 }
512 }
513 }
514 for k, found := range want {
515 if !found {
516 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find metric %s", k)
517 }
518 }
519 })
520 }
521 }
522
523 func TestSentinelScrapeRedisHostSentinelPathscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelScrapeRedisHostSentinelPath().(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#) {
524 if 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_VALKEY_SENTINEL_URI") == "" {
525 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
526 }
527 addr := 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_VALKEY_SENTINEL_URI")
528 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
529 addr,
530 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test"},
531 )
532
533 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#, 1000)
534 go func() {
535 e.scrapeRedisHostscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#scrapeRedisHost().(chM)
536 close(chM)
537 }()
538
539 found := false
540 for m := range chM {
541 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().(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().(), "sentinel") {
542 found = true
543 break
544 }
545 }
546
547 if !found {
548 t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("Expected to find sentinel metrics when scraping sentinel host via scrapeRedisHost()")
549 }
550 }
551
552 func TestSentinelScrapeAllConfigscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestSentinelScrapeAllConfig().(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#) {
553 if 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_VALKEY_SENTINEL_URI") == "" {
554 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY_SENTINEL_URI not set - skipping")
555 }
556 addr := 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_VALKEY_SENTINEL_URI")
557 for _, inc := range []bool{false, true} {
558 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
559 addr,
560 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test",
561 InclConfigMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclConfigMetrics.: inc,
562 },
563 )
564
565 ts := httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/NewServer().(e)
566 defer ts.Closescip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/Server#Close().()
567
568 body := downloadURLscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/downloadURL().(t, ts.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/Server#URL.+"/metrics")
569 for _, want := range []string{
570 "sentinel_config_key_value",
571 "sentinel_config_value",
572 } {
573 if inc && !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().(body, want) {
574 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("didn't find metrics with sentinel_config, want: %s, body: %s", want, body)
575 return
576 } else if !inc && 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().(body, want) {
577 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("did NOT want metrics to include sentinel_config, have:\n%s", body)
578 }
579 }
580 }
581 }