feat: added kafka - scenario - 4 (#6370)

* feat: added kafka - scenario - 4

* feat: added error handling and correct api handler for kafka apis
This commit is contained in:
SagarRajput-7 2024-11-06 14:24:38 +05:30 committed by GitHub
parent 7086470ce2
commit 468f056530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 124 additions and 119 deletions

View File

@ -13,7 +13,6 @@ import {
MessagingQueuesViewTypeOptions, MessagingQueuesViewTypeOptions,
ProducerLatencyOptions, ProducerLatencyOptions,
} from '../MessagingQueuesUtils'; } from '../MessagingQueuesUtils';
import { SelectLabelWithComingSoon } from '../MQCommon/MQCommon';
import MessagingQueueOverview from '../MQDetails/MessagingQueueOverview'; import MessagingQueueOverview from '../MQDetails/MessagingQueueOverview';
import MessagingQueuesDetails from '../MQDetails/MQDetails'; import MessagingQueuesDetails from '../MQDetails/MQDetails';
import MessagingQueuesConfigOptions from '../MQGraph/MQConfigOptions'; import MessagingQueuesConfigOptions from '../MQGraph/MQConfigOptions';
@ -70,13 +69,8 @@ function MQDetailPage(): JSX.Element {
value: MessagingQueuesViewType.producerLatency.value, value: MessagingQueuesViewType.producerLatency.value,
}, },
{ {
label: ( label: MessagingQueuesViewType.dropRate.label,
<SelectLabelWithComingSoon value: MessagingQueuesViewType.dropRate.value,
label={MessagingQueuesViewType.consumerLatency.label}
/>
),
value: MessagingQueuesViewType.consumerLatency.value,
disabled: true,
}, },
]} ]}
/> />
@ -96,10 +90,12 @@ function MQDetailPage(): JSX.Element {
)} )}
</div> </div>
<div className="messaging-queue-details"> <div className="messaging-queue-details">
{selectedView !== MessagingQueuesViewType.dropRate.value && (
<MessagingQueuesDetails <MessagingQueuesDetails
selectedView={selectedView} selectedView={selectedView}
producerLatencyOption={producerLatencyOption} producerLatencyOption={producerLatencyOption}
/> />
)}
</div> </div>
</div> </div>
); );

View File

