Skip to content

Commit 7c67aab

Browse files
committed
Fixes #3. Handle consumer group numbers
1 parent b60f20d commit 7c67aab

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

collector/collector.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package collector
22

33
import (
4+
"strconv"
5+
46
"github.com/google-cloud-tools/kafka-minion/options"
57
"github.com/google-cloud-tools/kafka-minion/storage"
68
"github.com/prometheus/client_golang/prometheus"
79
log "github.com/sirupsen/logrus"
8-
"strconv"
910
)
1011

1112
var (
@@ -376,5 +377,10 @@ func parseVersion(groupName string, versionString string, digitIndexCursor int)
376377
newVersionedString := lastCharacter + versionString
377378
indexCursor := digitIndexCursor - 1
378379

380+
// If we've got a consumer group name which only has digits, the indexCursor will ultimately be -1
381+
if indexCursor < 0 {
382+
return 0, groupName
383+
}
384+
379385
return parseVersion(groupName, newVersionedString, indexCursor)
380386
}

collector/collector_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package collector
22

33
import (
4-
"github.com/google-cloud-tools/kafka-minion/storage"
54
"testing"
5+
6+
"github.com/google-cloud-tools/kafka-minion/storage"
67
)
78

89
func TestGetVersionedConsumerGroups(t *testing.T) {
@@ -49,6 +50,13 @@ func TestGetVersionedConsumerGroups(t *testing.T) {
4950
Offset: 936,
5051
Timestamp: 1552723003485,
5152
}
53+
offsets["nongroupedconsumer"] = storage.ConsumerPartitionOffsetMetric{
54+
Group: "nongroupedconsumer",
55+
Topic: "important-topic",
56+
Partition: 0,
57+
Offset: 936,
58+
Timestamp: 1552723003485,
59+
}
5260

5361
tables := []struct {
5462
groupName string
@@ -89,9 +97,10 @@ func TestParseConsumerGroupName(t *testing.T) {
8997
baseName string
9098
isLatest bool
9199
}{
92-
{"sample-group-2", 2, "sample-group", false},
93-
{"sample-group-3", 3, "sample-group", false},
100+
{"sample-group-2", 2, "sample-group-", false},
101+
{"sample-group-3", 3, "sample-group-", false},
94102
{"another-group", 0, "another-group", false},
103+
{"14", 0, "14", false},
95104
}
96105
for _, table := range tables {
97106
versioned := parseConsumerGroupName(table.groupName)

0 commit comments

Comments
 (0)