This commit is contained in:
Anthony Stirling 2025-03-19 00:23:22 +00:00
parent 853744864b
commit d645159a9f

View File

@ -24,9 +24,6 @@ public class MetricsAggregatorService {
private final EndpointInspector endpointInspector; private final EndpointInspector endpointInspector;
private final Map<String, Double> lastSentMetrics = new ConcurrentHashMap<>(); private final Map<String, Double> lastSentMetrics = new ConcurrentHashMap<>();
// Flag to decide behavior if no endpoints are discovered
private boolean allowAllGetEndpointsIfNoneDiscovered = true;
@Autowired @Autowired
public MetricsAggregatorService( public MetricsAggregatorService(
MeterRegistry meterRegistry, MeterRegistry meterRegistry,
@ -37,17 +34,11 @@ public class MetricsAggregatorService {
this.endpointInspector = endpointInspector; this.endpointInspector = endpointInspector;
} }
@Scheduled(fixedRate = 72000) // Run every 2 hours @Scheduled(fixedRate = 7200000) // Run every 2 hours
public void aggregateAndSendMetrics() { public void aggregateAndSendMetrics() {
Map<String, Object> metrics = new HashMap<>(); Map<String, Object> metrics = new HashMap<>();
int endpointCount = endpointInspector.getValidGetEndpoints().size(); final boolean validateGetEndpoints = endpointInspector.getValidGetEndpoints().size() != 0;
boolean validateGetEndpoints = true;
if (endpointCount == 0 && allowAllGetEndpointsIfNoneDiscovered) {
validateGetEndpoints = false;
}
final boolean validateGetEndpointsFinal = validateGetEndpoints;
Search.in(meterRegistry) Search.in(meterRegistry)
.name("http.requests") .name("http.requests")
.counters() .counters()
@ -81,7 +72,7 @@ public class MetricsAggregatorService {
} }
// For GET requests, validate if we have a list of valid endpoints // For GET requests, validate if we have a list of valid endpoints
if ("GET".equals(method) if ("GET".equals(method)
&& validateGetEndpointsFinal && validateGetEndpoints
&& !endpointInspector.isValidGetEndpoint(uri)) { && !endpointInspector.isValidGetEndpoint(uri)) {
logger.debug("Skipping invalid GET endpoint: {}", uri); logger.debug("Skipping invalid GET endpoint: {}", uri);
return; return;