Skip to content

Commit 4a6b656

Browse files
committed
move the deprecation warning inside MultiProcessValue
In case people use directly `MultiProcessValue`, the deprecation warning will pop up. Added another warning if both are defined.
1 parent 38c65cf commit 4a6b656

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

prometheus_client/values.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class MmapedValue(object):
5252

5353
def __init__(self, typ, metric_name, name, labelnames, labelvalues, multiprocess_mode='', **kwargs):
5454
self._params = typ, metric_name, name, labelnames, labelvalues, multiprocess_mode
55+
# This deprecation warning can go away in a few releases when removing the compatibility
56+
if 'prometheus_multiproc_dir' in os.environ and 'PROMETHEUS_MULTIPROC_DIR' in os.environ:
57+
warnings.warn("You have declared both env variable in upper case and lower case, keep the upper case only PROMETHEUS_MULTIPROC_DIR'", DeprecationWarning)
58+
if 'prometheus_multiproc_dir' in os.environ and 'PROMETHEUS_MULTIPROC_DIR' not in os.environ:
59+
os.environ['PROMETHEUS_MULTIPROC_DIR'] = os.environ['prometheus_multiproc_dir']
60+
warnings.warn("You should declare the env variable in upper case PROMETHEUS_MULTIPROC_DIR'", DeprecationWarning)
5561
with lock:
5662
self.__check_for_pid_change()
5763
self.__reset()
@@ -109,10 +115,7 @@ def get_value_class():
109115
# This needs to be chosen before the first metric is constructed,
110116
# and as that may be in some arbitrary library the user/admin has
111117
# no control over we use an environment variable.
112-
if 'prometheus_multiproc_dir' in os.environ and 'PROMETHEUS_MULTIPROC_DIR' not in os.environ:
113-
os.environ['PROMETHEUS_MULTIPROC_DIR'] = os.environ['prometheus_multiproc_dir']
114-
warnings.warn("You should declare the env variable in upper case PROMETHEUS_MULTIPROC_DIR'", DeprecationWarning)
115-
if 'PROMETHEUS_MULTIPROC_DIR' in os.environ:
118+
if 'prometheus_multiproc_dir' in os.environ or 'PROMETHEUS_MULTIPROC_DIR' in os.environ:
116119
return MultiProcessValue()
117120
else:
118121
return MutexValue

0 commit comments

Comments
 (0)