PrometheusMetrics { public static void clearPartitionCollectors(int partition) { Map<SimpleCollector<?>, Set<List<String>>> collectorToChildLabels = REGISTERED_COLLECTORS.get(partition); if (collectorToChildLabels != null) { collectorToChildLabels.forEach((collector, childLabels) -> childLabels.forEach(labels -> collector.remove(labels.toArray(new String[0])))); } } private  PrometheusMetrics(); static Counter.Child tmpFileOpenFailuresCounter(String eventName); static Counter.Child tmpFilesOpened(String eventName); static Counter.Child filesCommittedCounter(String eventName); static Counter.Child checkpointFailuresCounter(String eventName, int partition); static Counter.Child checkpointSuccessesCounter(String eventName, int partition); static Counter.Child messageWritingFailuresCounter(String eventName, int partition); static Counter.Child messageWrittenCounter(String eventName, int partition); static Counter.Child hearbeatsSentCounter(String eventName, int partition); static Gauge.Child currentRunningOffsetsGauge(String eventName, int partition); static Gauge.Child latestCommittedOffsetGauge(String eventName, int partition); static Gauge.Child latestCommittedTimestampGauge(String eventName, int partition); static void clearCollectors(); static void clearPartitionCollectors(int partition); static Map<Integer, Map<SimpleCollector<?>, Set<List<String>>>> getRegisteredCollectors();  }
@Test public void shouldClearAllCollectorsForPartition() { createCollectorsForEventPartition("event_1", 0); createCollectorsForEventPartition("event_1", 1); createCollectorsForEventPartition("event_1", 2); createCollectorsForEventPartition("event_2", 0); createCollectorsForEventPartition("event_2", 1); createCollectorsForEventPartition("event_2", 2); checkLabelExist("partition", "0"); PrometheusMetrics.clearPartitionCollectors(0); checkLabelNotExist("partition", "0"); }
@Test public void shouldNotFailWhenCleaningNonAlreadyRegisteredPartition() { PrometheusMetrics.clearPartitionCollectors(0); }