Spring Boot Version 2.4.8
If you specify a value with the suffix d
for the timer when setting slo, then it is parsed as a number, not a duration.
Example:
management:
metrics:
distribution:
slo:
<YOUR_TIMER_NAME>: 1d, 2d, 3d
The values of the baskets will be 1, 2 ,3
, but required 86400s, 172800s, 259200s
.
To work around this problem, I specify the duration in hours.
Comment From: polarbear567
Hi @bespaltovyj ,
In this configuration, if you want to use seconds as the unit, in your example, I think you should use s
, as follows:
management:
metrics:
distribution:
slo:
<YOUR_TIMER_NAME>: 86400s, 172800s, 259200s
But this is an interesting problem. The root cause of this problem is that we will eventually convert the value to a double type, but for the value like 1d
, the Double.parseDouble(String s)
method will directly convert it to 1.0
.
@wilkinsona @snicoll I don't know what is the ideal treatment for string values like "1d"
in design, whether it is regarded as a double value or a day?
Comment From: wilkinsona
The documentation for the slo
map states the following:
Values can be specified as a long or as a Duration value (for timer meters, defaulting to ms if no unit specified)
I think we should be aiming to match the implementation to that documentation.
Comment From: wilkinsona
It looks like this worked in 2.2 but the behaviour changed due to https://github.com/spring-projects/spring-boot/issues/20837. Contrary to what I said above, it looks like the documentation for the slo
map should have been updated to reflect the switch from long to double. The question now is how to handle a value that's both a valid double and a valid duration such as 1d
.
Comment From: wilkinsona
The question now is how to handle a value that's both a valid double and a valid duration such as 1d.
If we assume that 1d
should be treated as a duration of one day, flipping the order so we trying to parse as a Duration
and then fall back to a double seems to work.