Skip to content

Commit 2eff40f

Browse files
zhanghaou张浩
and
张浩
authored
[fix][broker] http metric endpoint get compaction latency stats always be 0 (#24067)
Co-authored-by: 张浩 <[email protected]>
1 parent 694969f commit 2eff40f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactionRecord.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public long[] getCompactionLatencyBuckets() {
111111
}
112112

113113
public StatsBuckets getCompactionLatencyStats() {
114+
writeLatencyStats.refresh();
114115
return writeLatencyStats;
115116
}
116117

pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactorMXBeanImplTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.testng.Assert.assertEquals;
2222
import static org.testng.Assert.assertTrue;
23+
import org.apache.bookkeeper.mledger.util.StatsBuckets;
2324
import org.testng.annotations.Test;
2425

2526
import java.util.concurrent.TimeUnit;
@@ -61,4 +62,17 @@ public void testSimple() throws Exception {
6162
assertTrue(compaction.getCompactionLatencyBuckets()[0] > 0L);
6263
}
6364

65+
@Test
66+
public void testCompactionLatencyStatsAddAll() {
67+
CompactorMXBeanImpl mxBean = new CompactorMXBeanImpl();
68+
String topic = "topic2";
69+
mxBean.addCompactionStartOp(topic);
70+
CompactionRecord compaction = mxBean.getCompactionRecordForTopic(topic).get();
71+
StatsBuckets compactionLatencyBuckets = new StatsBuckets(CompactionRecord.WRITE_LATENCY_BUCKETS_USEC);
72+
mxBean.addCompactionLatencyOp(topic, 10, TimeUnit.NANOSECONDS);
73+
compactionLatencyBuckets.addAll(compaction.getCompactionLatencyStats());
74+
compactionLatencyBuckets.refresh();
75+
assertTrue(compactionLatencyBuckets.getBuckets()[0] > 0L);
76+
}
77+
6478
}

0 commit comments

Comments
 (0)