org.eclipse.microprofile.metrics.MetricFilter Java Examples

The following examples show how to use org.eclipse.microprofile.metrics.MetricFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public SortedMap<MetricID, Metric> getMetrics(MetricFilter filter) {
    SortedMap<MetricID, Metric> out = new TreeMap<>();
    for (Map.Entry<MetricID, Metric> entry : metricMap.entrySet()) {
        if (filter.matches(entry.getKey(), entry.getValue())) {
            out.put(entry.getKey(), entry.getValue());
        }
    }
    return out;
}
 
Example #2
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
private <T extends Metric> SortedMap<MetricID, T> getMetrics(MetricType type, MetricFilter filter) {
    SortedMap<MetricID, T> out = new TreeMap<>();

    for (Map.Entry<MetricID, Metric> entry : metricMap.entrySet()) {
        if (isSameType(entry.getValue(), type)) {
            if (filter.matches(entry.getKey(), entry.getValue())) {
                out.put(entry.getKey(), (T) entry.getValue());
            }
        }
    }
    return out;
}
 
Example #3
Source File: MetricRegistryThreadSafetyTest.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
/**
 * One set of threads is registering new metrics and removing them after a short while,
 * at the same time, another set of threads is retrieving a list of metrics conforming to a filter.
 * None of the threads should be getting any exceptions.
 */
@Test
public void tryRegisteringRemovingAndReadingAtTheSameTime() throws InterruptedException {
    for (int i = 0; i < 20; i++) {
        cleanup();
        final ExecutorService executor = Executors.newFixedThreadPool(10);
        final CompletableFuture[] futures = IntStream.range(0, 200)
                .parallel()
                .mapToObj(j -> CompletableFuture.runAsync(
                        () -> {
                            try {
                                if (j % 2 == 0) {
                                    MetricID metricID = new MetricID("mycounter", new Tag("number", String.valueOf(j)));
                                    registry.counter("mycounter", new Tag("number", String.valueOf(j)));
                                    registry.remove(metricID);
                                } else {
                                    registry.getCounters(MetricFilter.ALL);
                                }
                            } catch (Throwable t) {
                                t.printStackTrace();
                                throw t;
                            }
                        }, executor))
                .toArray(CompletableFuture[]::new);
        executor.shutdown();
        executor.awaitTermination(10, TimeUnit.SECONDS);

        assertEquals("All threads should finish without exceptions",
                0, Arrays.stream(futures).filter(CompletableFuture::isCompletedExceptionally).count());
    }
}
 
Example #4
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public void removeMatching(MetricFilter metricFilter) {
    Iterator<Map.Entry<MetricID, Metric>> iterator = metricMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<MetricID, Metric> entry = iterator.next();
        if (metricFilter.matches(entry.getKey(), entry.getValue())) {
            remove(entry.getKey());
        }
    }
}
 
Example #5
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Timer> getTimers() {
    return getTimers(MetricFilter.ALL);
}
 
Example #6
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Meter> getMeters(MetricFilter metricFilter) {
    return getMetrics(MetricType.METERED, metricFilter);
}
 
Example #7
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Timer> getTimers(MetricFilter metricFilter) {
    return getMetrics(MetricType.TIMER, metricFilter);
}
 
Example #8
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, SimpleTimer> getSimpleTimers() {
    return getSimpleTimers(MetricFilter.ALL);

}
 
Example #9
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, SimpleTimer> getSimpleTimers(MetricFilter filter) {
    return getMetrics(MetricType.SIMPLE_TIMER, filter);
}
 
Example #10
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends Metric> SortedMap<MetricID, T> getMetrics(Class<T> ofType, MetricFilter filter) {
    return (SortedMap<MetricID, T>) getMetrics(
            (metricID, metric) -> filter.matches(metricID, metric)
                    && ofType.isAssignableFrom(metric.getClass()));
}
 
Example #11
Source File: MetricRegistryThreadSafetyTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #12
Source File: MetricTypeMismatchTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #13
Source File: MetadataMismatchTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #14
Source File: ReusabilityByDefaultTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #15
Source File: RegistrationCornerCasesTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #16
Source File: ExportersMetricScalingTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}
 
Example #17
Source File: OpenMetricsExporterTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}
 
Example #18
Source File: JsonExporterTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
    MetricRegistries.get(MetricRegistry.Type.BASE).removeMatching(MetricFilter.ALL);
    MetricRegistries.get(MetricRegistry.Type.VENDOR).removeMatching(MetricFilter.ALL);
}
 
Example #19
Source File: JsonMetadataExporterTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}
 
Example #20
Source File: MetricFilterTest.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Test
public void theAllFilterMatchesAllMetrics() throws Exception {
    Assert.assertTrue(MetricFilter.ALL.matches(new MetricID(""), metric));
}
 
Example #21
Source File: GlobalTagsTest.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    registry.removeMatching(MetricFilter.ALL);
}
 
Example #22
Source File: MetricsRegistryImpl.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Gauge> getGauges() {
    return getGauges(MetricFilter.ALL);
}
 
Example #23
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Gauge> getGauges(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #24
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Counter> getCounters(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #25
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #26
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Histogram> getHistograms(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #27
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Meter> getMeters(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #28
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Timer> getTimers(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #29
Source File: TestMetricsServiceImpl.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, SimpleTimer> getSimpleTimers(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example #30
Source File: GaugeInDependentScopedBeanTest.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@After
public void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}