@ -139,7 +139,7 @@ const checkValidityOfDetailConfigs = (
return Boolean(configDetails?.topic && configDetails?.service_name); return Boolean(configDetails?.topic && configDetails?.service_name);
} }
return false; return selectedView === MessagingQueuesViewType.dropRate.value;
}; };
function MessagingQueuesDetails({ function MessagingQueuesDetails({
@ -213,14 +213,14 @@ function MessagingQueuesDetails({
<MessagingQueuesTable <MessagingQueuesTable
currentTab={currentTab} currentTab={currentTab}
selectedView={selectedView} selectedView={selectedView}
tableApi={serviceConfigDetails[selectedView].tableApi} tableApi={serviceConfigDetails[selectedView]?.tableApi}
validConfigPresent={checkValidityOfDetailConfigs( validConfigPresent={checkValidityOfDetailConfigs(
timelineQueryData, timelineQueryData,
selectedView, selectedView,
currentTab, currentTab,
configDetailQueryData, configDetailQueryData,
)} )}
tableApiPayload={serviceConfigDetails[selectedView].tableApiPayload} tableApiPayload={serviceConfigDetails[selectedView]?.tableApiPayload}
/> />
</div> </div>
); );

View File

@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable react/require-default-props */ /* eslint-disable react/require-default-props */
import './MQTables.styles.scss'; import './MQTables.styles.scss';
@ -169,7 +170,9 @@ function MessagingQueuesTable({
}); });
}; };
const { mutate: getViewDetails, isLoading } = useMutation(tableApi, { const { mutate: getViewDetails, isLoading, error, isError } = useMutation(
tableApi,
{
onSuccess: (data) => { onSuccess: (data) => {
if (data.payload) { if (data.payload) {
setColumns(getColumns(data?.payload, history)); setColumns(getColumns(data?.payload, history));
@ -177,7 +180,8 @@ function MessagingQueuesTable({
} }
}, },
onError: handleConsumerDetailsOnError, onError: handleConsumerDetailsOnError,
}); },
);
useEffect( useEffect(
() => { () => {
@ -230,6 +234,10 @@ function MessagingQueuesTable({
</Typography.Text> </Typography.Text>
<Skeleton /> <Skeleton />
</div> </div>
) : isError ? (
<div className="no-data-style">
<Typography.Text>{error?.message || SOMETHING_WENT_WRONG}</Typography.Text>
</div>
) : ( ) : (
<> <>
{currentTab && ( {currentTab && (

View File

@ -1,20 +1,18 @@
import axios from 'api'; import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { MessagingQueueServiceDetailType } from 'pages/MessagingQueues/MessagingQueuesUtils'; import { MessagingQueueServiceDetailType } from 'pages/MessagingQueues/MessagingQueuesUtils';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
export interface MessagingQueueServicePayload { export interface MessagingQueueServicePayload {
start?: number | string; start?: number | string;
end?: number | string; end?: number | string;
variables: { variables?: {
partition?: string; partition?: string;
topic?: string; topic?: string;
consumer_group?: string; consumer_group?: string;
service_name?: string; service_name?: string;
}; };
detailType?: MessagingQueueServiceDetailType | 'producer' | 'consumer'; detailType?: MessagingQueueServiceDetailType | 'producer' | 'consumer';
evalTime?: number;
} }
export interface MessagingQueuesPayloadProps { export interface MessagingQueuesPayloadProps {
@ -42,7 +40,6 @@ export const getConsumerLagDetails = async (
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
> => { > => {
const { detailType, ...restProps } = props; const { detailType, ...restProps } = props;
try {
const response = await axios.post( const response = await axios.post(
`/messaging-queues/kafka/consumer-lag/${props.detailType}`, `/messaging-queues/kafka/consumer-lag/${props.detailType}`,
{ {
@ -56,7 +53,4 @@ export const getConsumerLagDetails = async (
message: response.data.status, message: response.data.status,
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) {
return ErrorResponseHandler((error as AxiosError) || SOMETHING_WENT_WRONG);
}
}; };

View File

@ -0,0 +1,27 @@
import axios from 'api';
import { ErrorResponse, SuccessResponse } from 'types/api';
import {
MessagingQueueServicePayload,
MessagingQueuesPayloadProps,
} from './getConsumerLagDetails';
export const getKafkaSpanEval = async (
props: Omit<MessagingQueueServicePayload, 'detailType' | 'variables'>,
): Promise<
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
> => {
const { start, end, evalTime } = props;
const response = await axios.post(`messaging-queues/kafka/span/evaluation`, {
start,
end,
eval_time: evalTime,
});
return {
statusCode: 200,
error: null,
message: response.data.status,
payload: response.data.data,
};
};

View File

@ -1,7 +1,4 @@
import axios from 'api'; import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { MessagingQueueServiceDetailType } from 'pages/MessagingQueues/MessagingQueuesUtils'; import { MessagingQueueServiceDetailType } from 'pages/MessagingQueues/MessagingQueuesUtils';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
@ -22,7 +19,7 @@ export const getPartitionLatencyDetails = async (
} else { } else {
endpoint = `/messaging-queues/kafka/consumer-lag/producer-details`; endpoint = `/messaging-queues/kafka/consumer-lag/producer-details`;
} }
try {
const response = await axios.post(endpoint, { const response = await axios.post(endpoint, {
...rest, ...rest,
}); });
@ -33,7 +30,4 @@ export const getPartitionLatencyDetails = async (
message: response.data.status, message: response.data.status,
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) {
return ErrorResponseHandler((error as AxiosError) || SOMETHING_WENT_WRONG);
}
}; };

View File

@ -1,7 +1,4 @@
import axios from 'api'; import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
import { import {
@ -14,7 +11,6 @@ export const getPartitionLatencyOverview = async (
): Promise< ): Promise<
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
> => { > => {
try {
const response = await axios.post( const response = await axios.post(
`/messaging-queues/kafka/partition-latency/overview`, `/messaging-queues/kafka/partition-latency/overview`,
{ {
@ -28,7 +24,4 @@ export const getPartitionLatencyOverview = async (
message: response.data.status, message: response.data.status,
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) {
return ErrorResponseHandler((error as AxiosError) || SOMETHING_WENT_WRONG);
}
}; };

View File

@ -1,7 +1,4 @@
import axios from 'api'; import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
import { import {
@ -16,7 +13,6 @@ export const getTopicThroughputDetails = async (
> => { > => {
const { detailType, ...rest } = props; const { detailType, ...rest } = props;
const endpoint = `/messaging-queues/kafka/topic-throughput/${detailType}`; const endpoint = `/messaging-queues/kafka/topic-throughput/${detailType}`;
try {
const response = await axios.post(endpoint, { const response = await axios.post(endpoint, {
...rest, ...rest,
}); });
@ -27,7 +23,4 @@ export const getTopicThroughputDetails = async (
message: response.data.status, message: response.data.status,
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) {
return ErrorResponseHandler((error as AxiosError) || SOMETHING_WENT_WRONG);
}
}; };

View File

@ -1,7 +1,4 @@
import axios from 'api'; import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { ErrorResponse, SuccessResponse } from 'types/api'; import { ErrorResponse, SuccessResponse } from 'types/api';
import { import {
@ -15,8 +12,6 @@ export const getTopicThroughputOverview = async (
SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse SuccessResponse<MessagingQueuesPayloadProps['payload']> | ErrorResponse
> => { > => {
const { detailType, start, end } = props; const { detailType, start, end } = props;
console.log(detailType);
try {
const response = await axios.post( const response = await axios.post(
`messaging-queues/kafka/topic-throughput/${detailType}`, `messaging-queues/kafka/topic-throughput/${detailType}`,
{ {
@ -31,7 +26,4 @@ export const getTopicThroughputOverview = async (
message: response.data.status, message: response.data.status,
payload: response.data.data, payload: response.data.data,
}; };
} catch (error) {
return ErrorResponseHandler((error as AxiosError) || SOMETHING_WENT_WRONG);
}
}; };

View File

@ -12,6 +12,7 @@ import {
ProducerLatencyOptions, ProducerLatencyOptions,
} from '../MessagingQueuesUtils'; } from '../MessagingQueuesUtils';
import { MessagingQueueServicePayload } from './MQTables/getConsumerLagDetails'; import { MessagingQueueServicePayload } from './MQTables/getConsumerLagDetails';
import { getKafkaSpanEval } from './MQTables/getKafkaSpanEval';
import { getPartitionLatencyOverview } from './MQTables/getPartitionLatencyOverview'; import { getPartitionLatencyOverview } from './MQTables/getPartitionLatencyOverview';
import { getTopicThroughputOverview } from './MQTables/getTopicThroughputOverview'; import { getTopicThroughputOverview } from './MQTables/getTopicThroughputOverview';
import MessagingQueuesTable from './MQTables/MQTables'; import MessagingQueuesTable from './MQTables/MQTables';
@ -51,6 +52,9 @@ const getTableApi = (selectedView: MessagingQueuesViewTypeOptions): any => {
if (selectedView === MessagingQueuesViewType.producerLatency.value) { if (selectedView === MessagingQueuesViewType.producerLatency.value) {
return getTopicThroughputOverview; return getTopicThroughputOverview;
} }
if (selectedView === MessagingQueuesViewType.dropRate.value) {
return getKafkaSpanEval;
}
return getPartitionLatencyOverview; return getPartitionLatencyOverview;
}; };
@ -78,6 +82,10 @@ function MessagingQueueOverview({
? 'producer' ? 'producer'
: 'consumer' : 'consumer'
: undefined, : undefined,
evalTime:
selectedView === MessagingQueuesViewType.dropRate.value
? 2363404
: undefined,
}; };
return ( return (

View File

@ -187,7 +187,7 @@ function MessagingQueues(): JSX.Element {
</div> </div>
<div className="summary-card coming-soon-card"> <div className="summary-card coming-soon-card">
<div className="summary-title"> <div className="summary-title">
<p>{MessagingQueuesViewType.consumerLatency.label}</p> <p>{MessagingQueuesViewType.dropRate.label}</p>
<div className="time-value"> <div className="time-value">
<Calendar size={14} color={Color.BG_SLATE_200} /> <Calendar size={14} color={Color.BG_SLATE_200} />
<p className="time-value">1D</p> <p className="time-value">1D</p>

View File

@ -238,9 +238,9 @@ export const MessagingQueuesViewType = {
label: 'Producer Latency view', label: 'Producer Latency view',
value: MessagingQueuesViewTypeOptions.ProducerLatency, value: MessagingQueuesViewTypeOptions.ProducerLatency,
}, },
consumerLatency: { dropRate: {
label: 'Consumer latency view', label: 'Drop Rate',
value: MessagingQueuesViewTypeOptions.ConsumerLatency, value: 'dropRate',
}, },
}; };