1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-26 00:39:41 +02:00

fix(gke): port metrics to the backend EE-5447 (#9041)

This commit is contained in:
Dakota Walsh 2023-07-24 12:16:29 +12:00 committed by GitHub
parent e996d29d52
commit 704d70c99b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 441 additions and 247 deletions

View file

@ -6,8 +6,11 @@ import { withError } from '@/react-tools/react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { isFulfilled } from '@/portainer/helpers/promise-utils';
import { Service } from './types';
import {
NodeMetrics,
NodeMetric,
Service,
} from '@/react/kubernetes/services/types';
export const queryKeys = {
clusterServices: (environmentId: EnvironmentId) =>
@ -105,3 +108,67 @@ export async function deleteServices({
throw parseAxiosError(e as Error, 'Unable to delete service(s)');
}
}
export async function getMetricsForAllNodes(environmentId: EnvironmentId) {
try {
const { data: nodes } = await axios.get<NodeMetrics>(
`kubernetes/${environmentId}/metrics/nodes`,
{}
);
return nodes;
} catch (e) {
throw parseAxiosError(
e as Error,
'Unable to retrieve metrics for all nodes'
);
}
}
export async function getMetricsForNode(
environmentId: EnvironmentId,
nodeName: string
) {
try {
const { data: node } = await axios.get<NodeMetric>(
`kubernetes/${environmentId}/metrics/nodes/${nodeName}`,
{}
);
return node;
} catch (e) {
throw parseAxiosError(e as Error, 'Unable to retrieve metrics for node');
}
}
export async function getMetricsForAllPods(
environmentId: EnvironmentId,
namespace: string
) {
try {
const { data: pods } = await axios.get(
`kubernetes/${environmentId}/metrics/pods/namespace/${namespace}`,
{}
);
return pods;
} catch (e) {
throw parseAxiosError(
e as Error,
'Unable to retrieve metrics for all pods'
);
}
}
export async function getMetricsForPod(
environmentId: EnvironmentId,
namespace: string,
podName: string
) {
try {
const { data: pod } = await axios.get(
`kubernetes/${environmentId}/metrics/pods/namespace/${namespace}/${podName}`,
{}
);
return pod;
} catch (e) {
throw parseAxiosError(e as Error, 'Unable to retrieve metrics for pod');
}
}