use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.
the class MeterRegistryTest method histogramConfigTransformingMeterFilter.
@Test
void histogramConfigTransformingMeterFilter() {
MeterRegistry registry = new SimpleMeterRegistry() {
@Override
protected Timer newTimer(@Nonnull Meter.Id id, DistributionStatisticConfig histogramConfig, PauseDetector pauseDetector) {
assertThat(histogramConfig.isPublishingHistogram()).isTrue();
return super.newTimer(id, histogramConfig, pauseDetector);
}
};
registry.config().meterFilter(new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id mappedId, DistributionStatisticConfig config) {
return DistributionStatisticConfig.builder().percentiles(0.95).percentilesHistogram(true).build().merge(config);
}
});
registry.timer("my.timer");
}
use of io.micrometer.core.instrument.config.MeterFilter 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);
}
use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.
the class TimedAspectTest method serviceIsTimedWithHistogram.
@Test
public void serviceIsTimedWithHistogram() {
// given...
// ... we are waiting for a metric to be created with a histogram
AtomicReference<DistributionStatisticConfig> myConfig = new AtomicReference<>();
registry.config().meterFilter(new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
if (id.getName().equals("something")) {
myConfig.set(config);
}
return config;
}
});
// when...
// ... the service is being called
service.timeWithHistogram();
// then...
assertThat(myConfig.get()).as("the metric has been created").isNotNull();
assertThat(myConfig.get().isPublishingHistogram()).as("the metric has a histogram").isTrue();
}
use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.
the class MeterRegistry method registerMeterIfNecessary.
private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.Id id, @Nullable DistributionStatisticConfig config, BiFunction<Meter.Id, DistributionStatisticConfig, Meter> builder, Function<Meter.Id, M> noopBuilder) {
Meter.Id mappedId = id;
for (MeterFilter filter : filters) {
mappedId = filter.map(mappedId);
}
if (!accept(id)) {
// noinspection unchecked
return noopBuilder.apply(id);
}
if (config != null) {
for (MeterFilter filter : filters) {
DistributionStatisticConfig filteredConfig = filter.configure(mappedId, config);
if (filteredConfig != null) {
config = filteredConfig;
}
}
}
Meter m = getOrCreateMeter(config, builder, mappedId, noopBuilder);
if (!meterClass.isInstance(m)) {
throw new IllegalArgumentException("There is already a registered meter of a different type with the same name");
}
// noinspection unchecked
return (M) m;
}
use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.
the class MeterFilterTest method maxExpectedOnTimer.
@Test
void maxExpectedOnTimer() {
MeterFilter filter = MeterFilter.maxExpected("name", Duration.ofNanos(100));
Meter.Id timer = new Meter.Id("name", emptyList(), null, null, Meter.Type.TIMER);
assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT)).satisfies(conf -> assertThat(conf.getMaximumExpectedValue()).isEqualTo(100));
}
Aggregations