Java Code Examples for io.micrometer.core.instrument.config.MeterFilter#maximumAllowableTags()

The following examples show how to use io.micrometer.core.instrument.config.MeterFilter#maximumAllowableTags() . 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: MeterFilterTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void maximumAllowableTagsWhenDifferentTagKeyShouldNotAffect() {
    MeterFilter onMaxReached = mock(MeterFilter.class);
    MeterFilter filter = MeterFilter.maximumAllowableTags("name1", "key1", 3, onMaxReached);

    Meter.Id id1 = new Meter.Id("name1", Tags.of("key1", "value1"), null, null, Meter.Type.COUNTER);
    Meter.Id id2 = new Meter.Id("name1", Tags.of("key1", "value2"), null, null, Meter.Type.COUNTER);
    Meter.Id id3 = new Meter.Id("name1", Tags.of("key1", "value3"), null, null, Meter.Type.COUNTER);
    Meter.Id id4 = new Meter.Id("name1", Tags.of("key1", "value4"), null, null, Meter.Type.COUNTER);
    Meter.Id id5 = new Meter.Id("name1", Tags.of("key2", "value5"), null, null, Meter.Type.COUNTER);

    filter.accept(id1);
    filter.accept(id2);
    filter.accept(id3);
    verifyNoInteractions(onMaxReached);

    filter.accept(id4);
    verify(onMaxReached).accept(id4);

    filter.accept(id5);
    verifyNoMoreInteractions(onMaxReached);
}
 
Example 2
Source File: MeterFilterTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void maximumAllowableTagsWhenAlreadyInAllowableTagValuesShouldNotAffect() {
    MeterFilter onMaxReached = mock(MeterFilter.class);
    MeterFilter filter = MeterFilter.maximumAllowableTags("name1", "key1", 3, onMaxReached);

    Meter.Id id1 = new Meter.Id("name1", Tags.of("key1", "value1"), null, null, Meter.Type.COUNTER);
    Meter.Id id2 = new Meter.Id("name1", Tags.of("key1", "value2"), null, null, Meter.Type.COUNTER);
    Meter.Id id3 = new Meter.Id("name1", Tags.of("key1", "value3"), null, null, Meter.Type.COUNTER);
    Meter.Id id4 = new Meter.Id("name1", Tags.of("key1", "value4"), null, null, Meter.Type.COUNTER);

    filter.accept(id1);
    filter.accept(id2);
    filter.accept(id3);
    verifyNoInteractions(onMaxReached);

    filter.accept(id4);
    verify(onMaxReached).accept(id4);

    filter.accept(id1);
    verifyNoMoreInteractions(onMaxReached);
}
 
Example 3
Source File: WebMvcMetricsAutoConfiguration.java    From foremast with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(0)
public MeterFilter metricsHttpServerUriTagFilter() {
    String metricName = this.properties.getWeb().getServer().getRequestsMetricName();
    MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(() -> String
            .format("Reached the maximum number of URI tags for '%s'.", metricName));
    return MeterFilter.maximumAllowableTags(metricName, "uri",
            this.properties.getWeb().getServer().getMaxUriTags(), filter);
}
 
Example 4
Source File: MetricsAutoConfiguration.java    From foremast with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(0)
public MeterFilter metricsHttpServerUriTagFilter(MetricsProperties properties) {
    String metricName = properties.getWeb().getServer().getRequestsMetricName();
    MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(() -> String
            .format("Reached the maximum number of URI tags for '%s'.", metricName));
    return MeterFilter.maximumAllowableTags(metricName, "uri",
            properties.getWeb().getServer().getMaxUriTags(), filter);
}