From ec4fd7e4eb7661981a38e867199592eca27eae6d Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 4 Oct 2024 11:44:19 +0530 Subject: [PATCH 1/3] Update dsmetadata queries --- .../common/data/dataSourceQueries/DataSourceQueries.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/autotune/common/data/dataSourceQueries/DataSourceQueries.java b/src/main/java/com/autotune/common/data/dataSourceQueries/DataSourceQueries.java index d485dd2a5..2620b8260 100644 --- a/src/main/java/com/autotune/common/data/dataSourceQueries/DataSourceQueries.java +++ b/src/main/java/com/autotune/common/data/dataSourceQueries/DataSourceQueries.java @@ -7,9 +7,9 @@ */ public class DataSourceQueries { public enum PromQLQuery { - NAMESPACE_QUERY("sum by (namespace) (kube_namespace_status_phase{phase=\"Active\" ADDITIONAL_LABEL })"), - WORKLOAD_INFO_QUERY("sum by (namespace, workload, workload_type) (namespace_workload_pod:kube_pod_owner:relabel{ ADDITIONAL_LABEL })"), - CONTAINER_INFO_QUERY("sum by (container, image, workload) (kube_pod_container_info{ ADDITIONAL_LABEL } * on(pod) group_left(workload, workload_type) (namespace_workload_pod:kube_pod_owner:relabel{ ADDITIONAL_LABEL }))"); + NAMESPACE_QUERY("sum by (namespace) ( avg_over_time(kube_namespace_status_phase{namespace!=\"\" ADDITIONAL_LABEL}[15d]))"), + WORKLOAD_INFO_QUERY("sum by (namespace, workload, workload_type) ( avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=\"\" ADDITIONAL_LABEL}[15d]))"), + CONTAINER_INFO_QUERY("sum by (container, image, workload, workload_type, namespace) ( avg_over_time(kube_pod_container_info{container!=\"\" ADDITIONAL_LABEL}[15d]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=\"\" ADDITIONAL_LABEL}[15d]))"); private final String query; PromQLQuery(String query) { From f31d0d3914956afbeeb6f7c117738d272782ad86 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 4 Oct 2024 13:31:24 +0530 Subject: [PATCH 2/3] Include workloads with no containers edge case in dsmetadata DB object --- .../autotune/database/helper/DBHelpers.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/autotune/database/helper/DBHelpers.java b/src/main/java/com/autotune/database/helper/DBHelpers.java index 512cf7e3e..8b3d018fd 100644 --- a/src/main/java/com/autotune/database/helper/DBHelpers.java +++ b/src/main/java/com/autotune/database/helper/DBHelpers.java @@ -895,6 +895,11 @@ public static List convertKruizeMetadataToDataSourceMeta continue; } dataSourceNamespace.getDataSourceWorkloadHashMap().put(kruizeMetadata.getWorkloadName(), dataSourceWorkload); + + if (null == dataSourceContainer) { + dataSourceWorkload.setDataSourceContainerHashMap(null); + continue; + } dataSourceWorkload.getDataSourceContainerHashMap().put(kruizeMetadata.getContainerName(), dataSourceContainer); } catch (Exception e) { LOGGER.error("Error occurred while converting to dataSourceMetadataInfo from DB object : {}", e.getMessage()); @@ -1028,6 +1033,23 @@ public static List convertDataSourceMetadataToMetadataObj } for (DataSourceWorkload dataSourceWorkload : dataSourceNamespace.getDataSourceWorkloadHashMap().values()) { + // handles 'job' workload type with no containers + if(null == dataSourceWorkload.getDataSourceContainerHashMap()) { + KruizeDSMetadataEntry kruizeMetadata = new KruizeDSMetadataEntry(); + kruizeMetadata.setVersion(KruizeConstants.DataSourceConstants.DataSourceMetadataInfoConstants.version); + + kruizeMetadata.setDataSourceName(dataSourceName); + kruizeMetadata.setClusterName(dataSourceClusterName); + kruizeMetadata.setNamespace(namespaceName); + kruizeMetadata.setWorkloadType(dataSourceWorkload.getDataSourceWorkloadType()); + kruizeMetadata.setWorkloadName(dataSourceWorkload.getDataSourceWorkloadName()); + + kruizeMetadata.setContainerName(null); + kruizeMetadata.setContainerImageName(null); + + kruizeMetadataList.add(kruizeMetadata); + continue; + } for (DataSourceContainer dataSourceContainer : dataSourceWorkload.getDataSourceContainerHashMap().values()) { KruizeDSMetadataEntry kruizeMetadata = new KruizeDSMetadataEntry(); From e3eb030e041ee8cc95eb51080ffa8ff8e0b8b8a7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 16 Oct 2024 10:18:41 +0530 Subject: [PATCH 3/3] Remove containers required field from list metadata JSON schema --- tests/scripts/helpers/list_metadata_json_verbose_true_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py b/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py index 5f0588816..2be52ee04 100644 --- a/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py +++ b/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py @@ -64,7 +64,7 @@ } } }, - "required": ["workload_name", "workload_type", "containers"] + "required": ["workload_name", "workload_type"] } } }