Skip to content

Commit

Permalink
Merge pull request #1322 from shreyabiradar07/update-dsmetadata-queries
Browse files Browse the repository at this point in the history
Update datasource metadata queries
  • Loading branch information
dinogun authored Oct 16, 2024
2 parents 4868a14 + e3eb030 commit 6f88eea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/autotune/database/helper/DBHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ public static List<DataSourceMetadataInfo> 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());
Expand Down Expand Up @@ -1028,6 +1033,23 @@ public static List<KruizeDSMetadataEntry> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
}
},
"required": ["workload_name", "workload_type", "containers"]
"required": ["workload_name", "workload_type"]
}
}
}
Expand Down

0 comments on commit 6f88eea

Please sign in to comment.