GH-3396: Add Docs for Micrometer MeterFilters
Resolves https://github.com/spring-projects/spring-integration/issues/3396 * Add an example.
This commit is contained in:
@@ -59,6 +59,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.config.MeterFilter;
|
||||
import io.micrometer.core.instrument.search.MeterNotFoundException;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
|
||||
@@ -92,6 +93,9 @@ public class MicrometerMetricsTests {
|
||||
@Autowired
|
||||
private QueueChannel queue;
|
||||
|
||||
@Autowired
|
||||
private QueueChannel noMeters;
|
||||
|
||||
@Autowired
|
||||
private PollableChannel badPoll;
|
||||
|
||||
@@ -131,7 +135,7 @@ public class MicrometerMetricsTests {
|
||||
|
||||
nullChannel.send(message);
|
||||
MeterRegistry registry = this.meterRegistry;
|
||||
assertThat(registry.get("spring.integration.channels").gauge().value()).isEqualTo(7);
|
||||
assertThat(registry.get("spring.integration.channels").gauge().value()).isEqualTo(8);
|
||||
assertThat(registry.get("spring.integration.handlers").gauge().value()).isEqualTo(4);
|
||||
assertThat(registry.get("spring.integration.sources").gauge().value()).isEqualTo(1);
|
||||
|
||||
@@ -243,6 +247,13 @@ public class MicrometerMetricsTests {
|
||||
.tag("result", "success")
|
||||
.timer().count()).isEqualTo(2);
|
||||
|
||||
this.noMeters.send(message);
|
||||
assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> registry.get("spring.integration.send")
|
||||
.tag("type", "channel")
|
||||
.tag("name", "noMeters")
|
||||
.tag("result", "success")
|
||||
.timer().count());
|
||||
|
||||
this.context.close();
|
||||
|
||||
assertThatExceptionOfType(MeterNotFoundException.class)
|
||||
@@ -264,7 +275,11 @@ public class MicrometerMetricsTests {
|
||||
|
||||
@Bean
|
||||
public static MeterRegistry meterRegistry() {
|
||||
return new SimpleMeterRegistry();
|
||||
SimpleMeterRegistry registry = new SimpleMeterRegistry();
|
||||
registry.config().meterFilter(MeterFilter.deny(id ->
|
||||
"channel".equals(id.getTag("type")) &&
|
||||
"noMeters".equals(id.getTag("name"))));
|
||||
return registry;
|
||||
}
|
||||
|
||||
@ServiceActivator(inputChannel = "channel")
|
||||
@@ -310,6 +325,11 @@ public class MicrometerMetricsTests {
|
||||
return new QueueChannel(10);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QueueChannel noMeters() {
|
||||
return new QueueChannel(10);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PollableChannel badPoll() {
|
||||
return new AbstractPollableChannel() {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
This section describes how to capture metrics for Spring Integration.
|
||||
In recent versions, we have relied more on Micrometer (see https://micrometer.io), and we plan to use Micrometer even more in future releases.
|
||||
|
||||
[[configuring-metrics-capture]]
|
||||
[[legacy-metrics]]
|
||||
==== Legacy Metrics
|
||||
|
||||
Legacy metrics were removed in Version 5.4; see Micrometer Integration below.
|
||||
@@ -48,6 +48,8 @@ IMPORTANT: `defaultLoggingEnabled` is applied only if you have not explicitly co
|
||||
[[micrometer-integration]]
|
||||
==== Micrometer Integration
|
||||
|
||||
===== Overview
|
||||
|
||||
Starting with version 5.0.3, the presence of a https://micrometer.io/[Micrometer] `MeterRegistry` in the application context triggers support for Micrometer metrics.
|
||||
|
||||
To use Micrometer, add one of the `MeterRegistry` beans to the application context.
|
||||
@@ -118,3 +120,34 @@ and
|
||||
* `tag`: `type:channel`
|
||||
* `tag`: `name:<componentName>`
|
||||
* `description`: `The remaining capacity of the queue channel`
|
||||
|
||||
===== Disabling Meters
|
||||
|
||||
With the <<legacy-metrics>> (which have now been removed), you could specify which integration components would collect metrics.
|
||||
By default, all meters are registered when first used.
|
||||
Now, with Micrometer, you can add `MeterFilter` s to the `MeterRegistry` to prevent some or all from being registered.
|
||||
You can filter out (deny) meters by any of the properties provided, `name`, `tag`, etc.
|
||||
See https://micrometer.io/docs/concepts#_meter_filters[Meter Filters] in the Micrometer documentation for more information.
|
||||
|
||||
For example, given:
|
||||
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
@Bean
|
||||
public QueueChannel noMeters() {
|
||||
return new QueueChannel(10);
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
You can suppress registration of meters for just this channel with:
|
||||
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
registry.config().meterFilter(MeterFilter.deny(id ->
|
||||
"channel".equals(id.getTag("type")) &&
|
||||
"noMeters".equals(id.getTag("name"))));
|
||||
----
|
||||
====
|
||||
|
||||
Reference in New Issue
Block a user