Search in sources :

Example 1 with MeterFilterReply

use of io.micrometer.core.instrument.config.MeterFilterReply in project micrometer by micrometer-metrics.

the class MeterFilterTest method maximumAllowableTags.

@Test
void maximumAllowableTags() {
    AtomicInteger n = new AtomicInteger(0);
    MeterFilter filter = MeterFilter.maximumAllowableTags("name", "k", 2, new MeterFilter() {

        @Override
        public MeterFilterReply accept(Meter.Id id) {
            n.incrementAndGet();
            return MeterFilterReply.NEUTRAL;
        }
    });
    Meter.Id id = new Meter.Id("name", Tags.of("k", "1"), null, null, Meter.Type.COUNTER);
    Meter.Id id2 = new Meter.Id("name", Tags.of("k", "2"), null, null, Meter.Type.COUNTER);
    Meter.Id id3 = new Meter.Id("name", Tags.of("k", "3"), null, null, Meter.Type.COUNTER);
    filter.accept(id);
    filter.accept(id);
    filter.accept(id2);
    filter.accept(id);
    filter.accept(id3);
    assertThat(n.get()).isEqualTo(1);
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) MeterFilterReply(io.micrometer.core.instrument.config.MeterFilterReply) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 2 with MeterFilterReply

use of io.micrometer.core.instrument.config.MeterFilterReply in project micrometer by micrometer-metrics.

the class MeterRegistryTest method acceptMeterFilter.

@Test
void acceptMeterFilter() {
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public MeterFilterReply accept(Meter.Id id) {
            return id.getName().contains("jvm") ? MeterFilterReply.DENY : MeterFilterReply.NEUTRAL;
        }
    });
    assertThat(registry.counter("jvm.my.counter")).isInstanceOf(NoopCounter.class);
    assertThat(registry.counter("my.counter")).isNotInstanceOf(NoopCounter.class);
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) MeterFilterReply(io.micrometer.core.instrument.config.MeterFilterReply) Test(org.junit.jupiter.api.Test)

Aggregations

MeterFilter (io.micrometer.core.instrument.config.MeterFilter)2 MeterFilterReply (io.micrometer.core.instrument.config.MeterFilterReply)2 Test (org.junit.jupiter.api.Test)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1