Skip to content

Commit 8f7917e

Browse files
committed
debug logs, misc cleanup
1 parent 1d4eed7 commit 8f7917e

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

exporter/exporter_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var (
3333
keysExpiring []string
3434
listKeys []string
3535
singleStringKey string
36-
ts = int32(time.Now().Unix())
3736

3837
dbNumStr = "11"
3938
altDBNumStr = "12"
@@ -44,6 +43,7 @@ var (
4443
const (
4544
TestSetName = "test-set"
4645
TestStreamName = "test-stream"
46+
TestHllName = "test-hll"
4747
)
4848

4949
func getTestExporter() *Exporter {
@@ -99,6 +99,10 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
9999
}
100100
}
101101

102+
c.Do("PFADD", TestHllName, "val1")
103+
c.Do("PFADD", TestHllName, "val22")
104+
c.Do("PFADD", TestHllName, "val333")
105+
102106
c.Do("SADD", TestSetName, "test-val-1")
103107
c.Do("SADD", TestSetName, "test-val-2")
104108

@@ -109,6 +113,7 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
109113
c.Do("XGROUP", "CREATE", TestStreamName, "test_group_2", "$", "MKSTREAM")
110114
c.Do("XADD", TestStreamName, TestStreamTimestamps[0], "field_1", "str_1")
111115
c.Do("XADD", TestStreamName, TestStreamTimestamps[1], "field_2", "str_2")
116+
112117
// Process messages to assign Consumers to their groups
113118
c.Do("XREADGROUP", "GROUP", "test_group_1", "test_consumer_1", "COUNT", "1", "STREAMS", TestStreamName, ">")
114119
c.Do("XREADGROUP", "GROUP", "test_group_1", "test_consumer_2", "COUNT", "1", "STREAMS", TestStreamName, ">")
@@ -135,6 +140,7 @@ func deleteKeys(c redis.Conn, dbNumStr string) {
135140
c.Do("DEL", key)
136141
}
137142

143+
c.Do("DEL", TestHllName)
138144
c.Do("DEL", TestSetName)
139145
c.Do("DEL", TestStreamName)
140146
c.Do("DEL", singleStringKey)
@@ -450,15 +456,17 @@ func init() {
450456
log.SetLevel(log.InfoLevel)
451457
}
452458

459+
testTimestamp := time.Now().Unix()
460+
453461
for _, n := range []string{"john", "paul", "ringo", "george"} {
454-
keys = append(keys, fmt.Sprintf("key_%s_%d", n, ts))
462+
keys = append(keys, fmt.Sprintf("key_%s_%d", n, testTimestamp))
455463
}
456464

457-
singleStringKey = fmt.Sprintf("key_string_%d", ts)
465+
singleStringKey = fmt.Sprintf("key_string_%d", testTimestamp)
458466

459467
listKeys = append(listKeys, "beatles_list")
460468

461469
for _, n := range []string{"A.J.", "Howie", "Nick", "Kevin", "Brian"} {
462-
keysExpiring = append(keysExpiring, fmt.Sprintf("key_exp_%s_%d", n, ts))
470+
keysExpiring = append(keysExpiring, fmt.Sprintf("key_exp_%s_%d", n, testTimestamp))
463471
}
464472
}

