Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compatible with stream entry id metric for redis version 6.x/5.x. #917

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions exporter/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ func getStreamInfo(c redis.Conn, key string) (*streamInfo, error) {
}

// Extract first and last id from slice
stream.FirstEntryId = getStreamEntryId(values, 17)
stream.LastEntryId = getStreamEntryId(values, 19)
for idx, v := range values {
vbytes, ok := v.([]byte)
if !ok {
continue
}
if strings.EqualFold(string(vbytes), "first-entry") {
gitsang marked this conversation as resolved.
Show resolved Hide resolved
stream.FirstEntryId = getStreamEntryId(values, idx+1)
}
if strings.EqualFold(string(vbytes), "last-entry") {
stream.LastEntryId = getStreamEntryId(values, idx+1)
}
}

stream.StreamGroupsInfo, err = scanStreamGroups(c, key)
if err != nil {
Expand All @@ -65,7 +75,9 @@ func getStreamInfo(c redis.Conn, key string) (*streamInfo, error) {
}

func getStreamEntryId(redisValue []interface{}, index int) string {
if len(redisValue) < index || redisValue[index] == nil || len(redisValue[index].([]interface{})) < 2 {
if _, ok := redisValue[index].([]interface{}); !ok ||
gitsang marked this conversation as resolved.
Show resolved Hide resolved
len(redisValue) < index || redisValue[index] == nil ||
len(redisValue[index].([]interface{})) < 2 {
log.Debugf("Failed to parse StreamEntryId")
return ""
}
Expand Down
8 changes: 4 additions & 4 deletions exporter/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func TestStreamsGetStreamInfo(t *testing.T) {
if isNotTestTimestamp(info.LastGeneratedId) {
t.Errorf("Stream LastGeneratedId mismatch.\nActual: %#v;\nExpected any of: %#v", info.LastGeneratedId, TestStreamTimestamps)
}
if info.FirstEntryId != "" {
t.Errorf("Stream FirstEntryId mismatch.\nActual: %#v; - Expected empty", info.FirstEntryId)
if info.FirstEntryId != TestStreamTimestamps[0] {
t.Errorf("Stream FirstEntryId mismatch.\nActual: %#v;\nExpected any of: %#v", info.FirstEntryId, TestStreamTimestamps)
}
if info.LastEntryId != "" {
t.Errorf("Stream LastEntryId mismatch.\nActual: %#v;\nExpected empty", info.LastEntryId)
if info.LastEntryId != TestStreamTimestamps[len(TestStreamTimestamps)-1] {
t.Errorf("Stream LastEntryId mismatch.\nActual: %#v;\nExpected any of: %#v", info.LastEntryId, TestStreamTimestamps)
}
if info.MaxDeletedEntryId != "" {
t.Errorf("Stream MaxDeletedEntryId mismatch.\nActual: %#v;\nExpected: %#v", info.MaxDeletedEntryId, "0-0")
Expand Down
Loading