From b7795b3e2ee22d196ab52d140806ad386cec6f97 Mon Sep 17 00:00:00 2001 From: clearml <> Date: Tue, 31 Dec 2024 22:06:05 +0200 Subject: [PATCH] Do not drop service request num to 0 on the chart for the periods when serving model was not reporting --- apiserver/bll/serving/stats.py | 13 +++++++++---- apiserver/utilities/dicts.py | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apiserver/bll/serving/stats.py b/apiserver/bll/serving/stats.py index 8c5f992..734d7f8 100644 --- a/apiserver/bll/serving/stats.py +++ b/apiserver/bll/serving/stats.py @@ -270,15 +270,20 @@ class ServingStats: } }, } + hist_params = {} + if metric_type == MetricType.requests: + hist_params["min_doc_count"] = 1 + else: + hist_params["extended_bounds"] = { + "min": int(from_date) * 1000, + "max": int(to_date) * 1000, + } aggs = { "dates": { "date_histogram": { "field": "timestamp", "fixed_interval": f"{interval}s", - "extended_bounds": { - "min": int(from_date) * 1000, - "max": int(to_date) * 1000, - }, + **hist_params, }, "aggs": aggs, } diff --git a/apiserver/utilities/dicts.py b/apiserver/utilities/dicts.py index 3850f6e..e794dec 100644 --- a/apiserver/utilities/dicts.py +++ b/apiserver/utilities/dicts.py @@ -1,4 +1,4 @@ -from typing import Sequence, Tuple, Any, Union, Callable, Optional, Mapping +from typing import Sequence, Tuple, Any, Union, Callable, Optional, Protocol def flatten_nested_items( @@ -35,8 +35,13 @@ def deep_merge(source: dict, override: dict) -> dict: return source +class GetItem(Protocol): + def __getitem__(self, key: Any) -> Any: + pass + + def nested_get( - dictionary: Mapping, + dictionary: GetItem, path: Sequence[str], default: Optional[Union[Any, Callable]] = None, ) -> Any: