-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple latency histogram metrics (#89)
* Add simple latency histogram metrics
- Loading branch information
YongGang
authored
Feb 28, 2022
1 parent
f243762
commit e702f27
Showing
4 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/com/salesforce/mirus/metrics/MirrorJmxReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.salesforce.mirus.metrics; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.apache.kafka.common.metrics.Metrics; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class MirrorJmxReporterTest { | ||
|
||
private MirrorJmxReporter mirrorJmxReporter; | ||
private Metrics metrics; | ||
private final String TEST_TOPIC = "TestTopic"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mirrorJmxReporter = MirrorJmxReporter.getInstance(); | ||
metrics = mirrorJmxReporter.metrics; | ||
} | ||
|
||
@Test | ||
public void updateLatencyMetrics() { | ||
TopicPartition topicPartition = new TopicPartition(TEST_TOPIC, 1); | ||
mirrorJmxReporter.addTopics(List.of(topicPartition)); | ||
|
||
mirrorJmxReporter.recordMirrorLatency(TEST_TOPIC, 500); | ||
|
||
Map<String, String> tags = new LinkedHashMap<>(); | ||
tags.put("topic", TEST_TOPIC); | ||
tags.put("bucket", "0m"); | ||
Object value = | ||
metrics | ||
.metrics() | ||
.get( | ||
metrics.metricName( | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.name(), | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.group(), | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.description(), | ||
tags)) | ||
.metricValue(); | ||
Assert.assertTrue((double) value > 0); | ||
|
||
tags.put("bucket", "12h"); | ||
value = | ||
metrics | ||
.metrics() | ||
.get( | ||
metrics.metricName( | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.name(), | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.group(), | ||
MirrorJmxReporter.HISTOGRAM_LATENCY.description(), | ||
tags)) | ||
.metricValue(); | ||
Assert.assertTrue((double) value == 0); | ||
} | ||
} |