graphite-project / carbon

Carbon is one of the components of Graphite, and is responsible for receiving metrics over the network and writing them down to disk using a storage backend.
http://graphite.readthedocs.org/
Apache License 2.0
1.5k stars 490 forks source link

[Feature] Hex-Float Support #930

Closed panzi closed 2 years ago

panzi commented 2 years ago

it would be nice if the protocol would allow to send numbers encoded as hex-floats. All needed would be to change this line:

https://github.com/graphite-project/carbon/blob/9fad18df5731271aab6f5c81d32eddcecdc1a695/lib/carbon/protocols.py#L197

To this:

      datapoint = (
         float.fromhex(timestamp) if timestamp.startswith('0x') else float(timestamp),
         float.fromhex(value) if value.startswith('0x') else float(value)
      )

A metric line in the plain text protocol would then be e.g.:

math.pi 0x1.921fb54442d18p+1 1648758971

Why? Because hex-floats enable exact transfer of floating-point numbers. Decimal doesn't exactly map to the in memory representation of IEEE doubles. But yeah, good float formatters/parsers add enough places to get the exact value across, and it isn't really a problem in practice. Just a nice to have, I think.

deniszh commented 2 years ago

Hi @panzi Yes, could be useful, for some applications, theoretically - but not sure if it's quite needed in practice. But thanks for suggestion!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.