def _get_scalar_average_per_task( self, metrics_interval: MetricInterval, task_ids: Sequence[str], es_index: str, key: ScalarKey, ) -> Sequence[MetricData]: """ Retrieve scalar histograms per several metric variants that share the same interval """ interval, task_metrics = metrics_interval aggregation = self._add_aggregation_average( key.get_aggregation(interval)) aggs = { "metrics": { "terms": { "field": "metric", "size": self.MAX_METRICS_COUNT }, "aggs": { "variants": { "terms": { "field": "variant", "size": self.MAX_VARIANTS_COUNT }, "aggs": { "tasks": { "terms": { "field": "task", "size": self.MAX_TASKS_COUNT, }, "aggs": aggregation, } }, } }, } } aggs_result = self._query_aggregation_for_metrics_and_tasks( es_index, aggs=aggs, task_ids=task_ids, task_metrics=task_metrics) if not aggs_result: return {} metrics = [( metric["key"], { variant["key"]: { task["key"]: key.get_iterations_data(task) for task in variant["tasks"]["buckets"] } for variant in metric["variants"]["buckets"] }, ) for metric in aggs_result["metrics"]["buckets"]] return metrics
def _get_scalar_average( self, metrics_interval: MetricInterval, task_ids: Sequence[str], es_index: str, key: ScalarKey, ) -> Sequence[MetricData]: """ Retrieve scalar histograms per several metric variants that share the same interval Note: the function works with a single task only """ assert len(task_ids) == 1 interval, task_metrics = metrics_interval aggregation = self._add_aggregation_average( key.get_aggregation(interval)) aggs = { "metrics": { "terms": { "field": "metric", "size": self.MAX_METRICS_COUNT, "order": { "_term": "desc" }, }, "aggs": { "variants": { "terms": { "field": "variant", "size": self.MAX_VARIANTS_COUNT, "order": { "_term": "desc" }, }, "aggs": aggregation, } }, } } aggs_result = self._query_aggregation_for_metrics_and_tasks( es_index, aggs=aggs, task_ids=task_ids, task_metrics=task_metrics) if not aggs_result: return {} metrics = [( metric["key"], { variant["key"]: { "name": variant["key"], **key.get_iterations_data(variant), } for variant in metric["variants"]["buckets"] }, ) for metric in aggs_result["metrics"]["buckets"]] return metrics