Skip to content

Commit

Permalink
[core] Support remove metric groups from metric instance (apache#2062)
Browse files Browse the repository at this point in the history
* [core] Support remove metric groups from metric instance
  • Loading branch information
schnappi17 authored Sep 28, 2023
1 parent ae1dde1 commit 8ee4d1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void close() {
if (!closed) {
closed = true;
metrics.clear();
Metrics.getInstance().removeGroup(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public void addGroup(AbstractMetricGroup group) {
metricGroups.add(group);
}

/** Remove a metric group. Called when closing the corresponding instances, like committer. */
public void removeGroup(AbstractMetricGroup group) {
metricGroups.remove(group);
}

/** Get metric groups. */
public ConcurrentLinkedQueue<MetricGroup> getMetricGroups() {
return metricGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ public void testGroupRegisterMetrics() {
assertThat(group.isClosed()).isFalse();
// these will fail is the registration is propagated
group.counter("testcounter");
group.gauge(
"testgauge",
new Gauge<Object>() {
@Override
public Object getValue() {
return null;
}
});
group.gauge("testgauge", () -> null);
assertThat(group.getGroupName()).isEqualTo("commit");
assertThat(group.getAllTags().size()).isEqualTo(1);
assertThat(group.getAllTags())
Expand All @@ -65,5 +58,15 @@ public void testTolerateMetricNameCollisions() {

// return the old one with the metric name collision
assertThat(group.counter(name)).isSameAs(counter1);
group.close();
}

@Test
public void testAddAndRemoveMetricGroups() {
AbstractMetricGroup metricGroup =
GenericMetricGroup.createGenericMetricGroup("myTable", "commit");
assertThat(Metrics.getInstance().getMetricGroups()).containsExactly(metricGroup);
metricGroup.close();
assertThat(Metrics.getInstance().getMetricGroups()).isEmpty();
}
}

0 comments on commit 8ee4d1a

Please sign in to comment.