Remove table gauge metrics once table got deleted.
@@ -76,6 +76,8 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
private TableSizeReader _tableSizeReader;
+ private Set<String> _cachedTableNamesWithType = new HashSet<>();
+
/**
* Constructs the segment status checker.
* @param pinotHelixResourceManager The resource checker used to interact with Helix
@@ -124,6 +126,7 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
// Remove the metric for this table
resetTableMetrics(tableNameWithType);
}
+ context._processedTables.add(tableNameWithType);
}
@Override
@@ -131,6 +134,12 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
_controllerMetrics.setValueOfGlobalGauge(ControllerGauge.REALTIME_TABLE_COUNT, context._realTimeTableCount);
_controllerMetrics.setValueOfGlobalGauge(ControllerGauge.OFFLINE_TABLE_COUNT, context._offlineTableCount);
_controllerMetrics.setValueOfGlobalGauge(ControllerGauge.DISABLED_TABLE_COUNT, context._disabledTableCount);
+
+ // Remove metrics for tables that are no longer in the cluster
+ _cachedTableNamesWithType.removeAll(context._processedTables);
+ _cachedTableNamesWithType.forEach(this::removeMetricsForTable);
+ _cachedTableNamesWithType.clear();
+ _cachedTableNamesWithType.addAll(context._processedTables);
}
/**
@@ -311,7 +320,10 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
@Override
protected void nonLeaderCleanup(List<String> tableNamesWithType) {
- for (String tableNameWithType : tableNamesWithType) {
+ tableNamesWithType.forEach(this::removeMetricsForTable);
+ }
+
+ private void removeMetricsForTable(String tableNameWithType) {
_controllerMetrics.removeTableGauge(tableNameWithType, ControllerGauge.NUMBER_OF_REPLICAS);
_controllerMetrics.removeTableGauge(tableNameWithType, ControllerGauge.PERCENT_OF_REPLICAS);
_controllerMetrics.removeTableGauge(tableNameWithType, ControllerGauge.PERCENT_SEGMENTS_AVAILABLE);
@@ -324,7 +336,6 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
_controllerMetrics.removeTableGauge(tableNameWithType, ControllerGauge.SEGMENTS_IN_ERROR_STATE);
_controllerMetrics.removeTableGauge(tableNameWithType, ControllerGauge.PERCENT_SEGMENTS_AVAILABLE);
}
- }
private void setStatusToDefault() {
List<String> allTableNames = _pinotHelixResourceManager.getAllTables();
@@ -357,5 +368,6 @@ public class SegmentStatusChecker extends ControllerPeriodicTask<SegmentStatusCh
private int _realTimeTableCount;
private int _offlineTableCount;
private int _disabledTableCount;
+ private Set<String> _processedTables = new HashSet<>();
}
}
