go-graphite / carbonapi

Implementation of graphite API (graphite-web) in golang
Other
308 stars 140 forks source link

Use IntOrInf type for keepLastValue and interpolate #788

Closed fionaliao closed 1 year ago

fionaliao commented 1 year ago

This PR makes infinity handling in carbonapi closer to graphite-web behaviour.

IntOrInf parameter

In graphite-web, the second parameter for the functions keepLastValue and interpolate is intOrInf, with the default being INF

Currently carbonapi treats the second parameter as a float that could be infinity.

graphite-web does not allow floats apart from infinity for this parameter: https://github.com/graphite-project/graphite-web/blob/dca59dc72ae28ffdae659232c10c60aa598536eb/webapp/graphite/functions/params.py#L64-L77

This PR introduces an InfOrInf type that behaves like graphite-web for these two functions.

Inf marshalling

In graphite-web, infinity values in suggestions are marshalled to 1e9999 in JSON, as infinity is not valid for browsers/nodejs

See: https://github.com/graphite-project/graphite-web/blob/dca59dc72ae28ffdae659232c10c60aa598536eb/webapp/graphite/functions/views.py#L9 and https://github.com/graphite-project/graphite-web/pull/2612.

Therefore I've updated the suggestion struct marshalling function to replace infinity with 1e9999 to match graphite-web behaviour.