Skip to content

Commit

Permalink
feat(metrics): skip reporting metrics delay for newly created partiti…
Browse files Browse the repository at this point in the history
…on (#2028)

give some exemption time (60s) for newly created partition to receive metrics before reporting it as out-of-sync to prevent false alert

Signed-off-by: Shichao Nie <niesc@automq.com>
  • Loading branch information
SCNieh authored Sep 19, 2024
1 parent a114ec3 commit ac9b075
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public abstract class AbstractInstanceUpdater {
protected Map<Byte, Samples> metricSampleMap = new HashMap<>();
protected long lastUpdateTimestamp = 0L;
protected MetricVersion metricVersion = defaultVersion();
private final long createTimestamp;

public AbstractInstanceUpdater() {
this.createTimestamp = System.currentTimeMillis();
}

public long createTimestamp() {
return createTimestamp;
}

public boolean update(Iterable<Map.Entry<Byte, Double>> metricsMap, long time) {
lock.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ClusterModel {
protected final Logger logger;
private static final String DEFAULT_RACK_ID = "rack_default";
private static final long DEFAULT_MAX_TOLERATED_METRICS_DELAY_MS = 60000L;

private static final long DEFAULT_METRICS_DELAY_EXEMPTION_TIME_MS = 60000L;
/*
* Guard the access on cluster structure (read/add/remove for brokers, replicas)
*/
Expand Down Expand Up @@ -78,6 +78,10 @@ Map<Integer, Long> calculateBrokerLatestMetricsTime() {
Map<TopicPartition, TopicPartitionReplicaUpdater> replicaMap = entry.getValue();
for (Map.Entry<TopicPartition, TopicPartitionReplicaUpdater> tpEntry : replicaMap.entrySet()) {
TopicPartitionReplicaUpdater replicaUpdater = tpEntry.getValue();
if (System.currentTimeMillis() - replicaUpdater.createTimestamp() <= DEFAULT_METRICS_DELAY_EXEMPTION_TIME_MS) {
// exempt the newly created partition
continue;
}
metricsTimeMap.put(brokerId, Math.min(metricsTimeMap.get(brokerId), replicaUpdater.getLastUpdateTimestamp()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void testMetricsTime() {

Map<Integer, Long> metricsTimeMap = clusterModel.calculateBrokerLatestMetricsTime();
Assertions.assertEquals(1, metricsTimeMap.size());
Assertions.assertEquals(now - 2000, metricsTimeMap.get(brokerId));
Assertions.assertEquals(now, metricsTimeMap.get(brokerId));
}

@Test
Expand Down

0 comments on commit ac9b075

Please sign in to comment.