Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

would be nice if Info.info() accepted non-str types in the given dict #1046

Open
calestyo opened this issue Jul 5, 2024 · 1 comment
Open

Comments

@calestyo
Copy link

calestyo commented Jul 5, 2024

Hey.

Right now, when one feeds a dict into Info.info()that contains values that are notstr` one get's an exception, like:

AttributeError: ("'float' object has no attribute 'replace'", Metric(smart_array, blafasl, info, , [Sample(name='smart_array_info', labels={'slot': '0', 'serial_number': 'xxx', 'controller_status': 'OK', 'hardware_revision': 'B', 'firmware_version': '6.60', 'rebuild_priority': 'High', 'cache_status': 'OK', 'battery_capacitor_status': 'OK', 'controller_temperature_celsius': 49.0, 'cache_module_temperature_celsius': 38.0, 'model': 'Smart Array P840ar'}, value=1.0, timestamp=None, exemplar=None)]))

IMO it woud be nice if that would accept at least other base Python types like int, float and bool and convert these automatically do a suitable representation (which is obvious, I guess, expect perhaps for bool , where one could go by 0/1 (guess that should be it) or True/False/etc.).

Stripping off \n and the likes wouldn't be needed for those types anyway.

Perhaps one could make it generic? Only if the value is an instance of str, try to .replace(...) in all other cases, make a str() out of it?

Maybe with an exception for bool if 0/1 shall be used.

Cheers,
Chris.

@csmarchbanks
Copy link
Member

The problem with accepting non-string values is that it is easy to create a footgun. Numbers are likely to change over the lifetime of a process, which will end up with encoding something like the controller temperature in your example into many different time series. Enforcing that only string values provides an option to correct any mistakes, and if they know what they are doing they can cast the number or other type into a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants