From 097a55ba2111d9befcdb26c017e1c25fe75da457 Mon Sep 17 00:00:00 2001 From: Sergio Troiano Date: Sat, 7 Sep 2024 05:16:22 +0200 Subject: [PATCH] Adding topics of the group in log --- pkg/metrics/metrics_calculator.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/metrics/metrics_calculator.go b/pkg/metrics/metrics_calculator.go index bb3c2b2..07584b7 100644 --- a/pkg/metrics/metrics_calculator.go +++ b/pkg/metrics/metrics_calculator.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "strconv" + "strings" "sync" "github.com/redis/go-redis/v9" @@ -37,9 +38,12 @@ func (lp *LagProcessor) processGroup(group *structs.Group) { // Set the group's sum values lp.updateGroupSums(group, tempSumLagInOffsets, tempSumLagInSeconds, validOffsetsFound, validSecondsFound) - logrus.Infof("Finished processing group in cluster: %s, Group: %s, MaxLagInOffsets: %d, MaxLagInSeconds: %d, SumLagInOffsets: %d, SumLagInSeconds: %d", - group.ClusterName, group.Name, group.MaxLagInOffsets, group.MaxLagInSeconds, group.SumLagInOffsets, group.SumLagInSeconds) + // Use the helper function to get the concatenated topic names + topicList := concatenateTopicNames(group) + // Include the topics in the log message + logrus.Infof("Finished processing group in cluster: %s, Group: %s, MaxLagInOffsets: %d, MaxLagInSeconds: %d, SumLagInOffsets: %d, SumLagInSeconds: %d, Topics: [%s]", + group.ClusterName, group.Name, group.MaxLagInOffsets, group.MaxLagInSeconds, group.SumLagInOffsets, group.SumLagInSeconds, topicList) } func (lp *LagProcessor) processTopic(topic *structs.Topic, group *structs.Group, tempSumLagInOffsets, tempSumLagInSeconds *int64, validOffsetsFound, validSecondsFound *bool) { @@ -333,3 +337,12 @@ func (lp *LagProcessor) GenerateMetrics(groupsComplete <-chan *structs.Group, nu return metricsToExportChan } + +// concatenateTopicNames takes a group and returns a concatenated string of topic names. +func concatenateTopicNames(group *structs.Group) string { + var topicNames []string + for _, topic := range group.Topics { + topicNames = append(topicNames, topic.Name) + } + return strings.Join(topicNames, ", ") +}