Skip to content

Commit

Permalink
Add clear() method into PrometheusRegistry to unregister all collectors
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Holubec <[email protected]>
  • Loading branch information
holubec-petr committed Jun 18, 2024
1 parent 5867b79 commit cd28469
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public void unregister(MultiCollector collector) {
}
}

public void clear() {
collectors.clear();
multiCollectors.clear();
prometheusNames.clear();
}

public MetricSnapshots scrape() {
return scrape((PrometheusScrapeRequest) null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,18 @@ public void registerOk() {
snapshots = registry.scrape();
Assert.assertEquals(3, snapshots.size());
}

@Test
public void clearOk() {
PrometheusRegistry registry = new PrometheusRegistry();
registry.register(counterA1);
registry.register(counterB);
registry.register(gaugeA);
MetricSnapshots snapshots = registry.scrape();
Assert.assertEquals(3, snapshots.size());

registry.clear();
snapshots = registry.scrape();
Assert.assertEquals(0, snapshots.size());
}
}

0 comments on commit cd28469

Please sign in to comment.