prometheus / prometheus/client_python

feature request/RFC: leave out a label (from at least `*MetricFamily` samples) when it's value is set to `None`

Offen
#1,176 0 Kommentare 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.

This is somewhat related to https://github.com/prometheus/docs/issues/2977, i.e. “what to do if some values of a sample aren’t available”, which obviously may not just be the actual metric value but also values of labels.

AFAIU, labels values are always strings, so sometimes it may be possible to use a special label value to indicate an error, for example if the label would be a host, one might simply use some characters that cannot appear in hostnames or addresses and thus either an empty string or perhaps <unknown> or similar values depending on the error.

But sometimes this may not be possible, in particular when the possible label values are arbitrary (like I have a case where the label is a description which may contain any string including the empty one).

Now in the error case (at least in my use case) it's better to have the rest of the data, but it still feels wrong to use a value for it that would be valid, even though I couldn't determine it on that particular scrape.
The time series is likely anyway already interrupted, so what's IMO the cleanest solution is simply leaving out the respective label in the error case, even if I have another metric which somehow indicates that sometime is fishy (like _up or so).

(Or any better ideas?)

Now I guess often, exporters will simply have a set of *MetricFamily-objects and .add_metrics to it, which requires however all the values for the defined labels to be given.

My proposal/RFC here is: Would it make sense to special-handle a value of None (which currently seems to simply lead to an error), causing it to leave that particular label out from the printed data for the particular label only?

I guess I could look in implementing this, but on a first short glance it didn't seem straightforward, so I wanted to ask what people even think about it.

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

Beginnen Sie damit, die Implementierungen der *MetricFamily-Klassen, von add_metric und des Pfads für die Ausgabeserialisierung zu finden. Prüfen Sie anschließend, wie None-Labelwerte derzeit validiert werden. Definieren und testen Sie das Verhalten, bei dem nur das betroffene Label weggelassen wird, während die übrigen Sample-Daten erhalten bleiben, nachdem Sie bestätigt haben, dass die Maintainer des Projekts diesem RFC zustimmen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
observability-sre
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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