diff --git a/exporter/streams.go b/exporter/streams.go index e6d82c2a..7e5dd1ac 100644 --- a/exporter/streams.go +++ b/exporter/streams.go @@ -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 string(vbytes) == "first-entry" { + stream.FirstEntryId = getStreamEntryId(values, idx+1) + } + if string(vbytes) == "last-entry" { + stream.LastEntryId = getStreamEntryId(values, idx+1) + } + } stream.StreamGroupsInfo, err = scanStreamGroups(c, key) if err != nil { @@ -65,7 +75,12 @@ 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 values, ok := redisValue[index].([]interface{}); !ok || len(values) < 2 { + log.Debugf("Failed to parse StreamEntryId") + return "" + } + + if len(redisValue) < index || redisValue[index] == nil { log.Debugf("Failed to parse StreamEntryId") return "" } diff --git a/exporter/streams_test.go b/exporter/streams_test.go index 41746135..8fca1f28 100644 --- a/exporter/streams_test.go +++ b/exporter/streams_test.go @@ -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")