Skip to content

Commit 1f5b1ea

Browse files
committed
Use constants
1 parent a1a1e06 commit 1f5b1ea

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main/java/org/gridsuite/gateway/NettyMetricsConfiguration.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.springframework.context.annotation.Configuration;
1414
import reactor.netty.http.server.HttpServer;
1515

16+
import java.util.List;
1617
import java.util.function.Function;
1718

1819
/**
@@ -22,6 +23,15 @@
2223
// Enable Netty metrics that are not enabled by default in Spring Boot.
2324
@Configuration
2425
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+
2535
@Override
2636
public HttpServer apply(HttpServer httpServer) {
2737
return httpServer.metrics(true, Function.identity());
@@ -32,14 +42,11 @@ public MeterFilter meterFilter() {
3242
return MeterFilter.denyUnless(id -> {
3343
String name = id.getName();
3444
// Allow all non-reactor metrics
35-
if (!name.startsWith("reactor.netty")) {
45+
if (!name.startsWith(REACTOR_NETTY_PREFIX)) {
3646
return true;
3747
}
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);
4350
});
4451
}
4552
}

0 commit comments

Comments
 (0)