prometheus / prometheus/client_python

Metric for label set has incorrect name exposed in multiprocess mode

Offen
#1,035 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

The following piece of code from the metrics.py

        with self._lock:
            if labelvalues not in self._metrics:
                self._metrics[labelvalues] = self.__class__(
                    self._name,
                    documentation=self._documentation,
                    labelnames=self._labelnames,
                    unit=self._unit,
                    _labelvalues=labelvalues,
                    **self._kwargs
                )

passes the self._name as name parameter in the ctor. The problem is that at this point self._name is actually a full name created by _build_full_name(), for example mynamespace_mysubsystem_mymetric_myunit. Unfortunately, this name undergoes a second round of full name construction. In case of default ctor, where namespace, subsystem and unit all have str = '' default value, this is not a big deal. But if a library user has custom ctor with non-empty default values it causes a pretty weird name to be produced:

mydefaultnamespace_mydefaultsubsystem_mynamespace_mysubsystem_mymetric_myunit_mydefaultunit

Now, in non-multiprocess mode this is not a problem as collector takes the metric name from the parent metric and simply append the child metric labels and values. But multiprocess collector takes what is present in the process files, and those have child metric names.

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 in metrics.py bei etwa den Zeilen 201-210 und verfolge, wie untergeordnete Metriknamen für den multiprocess collector geschrieben werden. Reproduziere den Fall mit nicht leeren namespace-, subsystem- und unit-Standardwerten und überprüfe anschließend, dass der Metrikname der Prozessdatei nicht zweimal erstellt wird und mit dem vorgesehenen vollständigen Namen übereinstimmt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
observability
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

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