Conversation
…"INF" and "Nan" special values. Mimics the return values used in api/v1/query Signed-off-by: Devin Trejo <dtrejo@palantir.com>
98e97f7 to
86ce89f
Compare
|
Thanks for spotting this! Tracking it down, the culprit is the json-iterator library which doesn't produce 100% compliant data. Another option would be to encode such values as In general the v1 API is considered stable but we have a disclaimer in the documentation for rules and alerts. |
|
What does the standard Go JSON library do with these? |
|
It returns an error: |
|
Okay, using the same approach we do for the query apis seems best then. I think the code can be cleaner, we should do whatever we do in the query api. |
|
Willing to rework the PR if need be. It looks like the other Marshalling functions used by the Would adding a reusable |
|
A Scalar should be enough here. |
91dfb68 to
5422131
Compare
Signed-off-by: Devin Trejo <dtrejo@palantir.com>
Signed-off-by: Devin Trejo <dtrejo@palantir.com>
Signed-off-by: Devin Trejo <dtrejo@palantir.com>
f81c3ec to
1042ec9
Compare
|
Latest commit uses Scalars. Apologies for the mess of commits as I pushed the wrong branch originally. Let me know if all looks good. |
| }, | ||
| "state": "firing", | ||
| "value": 1 | ||
| "value": [ |
There was a problem hiding this comment.
That's not right, it should be the value as a string - not a list with a timestamp.
There was a problem hiding this comment.
This is using the Scalar type as suggested which is a timestamp + value. If we are okay with modifying the API to return a different value type I think this approach is the best solution as it mimics what the query API currently returns.
There was a problem hiding this comment.
We're technically allowed to make breaking changes here, however if we wanted the timestamp I think we'd put it in a different field.
There was a problem hiding this comment.
Why not keep is the same as the query API?
$ curl -s -g 'http://$(hostname)/prometheus/api/v1/query?query=count(up)/0'|jq .
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {},
"value": [
1551461908.309,
"+Inf"
]
}
]
}
}
There was a problem hiding this comment.
That'd break existing users unnecessarily.
There was a problem hiding this comment.
Okay I understand. I thought we were moving forward with breaking the API given the clause.
Also, sorry I've been busy with other work. Hopefully I can revisit sometime next week. If someone wants to implement this before me, feel free.
|
@dtrejod are you willing to carry on the PR? |
|
Superseded by #5582 |
This patch changes the
api/v1/alertendpoint to return string alert values mimicking theapi/v1/queryreturn values. The change ensuresnull, and+-Infvalues can be properly parsed.We are using the
client_golanglibrary in our applications to interact with theapi/v1/alertendpoint. We've recently hit an issue where the library failed to parse the return values from a+Infalert value. We traced the problem back to the alert api not using string return values. We noticedNaNvalues are also affected.Problem
Create an alert with a
+Infreturn value; for examplecount(up)/0 != 0. When curling the api endpoint you can see the returned value is as follows:Running the same query against the
queryapi results in:The resulting error when parsing using the
client_golanglibrary is:Solution
This patch converts the return values for the
alertapi to strings. Running the same query now results with:Prometheus Version: 2.6.0