From 77c8c6136829879652193d50a371791acf0adc81 Mon Sep 17 00:00:00 2001 From: tlipoca9 <160737620+tlipoca9@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:48:42 +0800 Subject: [PATCH] fix: avoid exceed search.maxQueryLen (#312) --- .../prometheus_metrics_service.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 1901c7b..44bbadb 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -313,20 +313,22 @@ async def load_pods(self, object: K8sObjectData, period: timedelta) -> list[PodD pod_owners = [object.name] pod_owner_kind = object.kind - owners_regex = "|".join(pod_owners) - related_pods_result = await self.query( - f""" - last_over_time( - kube_pod_owner{{ - owner_name=~"{owners_regex}", - owner_kind="{pod_owner_kind}", - namespace="{object.namespace}" - {cluster_label} - }}[{period_literal}] - ) - """ - ) - + related_pods_result = [] + for owner_group in batched(pod_owners, 10): + owners_regex = "|".join(owner_group) + related_pods_result_item = await self.query( + f""" + last_over_time( + kube_pod_owner{{ + owner_name=~"{owners_regex}", + owner_kind="{pod_owner_kind}", + namespace="{object.namespace}" + {cluster_label} + }}[{period_literal}] + ) + """ + ) + related_pods_result.extend(related_pods_result_item) if related_pods_result == []: return []