http-headersprometheusspring-boot-3

Why Spring Boot 3 is logging HTTP 406 Not Acceptable in response to Prometheous scrape request?


I am using a Spring Boot app and trying to setup Prometheus to monitor is performance during the production time. But when I am starting the prometheus server, it is not able to gather the scraping data from the Spring Boot due to the following exception. [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]

I have dug deeper into this and found the following:

GET "/actuator/prometheus", parameters={}, headers={host:[localhost:8080], user-agent:[Prometheus/2.49.0-rc.0], accept:[application/openmetrics-text;version=1.0.0;q=0.5,application/openmetrics-text;version=0.0.1;q=0.4,text/plain;version=0.0.4;q=0.3,*/*;q=2], accept-encoding:[gzip], x-prometheus-scrape-timeout-seconds:[3]} in DispatcherServlet 'dispatcherServlet'
2023-12-19T14:45:03.521+05:30  WARN 3767 --- [0.0-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]
2023-12-19T14:45:03.521+05:30 TRACE 3767 --- [0.0-8080-exec-3] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2023-12-19T14:45:03.521+05:30 DEBUG 3767 --- [0.0-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 406 NOT_ACCEPTABLE, headers={Access-Control-Allow-Origin:[*], Access-Control-Allow-Methods:[POST, PUT, GET, OPTIONS, DELETE], Access-Control-Max-Age:[3600], Access-Control-Allow-Headers:[Content-Type, Authorization, Control-Length, X-Requested-With], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Accept:[text/plain;version=0.0.4;charset=utf-8, application/openmetrics-text;version=1.0.0;charset=utf-8], X-Content-Type-Options:[nosniff], X-XSS-Protection:[0], Cache-Control:[no-cache, no-store, max-age=0, must-revalidate], Pragma:[no-cache], Expires:[0], X-Frame-Options:[DENY]}

This is the log of my Spring Boot app from the console.

I am able to understand that the problem is occuring due to the headers of the Prometheus request but, I am not sure how to configure my Spring Boot app, to produce a compatible response for prometheus?

Please suggest some solutions to this problem?


Solution

  • I have discovered that it happened because of Prometheus sends request with the header

    Accept: application/openmetrics-text;version=1.0.0;q=0.5,application/openmetrics-text;version=0.0.1;q=0.4,text/plain;version=0.0.4;q=0.3,*/*;q=2
    

    So, it looks like Quality values should be between 0.0 and 1.0