|
| 1 | +import axios from 'api'; |
| 2 | +import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; |
| 3 | +import { AxiosError } from 'axios'; |
| 4 | +import { ErrorResponse, SuccessResponse } from 'types/api'; |
| 5 | +import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse'; |
| 6 | +import { TagFilter } from 'types/api/queryBuilder/queryBuilderData'; |
| 7 | + |
| 8 | +export interface K8sVolumesListPayload { |
| 9 | + filters: TagFilter; |
| 10 | + groupBy?: BaseAutocompleteData[]; |
| 11 | + offset?: number; |
| 12 | + limit?: number; |
| 13 | + orderBy?: { |
| 14 | + columnName: string; |
| 15 | + order: 'asc' | 'desc'; |
| 16 | + }; |
| 17 | +} |
| 18 | + |
| 19 | +export interface K8sVolumesData { |
| 20 | + persistentVolumeClaimName: string; |
| 21 | + volumeAvailable: number; |
| 22 | + volumeCapacity: number; |
| 23 | + volumeInodes: number; |
| 24 | + volumeInodesFree: number; |
| 25 | + volumeInodesUsed: number; |
| 26 | + volumeUsage: number; |
| 27 | + meta: { |
| 28 | + k8s_cluster_name: string; |
| 29 | + k8s_namespace_name: string; |
| 30 | + k8s_node_name: string; |
| 31 | + k8s_persistentvolumeclaim_name: string; |
| 32 | + k8s_pod_name: string; |
| 33 | + k8s_pod_uid: string; |
| 34 | + k8s_statefulset_name: string; |
| 35 | + }; |
| 36 | +} |
| 37 | + |
| 38 | +export interface K8sVolumesListResponse { |
| 39 | + status: string; |
| 40 | + data: { |
| 41 | + type: string; |
| 42 | + records: K8sVolumesData[]; |
| 43 | + groups: null; |
| 44 | + total: number; |
| 45 | + sentAnyHostMetricsData: boolean; |
| 46 | + isSendingK8SAgentMetrics: boolean; |
| 47 | + }; |
| 48 | +} |
| 49 | + |
| 50 | +export const getK8sVolumesList = async ( |
| 51 | + props: K8sVolumesListPayload, |
| 52 | + signal?: AbortSignal, |
| 53 | + headers?: Record<string, string>, |
| 54 | +): Promise<SuccessResponse<K8sVolumesListResponse> | ErrorResponse> => { |
| 55 | + try { |
| 56 | + const response = await axios.post('/pvcs/list', props, { |
| 57 | + signal, |
| 58 | + headers, |
| 59 | + }); |
| 60 | + |
| 61 | + return { |
| 62 | + statusCode: 200, |
| 63 | + error: null, |
| 64 | + message: 'Success', |
| 65 | + payload: response.data, |
| 66 | + params: props, |
| 67 | + }; |
| 68 | + } catch (error) { |
| 69 | + return ErrorResponseHandler(error as AxiosError); |
| 70 | + } |
| 71 | +}; |
0 commit comments