@@ -28,26 +28,7 @@ object ConsumerMetricsOf {
28
28
registry <- KafkaMetricsRegistry .of(prometheus, prefix)
29
29
} yield { (clientId : ClientId ) =>
30
30
val source = sourceOf(clientId)
31
-
32
- new ConsumerMetrics [F ] {
33
- override def call (name : String , topic : Topic , latency : FiniteDuration , success : Boolean ): F [Unit ] =
34
- source.call(name, topic, latency, success)
35
-
36
- override def poll (topic : Topic , bytes : Int , records : Int , age : Option [FiniteDuration ]): F [Unit ] =
37
- source.poll(topic, bytes, records, age)
38
-
39
- override def count (name : String , topic : Topic ): F [Unit ] =
40
- source.count(name, topic)
41
-
42
- override def rebalance (name : String , topicPartition : TopicPartition ): F [Unit ] =
43
- source.rebalance(name, topicPartition)
44
-
45
- override def topics (latency : FiniteDuration ): F [Unit ] =
46
- source.topics(latency)
47
-
48
- override def exposeJavaMetrics [K , V ](consumer : Consumer [F , K , V ]): Resource [F , Unit ] =
49
- registry.register(consumer.clientMetrics)
50
- }
31
+ consumerMetricsOf(source, registry)
51
32
}
52
33
53
34
/**
@@ -65,7 +46,13 @@ object ConsumerMetricsOf {
65
46
): Resource [F , ConsumerMetrics [F ]] =
66
47
for {
67
48
registry <- KafkaMetricsRegistry .of(prometheus, prefix)
68
- } yield new ConsumerMetrics [F ] {
49
+ } yield consumerMetricsOf(source, registry)
50
+
51
+ private def consumerMetricsOf [F [_]](
52
+ source : ConsumerMetrics [F ],
53
+ registry : KafkaMetricsRegistry [F ],
54
+ ): ConsumerMetrics [F ] =
55
+ new ConsumerMetrics [F ] {
69
56
override def call (name : String , topic : Topic , latency : FiniteDuration , success : Boolean ): F [Unit ] =
70
57
source.call(name, topic, latency, success)
71
58
0 commit comments