Debian Codegraph @

exporter/streams_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 "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/"
5 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
6 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
7 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
8
9 "github.com/gomodule/redigo/redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/"
10 "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/"
11 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/ "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/"
12 )
13
14 type scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture# struct {
15 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name. string
16 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream. string
17 streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo. streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#
18 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups. []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#
19 consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers. []streamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#
20 }
21
22 var (
23 TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps. = []string{
24 "1638006862416-0",
25 "1638006862417-2",
26 }
27 )
28
29 func isNotTestTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/isNotTestTimestamp().(returned string) bool {
30 for _, expected := range TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps. {
31 if parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(expected) == parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(returned) {
32 return false
33 }
34 }
35 return true
36 }
37
38 func TestStreamsGetStreamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsGetStreamInfo().(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#) {
39 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_REDIS6_URI") == "" {
40 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS6_URI not set - skipping")
41 }
42
43 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_REDIS6_URI")
44 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)
45 if err != nil {
46 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
47 }
48 defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
49
50 setupTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/setupTestKeys().(t, addr)
51 defer deleteTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteTestKeys().(t, addr)
52
53 if _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("SELECT", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.); err != nil {
54 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Couldn't select database %#v", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.)
55 }
56
57 tsts := []scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#{
58 {
59 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Stream test",
60 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: TestKeyNameStreamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestKeyNameStream.,
61 streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo.: streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#{
62 Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length.: 2,
63 RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys.: 1,
64 RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes.: 2,
65 Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups.: 2,
66 },
67 },
68 }
69
70 for _, tst := range tsts {
71 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`/scanStreamFixture#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#) {
72 info, err := getStreamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/getStreamInfo().(c, tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.)
73 if err != nil {
74 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Error getting stream info for %#v: %s", tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream., err)
75 }
76
77 if info.Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length. {
78 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream length mismatch.\nActual: %#v \nExpected: %#v", info.Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length.)
79 }
80 if info.RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys. {
81 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream RadixTreeKeys mismatch.\nActual: %#v \nExpected: %#v", info.RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys.)
82 }
83 if info.RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes. {
84 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream RadixTreeNodes mismatch.\nActual: %#v \nExpected: %#v", info.RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes.)
85 }
86 if info.Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups. {
87 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream Groups mismatch.\nActual: %#v \nExpected: %#v", info.Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups.)
88 }
89 if isNotTestTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/isNotTestTimestamp().(info.LastGeneratedIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastGeneratedId.) {
90 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream LastGeneratedId mismatch.\nActual: %#v \nExpected any of: %#v", info.LastGeneratedIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastGeneratedId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
91 }
92 if info.FirstEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#FirstEntryId. != TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.[0] {
93 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream FirstEntryId mismatch.\nActual: %#v \nExpected any of: %#v", info.FirstEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#FirstEntryId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
94 }
95 if info.LastEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastEntryId. != TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.[len(TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)-1] {
96 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream LastEntryId mismatch.\nActual: %#v \nExpected any of: %#v", info.LastEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastEntryId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
97 }
98 if info.MaxDeletedEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#MaxDeletedEntryId. != "" {
99 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream MaxDeletedEntryId mismatch.\nActual: %#v \nExpected: %#v", info.MaxDeletedEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#MaxDeletedEntryId., "0-0")
100 }
101 })
102 }
103 }
104
105 func TestStreamsGetStreamInfoUsingValKey7scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsGetStreamInfoUsingValKey7().(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#) {
106 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_VALKEY7_URI") == "" {
107 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY7_URI not set - skipping")
108 }
109
110 addr := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(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_VALKEY7_URI"), "valkey://", "redis://", 1)
111 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)
112 if err != nil {
113 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
114 }
115 defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
116
117 setupTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/setupTestKeys().(t, addr)
118 defer deleteTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteTestKeys().(t, addr)
119
120 if _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("SELECT", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.); err != nil {
121 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Couldn't select database %#v", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.)
122 }
123
124 tsts := []scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#{
125 {
126 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Stream test",
127 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: TestKeyNameStreamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestKeyNameStream.,
128 streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo.: streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#{
129 Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length.: 2,
130 RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys.: 1,
131 RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes.: 2,
132 Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups.: 2,
133 },
134 },
135 }
136
137 for _, tst := range tsts {
138 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`/scanStreamFixture#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#) {
139 info, err := getStreamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/getStreamInfo().(c, tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.)
140 if err != nil {
141 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Error getting stream info for %#v: %s", tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream., err)
142 }
143
144 if info.Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length. {
145 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream length mismatch.\nActual: %#v \nExpected: %#v", info.Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Lengthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Length.)
146 }
147 if info.RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys. {
148 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream RadixTreeKeys mismatch.\nActual: %#v \nExpected: %#v", info.RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeKeys.)
149 }
150 if info.RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes. {
151 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream RadixTreeNodes mismatch.\nActual: %#v \nExpected: %#v", info.RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..RadixTreeNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#RadixTreeNodes.)
152 }
153 if info.Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups. != tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups. {
154 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream Groups mismatch.\nActual: %#v \nExpected: %#v", info.Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups., tst.streamInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#streamInfo..Groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#Groups.)
155 }
156 if isNotTestTimestampscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/isNotTestTimestamp().(info.LastGeneratedIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastGeneratedId.) {
157 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream LastGeneratedId mismatch.\nActual: %#v \nExpected any of: %#v", info.LastGeneratedIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastGeneratedId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
158 }
159 if info.FirstEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#FirstEntryId. != TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.[0] {
160 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream FirstEntryId mismatch.\nActual: %#v \nExpected any of: %#v", info.FirstEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#FirstEntryId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
161 }
162 if info.LastEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastEntryId. != TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.[len(TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)-1] {
163 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream LastEntryId mismatch.\nActual: %#v \nExpected any of: %#v", info.LastEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#LastEntryId., TestStreamTimestampsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamTimestamps.)
164 }
165 if info.MaxDeletedEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#MaxDeletedEntryId. != "0-0" {
166 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Stream MaxDeletedEntryId mismatch.\nActual: %#v \nExpected: %#v", info.MaxDeletedEntryIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamInfo#MaxDeletedEntryId., "0-0")
167 }
168 })
169 }
170 }
171
172 func TestStreamsScanStreamGroups123scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsScanStreamGroups123().(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#) {
173 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_REDIS6_URI") == "" {
174 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS6_URI not set - skipping")
175 }
176 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_REDIS6_URI")
177
178 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)
179 if err != nil {
180 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
181 }
182
183 if _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("SELECT", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.); err != nil {
184 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Couldn't select database %#v", dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.)
185 }
186
187 fixtures := []keyFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/keyFixture#{
188 {"XADD", "test_stream_1", []any{"1638006862521-0", "field_1", "str_1"}},
189 {"XADD", "test_stream_2", []any{"1638006862522-0", "field_pattern_1", "str_pattern_1"}},
190 }
191 // Create test streams
192 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_1", "test_group_1", "$", "MKSTREAM")
193 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_2", "test_group_1", "$", "MKSTREAM")
194 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_2", "test_group_2", "$")
195
196 // Add simple values
197 defer func() {
198 deleteKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteKeyFixtures().(t, c, fixtures)
199 c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
200 }()
201 createKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/createKeyFixtures().(t, c, fixtures)
202
203 // Process messages to assign Consumers to their groups
204 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "test_stream_1", ">")
205 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "test_stream_2", ">")
206 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_2", "COUNT", "1", "STREAMS", "test_stream_2", "0")
207
208 tsts := []scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#{
209 {
210 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Single group test",
211 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "test_stream_1",
212 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{
213 {
214 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1",
215 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 1,
216 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 1,
217 EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.: 0,
218 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 0,
219 LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.: "1638006862521-0",
220 StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.: []streamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#{
221 {
222 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.: "test_consumer_1",
223 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.: 1,
224 },
225 },
226 },
227 }},
228 {
229 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Multiple groups test",
230 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "test_stream_2",
231 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{
232 {
233 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1",
234 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 2,
235 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 1,
236 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 0,
237 EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.: 0,
238 LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.: "1638006862522-0",
239 },
240 {
241 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_2",
242 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 0,
243 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 0,
244 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 0,
245 },
246 }},
247 }
248 for _, tst := range tsts {
249 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`/scanStreamFixture#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#) {
250 scannedGroup, err := scanStreamGroupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamGroups().(c, tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.)
251 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("scanStreamGroups() err: %s", err)
252 if err != nil {
253 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Err: %s", err)
254 return
255 }
256
257 if len(scannedGroup) == len(tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.) {
258 for i := range scannedGroup {
259 if scannedGroup[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name. {
260 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) Group name mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name., scannedGroup[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.)
261 }
262 if scannedGroup[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers. {
263 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) Consumers count mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers., scannedGroup[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.)
264 }
265 if scannedGroup[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending. {
266 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) Pending items mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending., scannedGroup[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.)
267 }
268 if parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(scannedGroup[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.) != parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.) {
269 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) LastDeliveredId items mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId., scannedGroup[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.)
270 }
271 if scannedGroup[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag. {
272 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) Lag mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag., scannedGroup[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.)
273 }
274 if scannedGroup[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead. {
275 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d) EntriesRead mismatch.\nExpected: %#v \nActual: %#v", i, tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead., scannedGroup[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.)
276 }
277 }
278 } else {
279 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Consumers entries mismatch.\nExpected: %d\nActual: %d", len(tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.), len(scannedGroup))
280 }
281 })
282 }
283 }
284
285 func TestStreamsScanStreamGroupsUsingValKey7scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsScanStreamGroupsUsingValKey7().(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#) {
286 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_VALKEY7_URI") == "" {
287 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_VALKEY7_URI not set - skipping")
288 }
289 addr := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(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_VALKEY7_URI"), "valkey://", "redis://", 1)
290 db := dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.
291
292 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)
293 if err != nil {
294 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
295 }
296
297 if _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("SELECT", db); err != nil {
298 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Couldn't select database %#v", db)
299 }
300
301 fixtures := []keyFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/keyFixture#{
302 {"XADD", "test_stream_1", []any{"1638006862521-0", "field_1", "str_1"}},
303 {"XADD", "test_stream_2", []any{"1638006862522-0", "field_pattern_1", "str_pattern_1"}},
304 }
305
306 // Create test streams
307 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_1", "test_group_1", "$", "MKSTREAM")
308 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_2", "test_group_1", "$", "MKSTREAM")
309 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "test_stream_2", "test_group_2", "$")
310
311 // Add simple values
312 defer func() {
313 deleteKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteKeyFixtures().(t, c, fixtures)
314 c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
315 }()
316 createKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/createKeyFixtures().(t, c, fixtures)
317
318 // Process messages to assign Consumers to their groups
319 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "test_stream_1", ">")
320 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "test_stream_2", ">")
321 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_2", "COUNT", "1", "STREAMS", "test_stream_2", "0")
322
323 tsts := []scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#{
324 {
325 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Single group test",
326 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "test_stream_1",
327 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{
328 {
329 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1",
330 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 1,
331 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 1,
332 EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.: 1,
333 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 0,
334 LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.: "1638006862521-0",
335 StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.: []streamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#{
336 {
337 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.: "test_consumer_1",
338 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.: 1,
339 },
340 },
341 },
342 }},
343 {
344 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Multiple groups test",
345 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "test_stream_2",
346 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{
347 {
348 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1",
349 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 2,
350 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 1,
351 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 0,
352 EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.: 1,
353 LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.: "1638006862522-0",
354 },
355 {
356 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_2",
357 Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.: 0,
358 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.: 0,
359 Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.: 1,
360 },
361 }},
362 }
363 for _, tst := range tsts {
364 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`/scanStreamFixture#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#) {
365 scannedGroup, err := scanStreamGroupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamGroups().(c, tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.)
366 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("scanStreamGroups() err: %s", err)
367 if err != nil {
368 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Err: %s", err)
369 }
370
371 if len(scannedGroup) == len(tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.) {
372 for i := range scannedGroup {
373 if scannedGroup[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name. {
374 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Group name mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name., scannedGroup[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.)
375 }
376 if scannedGroup[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers. {
377 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Consumers count mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers., scannedGroup[i].Consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Consumers.)
378 }
379 if scannedGroup[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending. {
380 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Pending items mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending., scannedGroup[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Pending.)
381 }
382 if parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(scannedGroup[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.) != parseStreamItemIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseStreamItemId().(tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.) {
383 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("LastDeliveredId items mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId., scannedGroup[i].LastDeliveredIdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#LastDeliveredId.)
384 }
385 if scannedGroup[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag. {
386 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Lag mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag., scannedGroup[i].Lagscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Lag.)
387 }
388 if scannedGroup[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead. != tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead. {
389 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("EntriesRead mismatch.\nExpected: %#v \nActual: %#v", tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead., scannedGroup[i].EntriesReadscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#EntriesRead.)
390 }
391 }
392 } else {
393 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Consumers entries mismatch.\nExpected: %d\nActual: %d", len(tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.), len(scannedGroup))
394 }
395 })
396 }
397 }
398
399 func TestStreamsScanStreamGroupsConsumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsScanStreamGroupsConsumers().(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 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") == "" {
401 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS_URI not set - skipping")
402 }
403 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")
404 db := dbNumStrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStr.
405
406 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)
407 if err != nil {
408 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
409 }
410
411 if _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("SELECT", db); err != nil {
412 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Couldn't select database %#v", db)
413 }
414
415 fixtures := []keyFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/keyFixture#{
416 {"XADD", "single_consumer_stream", []any{"*", "field_1", "str_1"}},
417 {"XADD", "multiple_consumer_stream", []any{"*", "field_pattern_1", "str_pattern_1"}},
418 }
419
420 // Create test streams
421 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "single_consumer_stream", "test_group_1", "$", "MKSTREAM")
422 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XGROUP", "CREATE", "multiple_consumer_stream", "test_group_1", "$", "MKSTREAM")
423
424 // Add simple test items to streams
425 defer func() {
426 deleteKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteKeyFixtures().(t, c, fixtures)
427 c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
428 }()
429 createKeyFixturesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/createKeyFixtures().(t, c, fixtures)
430
431 // Process messages to assign Consumers to their groups
432 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "single_consumer_stream", ">")
433 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", "multiple_consumer_stream", ">")
434 c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XREADGROUP", "GROUP", "test_group_1", "test_consumer_2", "COUNT", "1", "STREAMS", "multiple_consumer_stream", "0")
435
436 tsts := []scanStreamFixturescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#{
437 {
438 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Single group test",
439 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "single_consumer_stream",
440 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{{Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1"}},
441 consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.: []streamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#{
442 {
443 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.: "test_consumer_1",
444 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.: 1,
445 },
446 },
447 },
448 {
449 namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#name.: "Multiple consumers test",
450 streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream.: "multiple_consumer_stream",
451 groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups.: []streamGroupsInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#{{Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.: "test_group_1"}},
452 consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.: []streamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#{
453 {
454 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.: "test_consumer_1",
455 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.: 1,
456 },
457 {
458 Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.: "test_consumer_2",
459 Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.: 0,
460 },
461 },
462 },
463 }
464
465 for _, tst := range tsts {
466 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`/scanStreamFixture#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#) {
467
468 // For each group
469 for _, g := range tst.groupsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#groups. {
470 g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo., err = scanStreamGroupConsumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamGroupConsumers().(c, tst.streamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#stream., g.Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#Name.)
471 if err != nil {
472 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Err: %s", err)
473 }
474 if len(g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.) == len(tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.) {
475 for i := range g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo. {
476 if g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name. != tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name. {
477 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Consumer name mismatch.\nExpected: %#v \nActual: %#v", tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name., g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name.)
478 }
479 if g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending. != tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending. {
480 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Pending items mismatch for %s.\nExpected: %#v \nActual: %#v", g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.[i].Namescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Name., tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending., g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.[i].Pendingscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupConsumersInfo#Pending.)
481 }
482
483 }
484 } else {
485 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Consumers entries mismatch.\nExpected: %d\nActual: %d", len(tst.consumersscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/scanStreamFixture#consumers.), len(g.StreamGroupConsumersInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/streamGroupsInfo#StreamGroupConsumersInfo.))
486 }
487 }
488
489 })
490 }
491 }
492
493 func TestStreamsExtractStreamMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsExtractStreamMetrics().(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#) {
494 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") == "" {
495 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS_URI not set - skipping")
496 }
497 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")
498 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
499 addr,
500 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", CheckSingleStreamsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckSingleStreams.: dbNumStrFullscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStrFull. + "=" + TestKeyNameStreamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestKeyNameStream.},
501 )
502 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)
503 if err != nil {
504 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
505 }
506
507 setupTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/setupTestKeys().(t, addr)
508 defer deleteTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteTestKeys().(t, addr)
509
510 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#)
511 go func() {
512 e.extractStreamMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractStreamMetrics().(chM, c)
513 close(chM)
514 }()
515 want := map[string]bool{
516 "stream_length": false,
517 "stream_radix_tree_keys": false,
518 "stream_radix_tree_nodes": false,
519 "stream_last_generated_id": false,
520 "stream_groups": false,
521 "stream_max_deleted_entry_id": false,
522 "stream_first_entry_id": false,
523 "stream_last_entry_id": false,
524 "stream_group_consumers": false,
525 "stream_group_messages_pending": false,
526 "stream_group_last_delivered_id": false,
527 "stream_group_entries_read": false,
528 "stream_group_lag": false,
529 "stream_group_consumer_messages_pending": false,
530 "stream_group_consumer_idle_seconds": false,
531 }
532
533 for m := range chM {
534 for k := range want {
535 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("metric: %s", 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().())
536 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("want: %s", k)
537
538 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) {
539 want[k] = true
540 }
541 }
542 }
543 for k, found := range want {
544 if !found {
545 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find %s", k)
546 }
547
548 }
549 }
550
551 func TestStreamsExtractStreamMetricsExcludeConsumerscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestStreamsExtractStreamMetricsExcludeConsumer().(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#) {
552 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") == "" {
553 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS_URI not set - skipping")
554 }
555 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")
556 e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
557 addr,
558 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", CheckSingleStreamsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckSingleStreams.: dbNumStrFullscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/dbNumStrFull. + "=" + TestKeyNameStreamscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestKeyNameStream., StreamsExcludeConsumerMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#StreamsExcludeConsumerMetrics.: true},
559 )
560 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)
561 if err != nil {
562 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to %#v: %#v", addr, err)
563 }
564
565 setupTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/setupTestKeys().(t, addr)
566 defer deleteTestKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/deleteTestKeys().(t, addr)
567
568 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#)
569 go func() {
570 e.extractStreamMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractStreamMetrics().(chM, c)
571 close(chM)
572 }()
573 want := map[string]bool{
574 "stream_length": false,
575 "stream_radix_tree_keys": false,
576 "stream_radix_tree_nodes": false,
577 "stream_last_generated_id": false,
578 "stream_groups": false,
579 "stream_max_deleted_entry_id": false,
580 "stream_first_entry_id": false,
581 "stream_last_entry_id": false,
582 "stream_group_consumers": false,
583 "stream_group_messages_pending": false,
584 "stream_group_last_delivered_id": false,
585 "stream_group_entries_read": false,
586 "stream_group_lag": false,
587 }
588
589 dontWant := map[string]bool{
590 "stream_group_consumer_messages_pending": false,
591 "stream_group_consumer_idle_seconds": false,
592 }
593
594 for m := range chM {
595 for k := range want {
596 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("metric: %s", 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().())
597 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("want: %s", k)
598
599 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) {
600 want[k] = true
601 }
602 }
603 for k := range dontWant {
604 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("metric: %s", 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().())
605 logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("don't want: %s", k)
606
607 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) {
608 dontWant[k] = true
609 }
610 }
611 }
612
613 for k, found := range want {
614 if !found {
615 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("didn't find %s metric, which should be collected", k)
616 }
617 }
618 for k, found := range dontWant {
619 if found {
620 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("found %s metric, which shouldn't be collected", k)
621 }
622 }
623 }
624
625 func TestClusterStreamMetricsExtractionscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestClusterStreamMetricsExtraction().(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#) {
626 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_CLUSTER_MASTER_URI") == "" {
627 t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_REDIS_CLUSTER_MASTER_URI not set - skipping cluster stream test")
628 }
629
630 clusterURI := 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_CLUSTER_MASTER_URI")
631
632 // Test streams to create
633 testStreams := []string{"audit_stream", "sa_audit_stream", "test_stream_cluster"}
634
635 // Setup cluster connection to create test streams
636 // Use cluster-aware connection to avoid MOVED errors
637 tempExporter, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(clusterURI, Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{IsClusterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#IsCluster.: true})
638 if err != nil {
639 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't create temp exporter for cluster setup: %v", err)
640 }
641
642 c, err := tempExporter.connectToRedisClusterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#connectToRedisCluster().()
643 if err != nil {
644 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Couldn't connect to cluster: %v", err)
645 }
646 defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().()
647
648 // Create test streams with some data using cluster connection
649 for _, streamName := range testStreams {
650 // Add entries to streams - cluster connection handles MOVED redirects automatically
651 _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XADD", streamName, "*", "field1", "value1", "field2", "value2")
652 if err != nil {
653 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Warning: couldn't create stream %s: %v", streamName, err)
654 continue
655 }
656 _, err = c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("XADD", streamName, "*", "field3", "value3")
657 if err != nil {
658 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Warning: couldn't add to stream %s: %v", streamName, err)
659 }
660 }
661
662 // Cleanup function - use the same cluster connection to avoid MOVED errors
663 defer func() {
664 for _, streamName := range testStreams {
665 _, err := c.Doscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Do().("DEL", streamName)
666 if err != nil {
667 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Warning: couldn't clean up stream %s: %v", streamName, err)
668 }
669 }
670 }()
671
672 // Create exporter with cluster mode and single streams config
673 // This reproduces the exact command from the GitHub issue:
674 // redis_exporter --check-single-streams=audit,sa_audit --is-cluster=true
675 streamConfig := "db0=audit_stream,db0=sa_audit_stream,db0=test_stream_cluster"
676
677 e, err := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(
678 clusterURI,
679 Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{
680 Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test",
681 CheckSingleStreamsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckSingleStreams.: streamConfig,
682 IsClusterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#IsCluster.: true,
683 },
684 )
685 if err != nil {
686 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("NewRedisExporter() err: %s", err)
687 }
688
689 // Test the full HTTP endpoint (this tests the complete path including cluster connection fix)
690 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)
691 defer ts.Closescip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/Server#Close().()
692
693 metricsOutput := 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")
694
695 // Check if we got HTML instead of metrics (indicates an error during metrics collection)
696 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().(metricsOutput, "<html>") {
697 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Got HTML response instead of metrics, this indicates an error during metrics collection")
698 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("This could be due to Redis connection issues or cluster MOVED errors")
699 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("First 500 chars of response: %.500s...", metricsOutput)
700 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("Expected Prometheus metrics but got HTML error page - check Redis cluster connectivity")
701 }
702
703 // Parse the metrics output to find stream metrics
704 foundMetrics := make(map[string]bool)
705 lines := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(metricsOutput, "\n")
706
707 for line := range lines {
708 // Look for stream_length metrics with our test streams
709 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().(line, "stream_length") {
710 for _, streamName := range testStreams {
711 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().(line, `stream="`+streamName+`"`) {
712 foundMetrics[streamName] = true
713 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Found stream metric for: %s", streamName)
714 }
715 }
716 }
717 }
718
719 // Verify that we found metrics for our test streams
720 // This ensures that the cluster MOVED errors are properly handled
721 expectedStreams := 0
722 for _, streamName := range testStreams {
723 if foundMetrics[streamName] {
724 expectedStreams++
725 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("✓ Successfully found metrics for stream: %s", streamName)
726 } else {
727 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("⚠ Did not find metrics for stream: %s", streamName)
728 }
729 }
730
731 if expectedStreams == 0 {
732 t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("Expected to find metrics for at least one test stream in cluster mode")
733 t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("This indicates that the cluster MOVED error fix may not be working properly")
734
735 // Additional debugging info
736 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Test streams created: %v", testStreams)
737 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("Found stream metrics for: %v", foundMetrics)
738
739 // Show sample of metrics output for debugging
740 sampleLines := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(metricsOutput, "\n")
741 t.Logscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Log().("Sample metrics output (first 10 lines):")
742 for i, line := range sampleLines {
743 if i >= 10 || line == "" {
744 break
745 }
746 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().(" %s", line)
747 }
748 } else {
749 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("✓ SUCCESS: Found stream metrics for %d/%d streams in cluster mode", expectedStreams, len(testStreams))
750 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("This confirms that Redis cluster MOVED errors are properly handled for streams")
751 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("HTTP endpoint successfully returned metrics without cluster MOVED errors")
752 }
753 }