diff --git a/paimon-core/src/main/java/org/apache/paimon/metrics/commit/CommitMetrics.java b/paimon-core/src/main/java/org/apache/paimon/metrics/commit/CommitMetrics.java index 662b6a2ba654..a216a94e21a1 100644 --- a/paimon-core/src/main/java/org/apache/paimon/metrics/commit/CommitMetrics.java +++ b/paimon-core/src/main/java/org/apache/paimon/metrics/commit/CommitMetrics.java @@ -37,6 +37,7 @@ public CommitMetrics(String tableName) { registerGenericCommitMetrics(); } + @VisibleForTesting public AbstractMetricGroup getMetricGroup() { return genericMetricGroup; } @@ -129,4 +130,8 @@ public void reportCommit(CommitStats commitStats) { latestCommit = commitStats; durationHistogram.update(commitStats.getDuration()); } + + public void close() { + this.genericMetricGroup.close(); + } } diff --git a/paimon-core/src/main/java/org/apache/paimon/table/sink/TableCommitImpl.java b/paimon-core/src/main/java/org/apache/paimon/table/sink/TableCommitImpl.java index 56341b559b15..19e95bb0cc6d 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/sink/TableCommitImpl.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/sink/TableCommitImpl.java @@ -265,7 +265,7 @@ public void close() throws Exception { } IOUtils.closeQuietly(lock); expireMainExecutor.shutdownNow(); - commitMetrics.getMetricGroup().close(); + commitMetrics.close(); } @Override diff --git a/paimon-core/src/test/java/org/apache/paimon/metrics/commit/CommitMetricsTest.java b/paimon-core/src/test/java/org/apache/paimon/metrics/commit/CommitMetricsTest.java index ec94752bf71b..b2599238aae3 100644 --- a/paimon-core/src/test/java/org/apache/paimon/metrics/commit/CommitMetricsTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/metrics/commit/CommitMetricsTest.java @@ -26,6 +26,7 @@ import org.apache.paimon.metrics.MetricGroup; import org.apache.paimon.metrics.Metrics; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,10 +46,14 @@ public class CommitMetricsTest { @BeforeEach public void beforeEach() { - Metrics.getInstance().getMetricGroups().clear(); commitMetrics = getCommitMetrics(); } + @AfterEach + public void afterEach() { + commitMetrics.close(); + } + /** Tests the registration of the commit metrics. */ @Test public void testGenericMetricsRegistration() {