Skip to content

Commit

Permalink
fix(prometheus): Handle +Inf/-Inf from Prometheus (#707)
Browse files Browse the repository at this point in the history
* Handle +Inf/-Inf from prometheus

Prometheus can return not only "NaN", but also "+Inf" and "-Inf" as values for metrics. Handle it properly and not crash if received such.

* fix(prometheus): Handle +Inf/-Inf as values from prometheus

Prometheus can return not only "NaN", but also "+Inf" and "-Inf" as values for metrics. Handle it properly and not crash if received such.

Co-authored-by: Justin Field <justin.field@armory.io>
  • Loading branch information
igcherkaev and fieldju committed Apr 29, 2020
1 parent 88279be commit e8737fa
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -73,7 +73,22 @@ public Object fromBody(TypedInput body, Type type) throws ConversionException {
List<Double> dataValues = new ArrayList<Double>(values.size());

for (List tuple : values) {
dataValues.add(Double.valueOf((String) tuple.get(1)));
String val = (String) tuple.get(1);
if (val != null) {
switch (val) {
case "+Inf":
dataValues.add(Double.POSITIVE_INFINITY);
break;
case "-Inf":
dataValues.add(Double.NEGATIVE_INFINITY);
break;
case "NaN":
dataValues.add(Double.NaN);
break;
default:
dataValues.add(Double.valueOf(val));
}
}
}

long startTimeMillis =
Expand Down

0 comments on commit e8737fa

Please sign in to comment.