graphite-web: json with `Infinity` values is invalid

When I make a request like http://mygraphite.com/render/?target=some.metric.name&format=json, I expect to get valid JSON.

I sometimes get invalid JSON containing Infinity values.

[{"target": "some.metric.name", "datapoints": [[Infinity, 1407296460], [Infinity, 1407296520], [Infinity, 1407296580]]}]

Not sure what the correct output should be. Maybe null?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

The assertion that this behavior is consistent with most JavaScript based encoders and decoders seems incorrect. Infinity is a parse error in both Chrome & Firefox.

Chrome: Chrome failing to parse Infinity

Firefox: FF failing to parse Infinity

Ping This is hitting us as well since the codahale metrics library initializes values with -infinity, so graphs containing metrics that never got any update in the viewed timeframe will always break, which is not pretty.

Do we know if 3rd party dashboard actually rely on that? I’d be more in favor of fixing the issue. Most dashboards using format=json being javascript-based [citation needed], we’d better make sure JSON.parse works with the returned data 😃

I’d translate +inf to 1e9999, -inf to -1e9999 and nan to null.

Workaround? No.

I think @drawks was on the right track before. I’d prefer a name like strictJson but otherwise agree with his suggestions. Anyone volunteering to submit this change? 👅