Skip to content

Commit 4928eee

Browse files
committed
[#noissue] Change heatmap kafka key for distribution
1 parent 5aa4639 commit 4928eee

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

collector/src/main/java/com/navercorp/pinpoint/collector/heatmap/config/HeatmapProperties.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class HeatmapProperties {
3131
private int heatMapTopicPaddingLength;
3232
@Value("${kafka.heatmap.topic.count}")
3333
private int heatmapTopicCount;
34-
34+
@Value("${kafka.heatmap.key.partition.count}")
35+
private int heatmapKeyPartitionCount;
3536

3637
public String getHeatmapTopicPrefix() {
3738
return heatmapTopicPrefix;
@@ -44,4 +45,8 @@ public int getHeatMapTopicPaddingLength() {
4445
public int getHeatmapTopicCount() {
4546
return heatmapTopicCount;
4647
}
48+
49+
public int getHeatmapKeyPartitionCount() {
50+
return heatmapKeyPartitionCount;
51+
}
4752
}

collector/src/main/java/com/navercorp/pinpoint/collector/heatmap/dao/pinot/PinotHeatmapDao.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
import com.navercorp.pinpoint.collector.heatmap.config.HeatmapProperties;
2020
import com.navercorp.pinpoint.collector.heatmap.dao.HeatmapDao;
21+
import com.navercorp.pinpoint.collector.heatmap.util.HashmapSortKeyUtils;
2122
import com.navercorp.pinpoint.collector.heatmap.vo.HeatmapStat;
2223
import com.navercorp.pinpoint.common.server.metric.dao.TopicNameManager;
2324
import org.apache.logging.log4j.LogManager;
2425
import org.apache.logging.log4j.Logger;
26+
import org.springframework.beans.factory.annotation.Value;
2527
import org.springframework.kafka.core.KafkaTemplate;
2628
import org.springframework.stereotype.Repository;
2729

2830
import java.util.Objects;
31+
import java.util.concurrent.ThreadLocalRandom;
2932

3033
/**
3134
* @author minwoo-jung
@@ -36,10 +39,12 @@ public class PinotHeatmapDao implements HeatmapDao {
3639
private final Logger logger = LogManager.getLogger(getClass());
3740
private final KafkaTemplate<String, HeatmapStat> kafkaHeatmapStatTemplate;
3841
private final TopicNameManager topicNameManager;
42+
private final int keyPartitionCount;
3943

4044
public PinotHeatmapDao(KafkaTemplate<String, HeatmapStat> kafkaHeatmapStatTemplate, HeatmapProperties heatmapProperties) {
4145
this.kafkaHeatmapStatTemplate = Objects.requireNonNull(kafkaHeatmapStatTemplate, "kafkaHeatmapStatTemplate");
4246
this.topicNameManager = new TopicNameManager(heatmapProperties.getHeatmapTopicPrefix(), heatmapProperties.getHeatMapTopicPaddingLength(), heatmapProperties.getHeatmapTopicCount());
47+
this.keyPartitionCount = heatmapProperties.getHeatmapKeyPartitionCount();
4348
}
4449

4550
@Override
@@ -49,6 +54,14 @@ public void insert(HeatmapStat heatmapStat) {
4954
return;
5055
}
5156
String topic = topicNameManager.getTopicName(heatmapStat.getApplicationName());
52-
kafkaHeatmapStatTemplate.send(topic, heatmapStat.getAgentId(), heatmapStat);
57+
kafkaHeatmapStatTemplate.send(topic, heatmapStat.getSortKey() + "#" + randomPartitionSuffix(), heatmapStat);
58+
}
59+
60+
private int randomPartitionSuffix() {
61+
if (keyPartitionCount <= 1) {
62+
return 0;
63+
}
64+
int nonNegativeRandom = ThreadLocalRandom.current().nextInt() & 0x7fffffff;
65+
return nonNegativeRandom % keyPartitionCount;
5366
}
5467
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
kafka.heatmap.topic.count=1
22
kafka.heatmap.topic.prefix=heatmap-stat-app-
3-
kafka.heatmap.topic.padding.length=2
3+
kafka.heatmap.topic.padding.length=2
4+
kafka.heatmap.key.partition.count=1
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
kafka.heatmap.topic.count=1
22
kafka.heatmap.topic.prefix=heatmap-stat-app-
3-
kafka.heatmap.topic.padding.length=2
3+
kafka.heatmap.topic.padding.length=2
4+
kafka.heatmap.key.partition.count=1

0 commit comments

Comments
 (0)