From 33dc624f96c8221d046253baea75d840ed217cb2 Mon Sep 17 00:00:00 2001 From: Simon Caron Date: Thu, 17 Sep 2020 00:17:35 -0400 Subject: [PATCH 1/2] Added Filter to Remove NaN Values from Aggregate Metrics Signed-off-by: Simon Caron --- .../lightbend/kafkalagexporter/ConsumerGroupCollector.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollector.scala b/src/main/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollector.scala index 409752fb..df5e4e31 100644 --- a/src/main/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollector.scala +++ b/src/main/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollector.scala @@ -271,11 +271,11 @@ object ConsumerGroupCollector { reporter ! Metrics.GroupValueMessage(Metrics.MaxGroupOffsetLagMetric, config.cluster.name, group, maxOffsetLag.offsetLag) reporter ! Metrics.GroupValueMessage(Metrics.MaxGroupTimeLagMetric, config.cluster.name, group, maxTimeLag.timeLag) - val sumOffsetLag = groupValues.map(_.offsetLag).sum + val sumOffsetLag = groupValues.map(_.offsetLag).filter(offsetLag => !offsetLag.isNaN).sum reporter ! Metrics.GroupValueMessage(Metrics.SumGroupOffsetLagMetric, config.cluster.name, group, sumOffsetLag) for((topic, topicValues) <- groupValues.groupBy(_.gtp.topic)) { - val topicOffsetLag = topicValues.map(_.offsetLag).sum + val topicOffsetLag = topicValues.map(_.offsetLag).filter(offsetLag => !offsetLag.isNaN).sum reporter ! Metrics.GroupTopicValueMessage(Metrics.SumGroupTopicOffsetLagMetric, config.cluster.name, group, topic, topicOffsetLag) } From 20ba3293c4c961a438e784807ecd907374587fa4 Mon Sep 17 00:00:00 2001 From: Simon Caron Date: Thu, 17 Sep 2020 00:44:38 -0400 Subject: [PATCH 2/2] Fix SumGroupTopicOffsetLagMetric Test --- .../lightbend/kafkalagexporter/ConsumerGroupCollectorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollectorSpec.scala b/src/test/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollectorSpec.scala index 3ea26854..eae9c976 100644 --- a/src/test/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollectorSpec.scala +++ b/src/test/scala/com/lightbend/kafkalagexporter/ConsumerGroupCollectorSpec.scala @@ -250,7 +250,7 @@ class ConsumerGroupCollectorSpec extends FreeSpec with Matchers with TestData wi "topic offset lag metric" in { metrics.collectFirst { - case GroupTopicValueMessage(`SumGroupTopicOffsetLagMetric`, config.cluster.name, `groupId`, `topic`, value) if value.isNaN => true + case GroupTopicValueMessage(`SumGroupTopicOffsetLagMetric`, config.cluster.name, `groupId`, `topic`, value) if !value.isNaN => true }.nonEmpty shouldBe true } }