exporter/key_groups_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestKeyGroupMetrics(t *testing.T) {
7171
wantedCount: map[string]int{
7272
"key_ringo": 1,
7373
"key_paul": 1,
74-
"unclassified": 6,
74+
"unclassified": 7,
7575
"key_exp": 5,
7676
},
7777
wantedMemory: map[string]bool{
@@ -92,13 +92,13 @@ func TestKeyGroupMetrics(t *testing.T) {
9292
// updates of the init() function
9393
wantedCount: map[string]int{
9494
"test-stream": 1,
95-
"overflow": 12,
95+
"overflow": 13,
9696
},
9797
wantedMemory: map[string]bool{
9898
"test-stream": true,
9999
"overflow": true,
100100
},
101-
wantedDistintKeyGroups: 13,
101+
wantedDistintKeyGroups: 14,
102102
},
103103
}
104104

exporter/keys.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,26 @@ func getStringInfoPipelined(c redis.Conn, key string) (keyInfo, error) {
5858
//
5959
// STRLEN on HyperLogLog strings returns the wrong length while PFCOUNT only
6060
// works on HLL strings and returns an error on regular strings.
61+
62+
log.Debugf("c.Send() PFCOUNT args: [%v]", key)
6163
if err := c.Send("PFCOUNT", key); err != nil {
6264
return info, err
6365
}
66+
67+
log.Debugf("c.Send() STRLEN args: [%v]", key)
6468
if err := c.Send("STRLEN", key); err != nil {
6569
return info, err
6670
}
71+
72+
log.Debugf("c.Flush()")
6773
if err := c.Flush(); err != nil {
6874
return info, err
6975
}
7076

7177
hllSize, hllErr := redis.Int64(c.Receive())
7278
strSize, strErr := redis.Int64(c.Receive())
79+
log.Debugf("Done with c.Receive() x 2, hllErr: %s strErr: %s", hllErr, strErr)
80+
7381
if hllErr == nil {
7482
// hyperloglog
7583
info.size = float64(hllSize)
@@ -102,7 +110,8 @@ func getKeyInfo(c redis.Conn, key string, isCluster bool) (keyInfo, error) {
102110
return info, errKeyTypeNotFound
103111
case "string":
104112
if isCluster {
105-
// can't pipeline for clusters because redisc doesn't support pipelined calls for clusters
113+
// can't use pipelining for clusters
114+
// because redisc doesn't support pipelined calls for clusters
106115
info, err = getStringInfoNotPipelined(c, key)
107116
} else {
108117
info, err = getStringInfoPipelined(c, key)

exporter/keys_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func TestClusterKeyValuesAndSizes(t *testing.T) {
9797
for _, exc := range []bool{true, false} {
9898
e, _ := NewRedisExporter(
9999
os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI"),
100-
Options{Namespace: "test", DisableExportingKeyValues: exc, CheckSingleKeys: dbNumStrFull + "=" + url.QueryEscape(keys[0]), IsCluster: true},
100+
Options{
101+
Namespace: "test", DisableExportingKeyValues: exc,
102+
CheckSingleKeys: dbNumStrFull + "=" + url.QueryEscape(keys[0]),
103+
IsCluster: true},
101104
)
102105

103106
uri := os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI")
@@ -466,7 +469,6 @@ func TestGetKeysFromPatterns(t *testing.T) {
466469
t.Errorf("Error expected with invalid database %#v, got valid response: %#v", invalidKeys, got)
467470
}
468471
}
469-
470472
}
471473

472474
func TestGetKeyInfo(t *testing.T) {
@@ -486,6 +488,7 @@ func TestGetKeyInfo(t *testing.T) {
486488
{"SET", "key_info_test_string", []interface{}{"Woohoo!"}},
487489
{"HSET", "key_info_test_hash", []interface{}{"hashkey1", "hashval1"}},
488490
{"PFADD", "key_info_test_hll", []interface{}{"hllval1", "hllval2"}},
491+
{"PFADD", "key_info_test_hll2", []interface{}{"hll2val_1", "hll2val_2", "hll2val_3"}},
489492
{"LPUSH", "key_info_test_list", []interface{}{"listval1", "listval2", "listval3"}},
490493
{"SADD", "key_info_test_set", []interface{}{"setval1", "setval2", "setval3", "setval4"}},
491494
{"ZADD", "key_info_test_zset", []interface{}{
@@ -509,6 +512,7 @@ func TestGetKeyInfo(t *testing.T) {
509512
"key_info_test_string": 7,
510513
"key_info_test_hash": 1,
511514
"key_info_test_hll": 2,
515+
"key_info_test_hll2": 3,
512516
"key_info_test_list": 3,
513517
"key_info_test_set": 4,
514518
"key_info_test_zset": 5,

exporter/sentinels.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import (
1010
log "github.com/sirupsen/logrus"
1111
)
1212

13-
func (e *Exporter) handleMetricsSentinel(ch chan<- prometheus.Metric, fieldKey string, fieldValue string) bool {
14-
13+
func (e *Exporter) handleMetricsSentinel(ch chan<- prometheus.Metric, fieldKey string, fieldValue string) {
1514
switch fieldKey {
16-
17-
case "sentinel_masters", "sentinel_tilt", "sentinel_running_scripts", "sentinel_scripts_queue_length", "sentinel_simulate_failure_flags":
15+
case
16+
"sentinel_masters",
17+
"sentinel_tilt",
18+
"sentinel_running_scripts",
19+
"sentinel_scripts_queue_length",
20+
"sentinel_simulate_failure_flags":
1821
val, _ := strconv.Atoi(fieldValue)
1922
e.registerConstMetricGauge(ch, fieldKey, float64(val))
20-
return true
23+
return
2124
}
2225

2326
if masterName, masterStatus, masterAddress, masterSlaves, masterSentinels, ok := parseSentinelMasterString(fieldKey, fieldValue); ok {
@@ -28,10 +31,8 @@ func (e *Exporter) handleMetricsSentinel(ch chan<- prometheus.Metric, fieldKey s
2831
e.registerConstMetricGauge(ch, "sentinel_master_status", masterStatusNum, masterName, masterAddress, masterStatus)
2932
e.registerConstMetricGauge(ch, "sentinel_master_slaves", masterSlaves, masterName, masterAddress)
3033
e.registerConstMetricGauge(ch, "sentinel_master_sentinels", masterSentinels, masterName, masterAddress)
31-
return true
34+
return
3235
}
33-
34-
return false
3536
}
3637

3738
func (e *Exporter) extractSentinelMetrics(ch chan<- prometheus.Metric, c redis.Conn) {

0 commit comments

Comments
 (0)