66 Any , Callable , Dict , Iterable , List , Literal , Optional , Sequence , Tuple ,
77 Type , TypeVar , Union ,
88)
9+ import warnings
910
1011from . import values # retain this import style for testability
1112from .context_managers import ExceptionCounter , InprogressTracker , Timer
@@ -210,6 +211,11 @@ def labels(self: T, *labelvalues: Any, **labelkwargs: Any) -> T:
210211 return self ._metrics [labelvalues ]
211212
212213 def remove (self , * labelvalues : Any ) -> None :
214+ if 'prometheus_multiproc_dir' in os .environ or 'PROMETHEUS_MULTIPROC_DIR' in os .environ :
215+ warnings .warn (
216+ "Removal of labels has not been implemented in multi-process mode yet." ,
217+ UserWarning )
218+
213219 if not self ._labelnames :
214220 raise ValueError ('No label names were set when constructing %s' % self )
215221
@@ -222,6 +228,10 @@ def remove(self, *labelvalues: Any) -> None:
222228
223229 def clear (self ) -> None :
224230 """Remove all labelsets from the metric"""
231+ if 'prometheus_multiproc_dir' in os .environ or 'PROMETHEUS_MULTIPROC_DIR' in os .environ :
232+ warnings .warn (
233+ "Clearing labels has not been implemented in multi-process mode yet" ,
234+ UserWarning )
225235 with self ._lock :
226236 self ._metrics = {}
227237
@@ -282,6 +292,12 @@ def f():
282292 # Count only one type of exception
283293 with c.count_exceptions(ValueError):
284294 pass
295+
296+ You can also reset the counter to zero in case your logical "process" restarts
297+ without restarting the actual python process.
298+
299+ c.reset()
300+
285301 """
286302 _type = 'counter'
287303
@@ -300,6 +316,11 @@ def inc(self, amount: float = 1, exemplar: Optional[Dict[str, str]] = None) -> N
300316 _validate_exemplar (exemplar )
301317 self ._value .set_exemplar (Exemplar (exemplar , amount , time .time ()))
302318
319+ def reset (self ) -> None :
320+ """Reset the counter to zero. Use this when a logical process restarts without restarting the actual python process."""
321+ self ._value .set (0 )
322+ self ._created = time .time ()
323+
303324 def count_exceptions (self , exception : Union [Type [BaseException ], Tuple [Type [BaseException ], ...]] = Exception ) -> ExceptionCounter :
304325 """Count exceptions in a block of code or function.
305326
0 commit comments