Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class HeatmapProperties {
private int heatMapTopicPaddingLength;
@Value("${kafka.heatmap.topic.count}")
private int heatmapTopicCount;

@Value("${kafka.heatmap.key.partition.count}")
private int heatmapKeyPartitionCount;

public String getHeatmapTopicPrefix() {
return heatmapTopicPrefix;
Expand All @@ -44,4 +45,8 @@ public int getHeatMapTopicPaddingLength() {
public int getHeatmapTopicCount() {
return heatmapTopicCount;
}

public int getHeatmapKeyPartitionCount() {
return heatmapKeyPartitionCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.stereotype.Repository;

import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;

/**
* @author minwoo-jung
Expand All @@ -36,10 +37,12 @@ public class PinotHeatmapDao implements HeatmapDao {
private final Logger logger = LogManager.getLogger(getClass());
private final KafkaTemplate<String, HeatmapStat> kafkaHeatmapStatTemplate;
private final TopicNameManager topicNameManager;
private final int keyPartitionCount;

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

@Override
Expand All @@ -49,6 +52,14 @@ public void insert(HeatmapStat heatmapStat) {
return;
}
String topic = topicNameManager.getTopicName(heatmapStat.getApplicationName());
kafkaHeatmapStatTemplate.send(topic, heatmapStat.getAgentId(), heatmapStat);
kafkaHeatmapStatTemplate.send(topic, heatmapStat.getSortKey() + "#" + randomPartitionSuffix(), heatmapStat);
}

private int randomPartitionSuffix() {
if (keyPartitionCount <= 1) {
return 0;
}
int nonNegativeRandom = ThreadLocalRandom.current().nextInt() & 0x7fffffff;
return nonNegativeRandom % keyPartitionCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kafka.heatmap.topic.count=1
kafka.heatmap.topic.prefix=heatmap-stat-app-
kafka.heatmap.topic.padding.length=2
kafka.heatmap.topic.padding.length=2
kafka.heatmap.key.partition.count=1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kafka.heatmap.topic.count=1
kafka.heatmap.topic.prefix=heatmap-stat-app-
kafka.heatmap.topic.padding.length=2
kafka.heatmap.topic.padding.length=2
kafka.heatmap.key.partition.count=1