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
- Render infinite values to valid JSON values. Fixes #813 - The 'json' and 'jsonp' formats output float('inf') as 1e9999, float ('-inf') as -1e9999, and float('nan') as null - The 'dygraph' format (a J... — committed to rehevkor5/graphite-web by rehevkor5 8 years ago
- Render infinite values to valid JSON values. Fixes #813 - The 'json' and 'jsonp' formats output float('inf') as 1e9999, float ('-inf') as -1e9999, and float('nan') as null - The 'dygraph' format (a J... — committed to rehevkor5/graphite-web by rehevkor5 8 years ago
- Merge pull request #1710 from rehevkor5/issue-813 Render infinite values to valid JSON values. Fixes #813 — committed to graphite-project/graphite-web by obfuscurity 8 years ago
The assertion that this behavior is
consistent with most JavaScript based encoders and decodersseems incorrect.Infinityis a parse error in both Chrome & Firefox.Chrome:
Firefox:
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=jsonbeing javascript-based [citation needed], we’d better make sureJSON.parseworks 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
strictJsonbut otherwise agree with his suggestions. Anyone volunteering to submit this change? 👅