use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig 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.distribution.DistributionStatisticConfig 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.distribution.DistributionStatisticConfig 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.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.
the class SimpleMeterRegistry method newDistributionSummary.
@Override
protected DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
DistributionStatisticConfig merged = distributionStatisticConfig.merge(DistributionStatisticConfig.builder().expiry(config.step()).build());
DistributionSummary summary;
switch(config.mode()) {
case CUMULATIVE:
summary = new CumulativeDistributionSummary(id, clock, merged, scale, false);
break;
case STEP:
default:
summary = new StepDistributionSummary(id, clock, merged, scale, false);
break;
}
HistogramGauges.registerWithCommonFormat(summary, this);
return summary;
}
use of io.micrometer.core.instrument.distribution.DistributionStatisticConfig in project micrometer by micrometer-metrics.
the class SimpleMeterRegistry method newTimer.
@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
DistributionStatisticConfig merged = distributionStatisticConfig.merge(DistributionStatisticConfig.builder().expiry(config.step()).build());
Timer timer;
switch(config.mode()) {
case CUMULATIVE:
timer = new CumulativeTimer(id, clock, merged, pauseDetector, getBaseTimeUnit(), false);
break;
case STEP:
default:
timer = new StepTimer(id, clock, merged, pauseDetector, getBaseTimeUnit(), false);
break;
}
HistogramGauges.registerWithCommonFormat(timer, this);
return timer;
}
Aggregations