From fb29683091690e4084f4ed23444cb455318d1b16 Mon Sep 17 00:00:00 2001 From: Branislav Jenco Date: Fri, 21 Aug 2026 11:20:37 +0200 Subject: [PATCH 1/6] Added option to set metric name when using _timer decorator --- datareservoirio/client.py | 64 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index 079d37f7..cf14c349 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -316,40 +316,40 @@ def delete(self, series_id): timeout=_TIMEOUT_DEAULT, ) - def _timer(func): + def _timer(metric_name="foo"): """Decorator used to log latency of the ``get`` and ``get_samples_aggregate`` method""" - - @wraps(func) - def wrapper(self, series_id, start=None, end=None, **kwargs): - start_time = time.perf_counter() - result = func(self, series_id, start=start, end=end, **kwargs) - end_time = time.perf_counter() - elapsed_time = end_time - start_time - start_date_as_str = None - end_date_as_str = None - if start: - start_date_as_str = pd.to_datetime( - start, dayfirst=True, unit="ns", utc=True - ).isoformat() - if end: - end_date_as_str = pd.to_datetime( - end, dayfirst=True, unit="ns", utc=True - ).isoformat() - number_of_samples = len(result) - properties = { - "series_id": series_id, - "start": start_date_as_str, - "end": end_date_as_str, - "elapsed": elapsed_time, - "number-of-samples": number_of_samples, - } - metric().info("Timer", extra=properties) - return result - - return wrapper + def decorator(func): + @wraps(func) + def wrapper(self, series_id, start=None, end=None, **kwargs): + start_time = time.perf_counter() + result = func(self, series_id, start=start, end=end, **kwargs) + end_time = time.perf_counter() + elapsed_time = end_time - start_time + start_date_as_str = None + end_date_as_str = None + if start: + start_date_as_str = pd.to_datetime( + start, dayfirst=True, unit="ns", utc=True + ).isoformat() + if end: + end_date_as_str = pd.to_datetime( + end, dayfirst=True, unit="ns", utc=True + ).isoformat() + number_of_samples = len(result) + properties = { + "series_id": series_id, + "start": start_date_as_str, + "end": end_date_as_str, + "elapsed": elapsed_time, + "number-of-samples": number_of_samples, + } + metric().info(metric_name, extra=properties) + return result + return wrapper + return decorator @log_decorator("exception") - @_timer + @_timer("Timer_get") @retry( stop=stop_after_attempt( 4 @@ -455,7 +455,7 @@ def get( return series @log_decorator("exception") - @_timer + @_timer("Timer_get_samples_aggregate") @log_decorator("warning") def get_samples_aggregate( self, From 2099481157599d739a3676dd97d0e779f732854a Mon Sep 17 00:00:00 2001 From: Branislav Jenco Date: Fri, 21 Aug 2026 11:24:05 +0200 Subject: [PATCH 2/6] Renaming from foo to Timer after test --- datareservoirio/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index cf14c349..ab984199 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -316,7 +316,7 @@ def delete(self, series_id): timeout=_TIMEOUT_DEAULT, ) - def _timer(metric_name="foo"): + def _timer(metric_name="Timer"): """Decorator used to log latency of the ``get`` and ``get_samples_aggregate`` method""" def decorator(func): @wraps(func) From 8a1c3b2c8ffecbe72e6043a4a673ac068558b318 Mon Sep 17 00:00:00 2001 From: Branislav Jenco Date: Fri, 21 Aug 2026 11:25:46 +0200 Subject: [PATCH 3/6] Making Black happy --- datareservoirio/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index ab984199..0d484d7b 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -318,6 +318,7 @@ def delete(self, series_id): def _timer(metric_name="Timer"): """Decorator used to log latency of the ``get`` and ``get_samples_aggregate`` method""" + def decorator(func): @wraps(func) def wrapper(self, series_id, start=None, end=None, **kwargs): @@ -345,7 +346,9 @@ def wrapper(self, series_id, start=None, end=None, **kwargs): } metric().info(metric_name, extra=properties) return result + return wrapper + return decorator @log_decorator("exception") From b9c1cb2b87185239c39a9981ecb2bf5a7b4145b4 Mon Sep 17 00:00:00 2001 From: Branislav Jenco <152614622+branislav-jenco-4ss@users.noreply.github.com> Date: Fri, 21 Aug 2026 11:46:53 +0200 Subject: [PATCH 4/6] Fix wording in comment Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- datareservoirio/client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index 0d484d7b..6a5bb421 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -316,9 +316,14 @@ def delete(self, series_id): timeout=_TIMEOUT_DEAULT, ) - def _timer(metric_name="Timer"): - """Decorator used to log latency of the ``get`` and ``get_samples_aggregate`` method""" +def _timer(metric_name="Timer"): + """Decorator factory used to log latency for the ``get`` and ``get_samples_aggregate`` methods. + Parameters + ---------- + metric_name : str + Metric name to emit (use a stable, low-cardinality value). + """ def decorator(func): @wraps(func) def wrapper(self, series_id, start=None, end=None, **kwargs): From 28963a634f4565b6f634485373e12b786f0d607d Mon Sep 17 00:00:00 2001 From: Branislav Jenco Date: Fri, 21 Aug 2026 11:49:05 +0200 Subject: [PATCH 5/6] Copilot messed up formatting --- datareservoirio/client.py | 62 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index 6a5bb421..27c0dd2d 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -316,6 +316,7 @@ def delete(self, series_id): timeout=_TIMEOUT_DEAULT, ) + def _timer(metric_name="Timer"): """Decorator factory used to log latency for the ``get`` and ``get_samples_aggregate`` methods. @@ -324,37 +325,38 @@ def _timer(metric_name="Timer"): metric_name : str Metric name to emit (use a stable, low-cardinality value). """ - def decorator(func): - @wraps(func) - def wrapper(self, series_id, start=None, end=None, **kwargs): - start_time = time.perf_counter() - result = func(self, series_id, start=start, end=end, **kwargs) - end_time = time.perf_counter() - elapsed_time = end_time - start_time - start_date_as_str = None - end_date_as_str = None - if start: - start_date_as_str = pd.to_datetime( - start, dayfirst=True, unit="ns", utc=True - ).isoformat() - if end: - end_date_as_str = pd.to_datetime( - end, dayfirst=True, unit="ns", utc=True - ).isoformat() - number_of_samples = len(result) - properties = { - "series_id": series_id, - "start": start_date_as_str, - "end": end_date_as_str, - "elapsed": elapsed_time, - "number-of-samples": number_of_samples, - } - metric().info(metric_name, extra=properties) - return result - - return wrapper - return decorator + def decorator(func): + @wraps(func) + def wrapper(self, series_id, start=None, end=None, **kwargs): + start_time = time.perf_counter() + result = func(self, series_id, start=start, end=end, **kwargs) + end_time = time.perf_counter() + elapsed_time = end_time - start_time + start_date_as_str = None + end_date_as_str = None + if start: + start_date_as_str = pd.to_datetime( + start, dayfirst=True, unit="ns", utc=True + ).isoformat() + if end: + end_date_as_str = pd.to_datetime( + end, dayfirst=True, unit="ns", utc=True + ).isoformat() + number_of_samples = len(result) + properties = { + "series_id": series_id, + "start": start_date_as_str, + "end": end_date_as_str, + "elapsed": elapsed_time, + "number-of-samples": number_of_samples, + } + metric().info(metric_name, extra=properties) + return result + + return wrapper + + return decorator @log_decorator("exception") @_timer("Timer_get") From 85da85ac36c175630a4061c84029bd227b2518cc Mon Sep 17 00:00:00 2001 From: Branislav Jenco Date: Fri, 21 Aug 2026 11:52:21 +0200 Subject: [PATCH 6/6] More formatting... --- datareservoirio/client.py | 75 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/datareservoirio/client.py b/datareservoirio/client.py index 27c0dd2d..22c7ca4c 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -316,47 +316,46 @@ def delete(self, series_id): timeout=_TIMEOUT_DEAULT, ) + def _timer(metric_name="Timer"): + """Decorator factory used to log latency for the ``get`` and ``get_samples_aggregate`` methods. -def _timer(metric_name="Timer"): - """Decorator factory used to log latency for the ``get`` and ``get_samples_aggregate`` methods. + Parameters + ---------- + metric_name : str + Metric name to emit (use a stable, low-cardinality value). + """ - Parameters - ---------- - metric_name : str - Metric name to emit (use a stable, low-cardinality value). - """ + def decorator(func): + @wraps(func) + def wrapper(self, series_id, start=None, end=None, **kwargs): + start_time = time.perf_counter() + result = func(self, series_id, start=start, end=end, **kwargs) + end_time = time.perf_counter() + elapsed_time = end_time - start_time + start_date_as_str = None + end_date_as_str = None + if start: + start_date_as_str = pd.to_datetime( + start, dayfirst=True, unit="ns", utc=True + ).isoformat() + if end: + end_date_as_str = pd.to_datetime( + end, dayfirst=True, unit="ns", utc=True + ).isoformat() + number_of_samples = len(result) + properties = { + "series_id": series_id, + "start": start_date_as_str, + "end": end_date_as_str, + "elapsed": elapsed_time, + "number-of-samples": number_of_samples, + } + metric().info(metric_name, extra=properties) + return result + + return wrapper - def decorator(func): - @wraps(func) - def wrapper(self, series_id, start=None, end=None, **kwargs): - start_time = time.perf_counter() - result = func(self, series_id, start=start, end=end, **kwargs) - end_time = time.perf_counter() - elapsed_time = end_time - start_time - start_date_as_str = None - end_date_as_str = None - if start: - start_date_as_str = pd.to_datetime( - start, dayfirst=True, unit="ns", utc=True - ).isoformat() - if end: - end_date_as_str = pd.to_datetime( - end, dayfirst=True, unit="ns", utc=True - ).isoformat() - number_of_samples = len(result) - properties = { - "series_id": series_id, - "start": start_date_as_str, - "end": end_date_as_str, - "elapsed": elapsed_time, - "number-of-samples": number_of_samples, - } - metric().info(metric_name, extra=properties) - return result - - return wrapper - - return decorator + return decorator @log_decorator("exception") @_timer("Timer_get")