Skip to content

Spring Boot (version 3.1.2) has UNKNOWN status in prometheus metrics #31028

Closed as not planned
@dimon8829

Description

@dimon8829

Hi all. When I switched to spring boot from version 2.2.13.RELEASE to version 3.1.2, there was a problem with the metrics.

application.yml:

management:
  endpoint:
    health:
      show-details: "ALWAYS"
    endpoint:
      metrics:
        enabled: true
      prometheus:
        enabled: true
  endpoints:
    web:
      exposure:
        include: "*"
  metrics:
    export:
      prometheus:
        enabled: true

Namely, in some metrics, the UNKNOWN status appeared. Although in fact all requests were successful and should have a status of 200:

http_server_requests_seconds_count{error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 9993.0
http_server_requests_seconds_sum{error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 80.860505828
http_server_requests_seconds_count{error="none",exception="none",method="GET",outcome="UNKNOWN",status="UNKNOWN",uri="/actuator/prometheus",} 10.0
http_server_requests_seconds_sum{error="none",exception="none",method="GET",outcome="UNKNOWN",status="UNKNOWN",uri="/actuator/prometheus",} 0.170536004

This can be easily reproduced by sending 1000 parallel requests to the /actuator/prometheus endpoint:

    public static void main(String[] args) {
        int numThreads = 10;
        int numRequestsPerThread = 1000;

        ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
        HttpClient httpClient = HttpClient.newHttpClient();

        for (int i = 0; i < numThreads; i++) {
            executorService.submit(() -> {
                for (int j = 0; j < numRequestsPerThread; j++) {
                    sendHttpRequest(httpClient, "http://localhost:8080/actuator/prometheus");
                }
            });
        }

        executorService.shutdown();
    }

    private static void sendHttpRequest(HttpClient httpClient, String url) {
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .GET()
                .build();

        try {
            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
            if (response.statusCode() != 200) {
                System.out.println("Response Code: " + response.statusCode());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

What could be causing this problem and how to fix it? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions