client_python
client_python copied to clipboard
Metric for label set has incorrect name exposed in multiprocess mode
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.