-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: added the host list view and filters #6210
base: infra-monitoring
Are you sure you want to change the base?
Changes from 2 commits
f8eeec6
ae014d1
08512b9
3d57dde
689440b
403fe9d
6648e84
4581cba
1af121d
a30bb58
5aa2f03
fc43930
8ace84c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { ApiBaseInstance } from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse'; | ||
import { TagFilter } from 'types/api/queryBuilder/queryBuilderData'; | ||
|
||
export interface HostListPayload { | ||
start: number; | ||
end: number; | ||
filters: TagFilter; | ||
groupBy: BaseAutocompleteData[]; | ||
offset?: number; | ||
limit?: number; | ||
} | ||
|
||
interface TimeSeriesValue { | ||
timestamp: number; | ||
value: string; | ||
} | ||
|
||
interface TimeSeries { | ||
labels: Record<string, string>; | ||
labelsArray: Array<Record<string, string>>; | ||
values: TimeSeriesValue[]; | ||
} | ||
|
||
interface HostData { | ||
hostName: string; | ||
active: boolean; | ||
os: string; | ||
cpu: number; | ||
cpuTimeSeries: TimeSeries; | ||
memory: number; | ||
memoryTimeSeries: TimeSeries; | ||
wait: number; | ||
waitTimeSeries: TimeSeries; | ||
load15: number; | ||
load15TimeSeries: TimeSeries; | ||
} | ||
|
||
export interface HostListResponse { | ||
status: string; | ||
data: { | ||
type: string; | ||
records: HostData[]; | ||
groups: null; | ||
total: number; | ||
}; | ||
} | ||
|
||
export const getHostLists = async ( | ||
props: HostListPayload, | ||
signal?: AbortSignal, | ||
headers?: Record<string, string>, | ||
): Promise<SuccessResponse<HostListResponse> | ErrorResponse> => { | ||
try { | ||
const response = await ApiBaseInstance.post('/hosts/list', props, { | ||
signal, | ||
headers, | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: 'Success', | ||
payload: response.data, | ||
params: props, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ApiBaseInstance } from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import createQueryParams from 'lib/createQueryParams'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { | ||
IAttributeValuesResponse, | ||
IGetAttributeValuesPayload, | ||
} from 'types/api/queryBuilder/getAttributesValues'; | ||
|
||
export const getInfraAttributesValues = async ({ | ||
dataSource, | ||
attributeKey, | ||
filterAttributeKeyDataType, | ||
tagType, | ||
searchText, | ||
}: IGetAttributeValuesPayload): Promise< | ||
SuccessResponse<IAttributeValuesResponse> | ErrorResponse | ||
> => { | ||
try { | ||
const response = await ApiBaseInstance.get( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above. |
||
`/hosts/attribute_values?${createQueryParams({ | ||
dataSource, | ||
attributeKey, | ||
searchText, | ||
})}&filterAttributeKeyDataType=${filterAttributeKeyDataType}&tagType=${tagType}`, | ||
); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { ApiV3Instance } from 'api'; | ||
import { ApiBaseInstance, ApiV3Instance } from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { baseAutoCompleteIdKeysOrder } from 'constants/queryBuilder'; | ||
|
@@ -18,20 +18,25 @@ export const getAggregateKeys = async ({ | |
dataSource, | ||
aggregateAttribute, | ||
tagType, | ||
isInfraMonitoring, | ||
}: IGetAttributeKeysPayload): Promise< | ||
SuccessResponse<IQueryAutocompleteResponse> | ErrorResponse | ||
> => { | ||
try { | ||
const endpoint = isInfraMonitoring | ||
? `/hosts/attribute_keys?dataSource=metrics&searchText=${searchText || ''}` | ||
: `/autocomplete/attribute_keys?${createQueryParams({ | ||
aggregateOperator, | ||
searchText, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is a complete endpoint change including the |
||
dataSource, | ||
aggregateAttribute, | ||
})}&tagType=${tagType}`; | ||
|
||
const apiInstance = isInfraMonitoring ? ApiBaseInstance : ApiV3Instance; | ||
|
||
const response: AxiosResponse<{ | ||
data: IQueryAutocompleteResponse; | ||
}> = await ApiV3Instance.get( | ||
`/autocomplete/attribute_keys?${createQueryParams({ | ||
aggregateOperator, | ||
searchText, | ||
dataSource, | ||
aggregateAttribute, | ||
})}&tagType=${tagType}`, | ||
); | ||
}> = await apiInstance.get(endpoint); | ||
|
||
const payload: BaseAutocompleteData[] = | ||
response.data.data.attributeKeys?.map(({ id: _, ...item }) => ({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.loading-host-metrics { | ||
padding: 24px 0; | ||
height: 600px; | ||
|
||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
.loading-host-metrics-content { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
|
||
.loading-gif { | ||
height: 72px; | ||
margin-left: -24px; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import './HostMetricsLoading.styles.scss'; | ||
|
||
import { Typography } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { DataSource } from 'types/common/queryBuilder'; | ||
|
||
export function HostMetricsLoading(): JSX.Element { | ||
const { t } = useTranslation('common'); | ||
return ( | ||
<div className="loading-host-metrics"> | ||
<div className="loading-host-metrics-content"> | ||
<img | ||
className="loading-gif" | ||
src="/Icons/loading-plane.gif" | ||
alt="wait-icon" | ||
/> | ||
|
||
<Typography> | ||
{t('pending_data_placeholder', { | ||
dataSource: `host ${DataSource.METRICS}`, | ||
})} | ||
</Typography> | ||
</div> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try catch block doesn't propagate the errors to the consuming component and we have to extract the success / error data from the successResponse.