prometheus / prometheus/client_python

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

Offen
#1,046 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
4.4k
Forks
876
Ø Merge
8 T. 4 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Implementierung von Info.info() und die vorhandenen Tests zu finden, und reproduziere dann den gemeldeten Fehler mit einem dict, das Werte vom Typ float, int und bool enthält. Die Arbeit ist abgeschlossen, wenn unterstützte Werte, die keine Strings sind, mit einer festgelegten Repräsentation akzeptiert werden und Tests das Konvertierungsverhalten abdecken.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
observability
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.