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

Bug 1810002: Fix Prometheus query on VMI utilization graphs #4623

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,38 +10,33 @@ export enum VMQueries {
}

const queries = {
// We don't set namespace explicitly in the PromQL template because it is
// being injected anyway by prom-label-proxy when we query Thanos.
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw you could potentially still leave it here for clarity, although being a no-op.

Copy link
Author

Choose a reason for hiding this comment

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

I don't mind adding it, but I think that it causes confusion where you specify the namespace in the query and it doesn't really being used... especially in cases where there will be a conflict between what is rendered here and what is present in the query param...

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good 👍

[VMQueries.CPU_USAGE]: _.template(
// TODO verify; use seconds or milicores?
// `kubevirt_vmi_vcpu_seconds{exported_namespace='<%= namespace %>',name='<%= vmName %>'}`,
`pod:container_cpu_usage:sum{namespace='<%= namespace %>',pod='<%= launcherPodName %>'}`,
),
[VMQueries.MEMORY_USAGE]: _.template(
`kubevirt_vmi_memory_resident_bytes{exported_namespace='<%= namespace %>',name='<%= vmName %>'}`,
`pod:container_cpu_usage:sum{pod='<%= launcherPodName %>'}`,
),
[VMQueries.MEMORY_USAGE]: _.template(`kubevirt_vmi_memory_resident_bytes{name='<%= vmName %>'}`),
[VMQueries.FILESYSTEM_USAGE]: _.template(
`sum(kubevirt_vmi_storage_traffic_bytes_total{exported_namespace='<%= namespace %>',name='<%= vmName %>'})`,
`sum(kubevirt_vmi_storage_traffic_bytes_total{name='<%= vmName %>'})`,
),
[VMQueries.NETWORK_IN_USAGE]: _.template(
`sum(kubevirt_vmi_network_traffic_bytes_total{type='rx',exported_namespace='<%= namespace %>',name='<%= vmName %>'})`,
`sum(kubevirt_vmi_network_traffic_bytes_total{type='rx',name='<%= vmName %>'})`,
),
[VMQueries.NETWORK_OUT_USAGE]: _.template(
`sum(kubevirt_vmi_network_traffic_bytes_total{type='tx',exported_namespace='<%= namespace %>',name='<%= vmName %>'})`,
`sum(kubevirt_vmi_network_traffic_bytes_total{type='tx', name='<%= vmName %>'})`,
),
};

export const getUtilizationQueries = (props: {
vmName: string;
namespace: string;
launcherPodName?: string;
}) => ({
export const getUtilizationQueries = (props: { vmName: string; launcherPodName?: string }) => ({
[VMQueries.CPU_USAGE]: queries[VMQueries.CPU_USAGE](props),
[VMQueries.MEMORY_USAGE]: queries[VMQueries.MEMORY_USAGE](props),
[VMQueries.FILESYSTEM_USAGE]: queries[VMQueries.FILESYSTEM_USAGE](props),
});

export const getMultilineUtilizationQueries = (props: {
vmName: string;
namespace: string;
launcherPodName?: string;
}) => ({
[VMQueries.NETWORK_USAGE]: [
Expand Down
Expand Up @@ -58,20 +58,18 @@ export const VMUtilizationCard: React.FC = () => {
() =>
getUtilizationQueries({
vmName,
namespace,
launcherPodName,
}),
[vmName, namespace, launcherPodName],
[vmName, launcherPodName],
);

const multilineQueries = React.useMemo(
() =>
getMultilineUtilizationQueries({
vmName,
namespace,
launcherPodName,
}),
[vmName, namespace, launcherPodName],
[vmName, launcherPodName],
);

const createdAt = getCreationTimestamp(vmi);
Expand Down