Skip to content

Commit

Permalink
Create a copy of the collections to remove in MetricsTestUtil.
Browse files Browse the repository at this point in the history
Signed-off-by: David Venable <dlv@amazon.com>
  • Loading branch information
dlvenable committed Jul 9, 2024
1 parent 28c6b5c commit 77dff3d
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
package org.opensearch.dataprepper.metrics;

import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Statistic;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class MetricsTestUtil {

public static synchronized void initMetrics() {
Metrics.globalRegistry.getRegistries().forEach(meterRegistry -> Metrics.globalRegistry.remove(meterRegistry));
Metrics.globalRegistry.getMeters().forEach(meter -> Metrics.globalRegistry.remove(meter));
final Set<MeterRegistry> registries = new HashSet<>(Metrics.globalRegistry.getRegistries());
registries.forEach(meterRegistry -> Metrics.globalRegistry.remove(meterRegistry));

final List<Meter> meters = new ArrayList<>(Metrics.globalRegistry.getMeters());
meters.forEach(meter -> Metrics.globalRegistry.remove(meter));

Metrics.addRegistry(new SimpleMeterRegistry());
}

Expand Down

0 comments on commit 77dff3d

Please sign in to comment.