Java Code Examples for org.eclipse.microprofile.metrics.MetricFilter

The following examples show how to use org.eclipse.microprofile.metrics.MetricFilter. These examples are extracted from open source projects. 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 Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 2
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 3
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 4
/**
 * 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 5
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeMatching(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 6
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Gauge> getGauges(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 7
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Counter> getCounters(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 8
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 9
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Histogram> getHistograms(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 10
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Meter> getMeters(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 11
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Timer> getTimers(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 12
Source Project: smallrye-graphql   Source File: TestMetricsServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, SimpleTimer> getSimpleTimers(MetricFilter filter) {
    throw new UnsupportedOperationException("unimplemented");
}
 
Example 13
@After
public void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}
 
Example 14
@AfterClass
public static void cleanupApplicationMetrics() {
    MetricRegistries.get(MetricRegistry.Type.APPLICATION).removeMatching(MetricFilter.ALL);
}
 
Example 15
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Gauge> getGauges() {
    return getGauges(MetricFilter.ALL);
}
 
Example 16
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Gauge> getGauges(MetricFilter metricFilter) {
    return getMetrics(MetricType.GAUGE, metricFilter);
}
 
Example 17
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Counter> getCounters() {
    return getCounters(MetricFilter.ALL);
}
 
Example 18
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, Counter> getCounters(MetricFilter metricFilter) {
    return getMetrics(MetricType.COUNTER, metricFilter);
}
 
Example 19
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges() {
    return getConcurrentGauges(MetricFilter.ALL);
}
 
Example 20
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter metricFilter) {
    return getMetrics(MetricType.CONCURRENT_GAUGE, metricFilter);
}
 
Example 21
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Histogram> getHistograms() {
    return getHistograms(MetricFilter.ALL);
}
 
Example 22
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Histogram> getHistograms(MetricFilter metricFilter) {
    return getMetrics(MetricType.HISTOGRAM, metricFilter);
}
 
Example 23
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Meter> getMeters() {
    return getMeters(MetricFilter.ALL);
}
 
Example 24
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 25
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public java.util.SortedMap<MetricID, Timer> getTimers() {
    return getTimers(MetricFilter.ALL);
}
 
Example 26
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 27
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<MetricID, SimpleTimer> getSimpleTimers() {
    return getSimpleTimers(MetricFilter.ALL);

}
 
Example 28
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 29
Source Project: smallrye-metrics   Source File: MetricsRegistryImpl.java    License: 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 30
@After
public void cleanup() {
    registry.removeMatching(MetricFilter.ALL);
}