13
13
import org .springframework .context .annotation .Configuration ;
14
14
import reactor .netty .http .server .HttpServer ;
15
15
16
+ import java .util .List ;
16
17
import java .util .function .Function ;
17
18
18
19
/**
22
23
// Enable Netty metrics that are not enabled by default in Spring Boot.
23
24
@ Configuration
24
25
public class NettyMetricsConfiguration implements NettyServerCustomizer {
26
+
27
+ private static final String REACTOR_NETTY_PREFIX = "reactor.netty" ;
28
+ // If additional metrics are added, ensure the URIs are provided in a template-like format.
29
+ // Without this, each unique URI generates a separate tag, which takes a lot of memory
30
+ private static final List <String > ALLOWED_REACTOR_NETTY_METRICS = List .of (
31
+ "reactor.netty.http.server.connections.total" ,
32
+ "reactor.netty.http.server.connections.active"
33
+ );
34
+
25
35
@ Override
26
36
public HttpServer apply (HttpServer httpServer ) {
27
37
return httpServer .metrics (true , Function .identity ());
@@ -32,14 +42,11 @@ public MeterFilter meterFilter() {
32
42
return MeterFilter .denyUnless (id -> {
33
43
String name = id .getName ();
34
44
// Allow all non-reactor metrics
35
- if (!name .startsWith ("reactor.netty" )) {
45
+ if (!name .startsWith (REACTOR_NETTY_PREFIX )) {
36
46
return true ;
37
47
}
38
- // Allow only the specific reactor metrics that we use.
39
- // If additional metrics are added, ensure the URIs are provided in a template-like format.
40
- // Without this, each unique URI generates a separate tag, which takes a lot of memory.
41
- return name .equals ("reactor.netty.http.server.connections" ) ||
42
- name .equals ("reactor.netty.http.server.connections.active" );
48
+ // Allow only the specific reactor metrics that we use
49
+ return ALLOWED_REACTOR_NETTY_METRICS .contains (name );
43
50
});
44
51
}
45
52
}
0 commit comments