Skip to content

Commit 66f9e36

Browse files
authored
fix: add server side backed up metrics (#1493)
* fix: add server side backed up metrics * fix: use exact int values returned from API to avoid rounding numbers
1 parent bffe907 commit 66f9e36

File tree

5 files changed

+18
-49
lines changed

5 files changed

+18
-49
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
2424
github.com/pkg/errors v0.9.1
2525
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.1.0
26-
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.5.0
26+
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0
2727
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.9.0
2828
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1
2929
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.6.1

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ github.com/redhat-developer/app-services-sdk-go v0.10.0 h1:zI0X5FR0NOj6IwBWk3y1T
628628
github.com/redhat-developer/app-services-sdk-go v0.10.0/go.mod h1:enn8Zz6IT0HZYzS6LSttiME2apwnvfVWZnGRS81A4rk=
629629
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.1.0 h1:MOljVN8AKTM72Yed8ioAwhdW0KdWEhBZjjam3lY2lyY=
630630
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.1.0/go.mod h1:0LX7ZCEmMKAbncO05/zRYsV0K5wsds7AGPpOFC7KWGo=
631-
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.5.0 h1:1FMsZfo2xCtYimrBcR+s0O0b0MzxdxiStY8A78oTGBA=
632-
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.5.0/go.mod h1:UYJgMZWmd238bk6l464U1g8I3YWcEE9PGnjvNRi5Lqw=
631+
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0 h1:ExEHQaihnPNxN2nKXB0q5nrmSv4p8b3Idzt7TChxv+Q=
632+
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0/go.mod h1:hMpejngP3BFnifCDH1gKRG9cU9Q4lr0WiQaW7A1LYo4=
633633
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.9.0 h1:wb335WbgyhFZRIHOwqHJm+D877l50MPMacrONCmknnw=
634634
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.9.0/go.mod h1:Bs/YQI9ZuZLzBoeBAWV6KmkO8Jwm8NcrUn3VFp8eleo=
635635
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1 h1:xRq5XJzRDs/Z7e/9SDt6zbNRIyesC4LTqN9ajHKwjHo=
@@ -910,7 +910,6 @@ golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ
910910
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
911911
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
912912
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
913-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
914913
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM=
915914
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
916915
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

pkg/cmd/kafka/consumergroup/describe/describe.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/http"
88
"sort"
99

10-
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/consumergroup/groupcmdutil"
1110
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
1211

1312
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
@@ -39,9 +38,9 @@ type consumerRow struct {
3938
MemberID string `json:"memberId,omitempty" header:"Consumer ID"`
4039
Partition int `json:"partition,omitempty" header:"Partition"`
4140
Topic string `json:"topic,omitempty" header:"Topic"`
42-
LogEndOffset int `json:"logEndOffset,omitempty" header:"Log end offset"`
43-
CurrentOffset int `json:"offset,omitempty" header:"Current offset"`
44-
OffsetLag int `json:"lag,omitempty" header:"Offset lag"`
41+
LogEndOffset int64 `json:"logEndOffset,omitempty" header:"Log end offset"`
42+
CurrentOffset int64 `json:"offset,omitempty" header:"Current offset"`
43+
OffsetLag int64 `json:"lag,omitempty" header:"Offset lag"`
4544
}
4645

4746
// NewDescribeConsumerGroupCommand gets a new command for describing a consumer group.
@@ -164,9 +163,9 @@ func mapConsumerGroupDescribeToTableFormat(consumers []kafkainstanceclient.Consu
164163
Partition: int(consumer.GetPartition()),
165164
Topic: consumer.GetTopic(),
166165
MemberID: consumer.GetMemberId(),
167-
LogEndOffset: int(consumer.GetLogEndOffset()),
168-
CurrentOffset: int(consumer.GetOffset()),
169-
OffsetLag: int(consumer.GetLag()),
166+
LogEndOffset: consumer.GetLogEndOffset(),
167+
CurrentOffset: consumer.GetOffset(),
168+
OffsetLag: consumer.GetLag(),
170169
}
171170

172171
if consumer.GetMemberId() == "" {
@@ -188,10 +187,11 @@ func mapConsumerGroupDescribeToTableFormat(consumers []kafkainstanceclient.Consu
188187
func printConsumerGroupDetails(w io.Writer, consumerGroupData kafkainstanceclient.ConsumerGroup, localizer localize.Localizer) {
189188
fmt.Fprintln(w, "")
190189
consumers := consumerGroupData.GetConsumers()
190+
metrics := consumerGroupData.GetMetrics()
191191

192-
activeMembersCount := groupcmdutil.GetActiveConsumersCount(consumers)
193-
partitionsWithLagCount := groupcmdutil.GetPartitionsWithLag(consumers)
194-
unassignedPartitions := groupcmdutil.GetUnassignedPartitions(consumers)
192+
activeMembersCount := metrics.GetActiveConsumers()
193+
partitionsWithLagCount := metrics.GetLaggingPartitions()
194+
unassignedPartitions := metrics.GetUnassignedPartitions()
195195

196196
fmt.Fprintln(w, color.Bold(localizer.MustLocalize("kafka.consumerGroup.describe.output.activeMembers")), activeMembersCount, "\t", color.Bold(localizer.MustLocalize("kafka.consumerGroup.describe.output.partitionsWithLag")), partitionsWithLagCount, "\t", color.Bold(localizer.MustLocalize("kafka.consumerGroup.describe.output.unassignedPartitions")), unassignedPartitions)
197197
fmt.Fprintln(w, "")

pkg/cmd/kafka/consumergroup/groupcmdutil/util.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,3 @@ const (
1313
)
1414

1515
var ValidOffsets = []string{OffsetAbsolute, OffsetEarliest, OffsetTimestamp, OffsetLatest}
16-
17-
// GetPartitionsWithLag returns the number of partitions having lag for a consumer group
18-
func GetPartitionsWithLag(consumers []kafkainstanceclient.Consumer) (partitionsWithLag int) {
19-
for _, consumer := range consumers {
20-
if consumer.Lag > 0 {
21-
partitionsWithLag++
22-
}
23-
}
24-
25-
return partitionsWithLag
26-
}
27-
28-
func GetActiveConsumersCount(consumers []kafkainstanceclient.Consumer) (count int) {
29-
for _, c := range consumers {
30-
if c.Partition != -1 {
31-
count++
32-
}
33-
}
34-
return count
35-
}
36-
37-
func GetUnassignedPartitions(consumers []kafkainstanceclient.Consumer) (unassignedPartitions int) {
38-
for _, c := range consumers {
39-
if c.GetMemberId() == "" {
40-
unassignedPartitions++
41-
}
42-
}
43-
return unassignedPartitions
44-
}

pkg/cmd/kafka/consumergroup/list/list.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"net/http"
66

7-
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/consumergroup/groupcmdutil"
87
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
98

109
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil"
@@ -41,8 +40,8 @@ type options struct {
4140

4241
type consumerGroupRow struct {
4342
ConsumerGroupID string `json:"groupId,omitempty" header:"Consumer group ID"`
44-
ActiveMembers int `json:"active_members,omitempty" header:"Active members"`
45-
PartitionsWithLag int `json:"lag,omitempty" header:"Partitions with lag"`
43+
ActiveMembers int32 `json:"active_members,omitempty" header:"Active members"`
44+
PartitionsWithLag int32 `json:"lag,omitempty" header:"Partitions with lag"`
4645
}
4746

4847
// NewListConsumerGroupCommand creates a new command to list consumer groups
@@ -179,11 +178,11 @@ func mapConsumerGroupResultsToTableFormat(consumerGroups []kafkainstanceclient.C
179178
rows := make([]consumerGroupRow, len(consumerGroups))
180179

181180
for i, t := range consumerGroups {
182-
consumers := t.GetConsumers()
181+
metrics := t.GetMetrics()
183182
row := consumerGroupRow{
184183
ConsumerGroupID: t.GetGroupId(),
185-
ActiveMembers: groupcmdutil.GetActiveConsumersCount(consumers),
186-
PartitionsWithLag: groupcmdutil.GetPartitionsWithLag(consumers),
184+
ActiveMembers: metrics.GetActiveConsumers(),
185+
PartitionsWithLag: metrics.GetLaggingPartitions(),
187186
}
188187
rows[i] = row
189188
}

0 commit comments

Comments
 (0)