Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datasource metadata queries #1322

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is containers removed?

Copy link
Contributor Author

@shreyabiradar07 shreyabiradar07 Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below assertion error is encountered in edge cases where there are no containers for a job workload type as "containers" is a required field:

assert [<ValidationError: "'containers' is a required property">, <ValidationError: "'containers' is a required property">, <ValidationError: ''>] == ''

Following are the few examples for edge cases observed after updating the datasource metadata queries to gather metric data for last 15 days:

"collect-profiles-28807155": {
                  "workload_name": "collect-profiles-28807155",
                  "workload_type": "job"
                },
"image-pruner-28802880": {
                  "workload_name": "image-pruner-28802880",
                  "workload_type": "job"
                }

Failed test logs : https://privatebin.corp.redhat.com/?cd5f4646e2d1f0e3#41XkaVvktuBJXmQDm4F11WTvfPXq4Rh7DRN164LyGUhQ

}
}
}
Expand Down
Loading