Skip to content

Commit

Permalink
chore: added logeEvents in Kafka-ui (#5810)
Browse files Browse the repository at this point in the history
* chore: added logeEvents in Kafka-ui

* chore: changed event logic for graph data fetch
  • Loading branch information
SagarRajput-7 authored Aug 30, 2024
1 parent 363fb7b commit 5dc5b2e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 11 deletions.
4 changes: 4 additions & 0 deletions frontend/src/container/GridCardLayout/GridCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function GridCardGraph({
onClickHandler,
onDragSelect,
customTooltipElement,
dataAvailable,
}: GridCardGraphProps): JSX.Element {
const dispatch = useDispatch();
const [errorMessage, setErrorMessage] = useState<string>();
Expand Down Expand Up @@ -180,6 +181,9 @@ function GridCardGraph({
onError: (error) => {
setErrorMessage(error.message);
},
onSettled: (data) => {
dataAvailable?.(Boolean(data?.payload?.data?.result?.length));
},
},
);

Expand Down
1 change: 1 addition & 0 deletions frontend/src/container/GridCardLayout/GridCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface GridCardGraphProps {
version?: string;
onDragSelect: (start: number, end: number) => void;
customTooltipElement?: HTMLDivElement;
dataAvailable?: (isDataAvailable: boolean) => void;
}

export interface GetGraphVisibilityStateOnLegendClickProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import '../MessagingQueues.styles.scss';

import { Select, Typography } from 'antd';
import logEvent from 'api/common/logEvent';
import ROUTES from 'constants/routes';
import DateTimeSelectionV2 from 'container/TopNav/DateTimeSelectionV2';
import { ListMinus } from 'lucide-react';
import { useEffect } from 'react';
import { useHistory } from 'react-router-dom';

import { MessagingQueuesViewType } from '../MessagingQueuesUtils';
Expand All @@ -15,6 +17,10 @@ import MessagingQueuesGraph from '../MQGraph/MQGraph';
function MQDetailPage(): JSX.Element {
const history = useHistory();

useEffect(() => {
logEvent('Messaging Queues: Detail page visited', {});
}, []);

return (
<div className="messaging-queue-container">
<div className="messaging-breadcrumb">
Expand Down
30 changes: 24 additions & 6 deletions frontend/src/pages/MessagingQueues/MQDetails/MQTables/MQTables.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './MQTables.styles.scss';

import { Skeleton, Table, Typography } from 'antd';
import logEvent from 'api/common/logEvent';
import axios from 'axios';
import { isNumber } from 'chart.js/helpers';
import { ColumnTypeRender } from 'components/Logs/TableView/types';
Expand All @@ -17,7 +18,7 @@ import {
RowData,
SelectedTimelineQuery,
} from 'pages/MessagingQueues/MessagingQueuesUtils';
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useMutation } from 'react-query';
import { useHistory } from 'react-router-dom';

Expand Down Expand Up @@ -169,11 +170,28 @@ function MessagingQueuesTable({
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => getConsumerDetails(props), [currentTab, props]);

const isEmptyDetails = (timelineQueryData: SelectedTimelineQuery): boolean =>
isEmpty(timelineQueryData) ||
(!timelineQueryData?.group &&
!timelineQueryData?.topic &&
!timelineQueryData?.partition);
const isLogEventCalled = useRef<boolean>(false);

const isEmptyDetails = (timelineQueryData: SelectedTimelineQuery): boolean => {
const isEmptyDetail =
isEmpty(timelineQueryData) ||
(!timelineQueryData?.group &&
!timelineQueryData?.topic &&
!timelineQueryData?.partition);

if (!isEmptyDetail && !isLogEventCalled.current) {
logEvent('Messaging Queues: More details viewed', {
'tab-option': ConsumerLagDetailTitle[currentTab],
variables: {
group: timelineQueryData?.group,
topic: timelineQueryData?.topic,
partition: timelineQueryData?.partition,
},
});
isLogEventCalled.current = true;
}
return isEmptyDetail;
};

return (
<div className="mq-tables-container">
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/pages/MessagingQueues/MQGraph/MQGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logEvent from 'api/common/logEvent';
import { QueryParams } from 'constants/query';
import { PANEL_TYPES } from 'constants/queryBuilder';
import { ViewMenuAction } from 'container/GridCardLayout/config';
Expand All @@ -6,7 +7,7 @@ import { Card } from 'container/GridCardLayout/styles';
import { getWidgetQueryBuilder } from 'container/MetricsApplication/MetricsApplication.factory';
import { useIsDarkMode } from 'hooks/useDarkMode';
import useUrlQuery from 'hooks/useUrlQuery';
import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useRef } from 'react';
import { useDispatch } from 'react-redux';
import { useHistory, useLocation } from 'react-router-dom';
import { UpdateTimeInterval } from 'store/actions';
Expand Down Expand Up @@ -34,8 +35,10 @@ function MessagingQueuesGraph(): JSX.Element {
() => getWidgetQueryBuilder(getWidgetQuery({ filterItems })),
[filterItems],
);

const history = useHistory();
const location = useLocation();
const isLogEventCalled = useRef<boolean>(false);

const messagingQueueCustomTooltipText = (): HTMLDivElement => {
const customText = document.createElement('div');
Expand Down Expand Up @@ -66,6 +69,14 @@ function MessagingQueuesGraph(): JSX.Element {
[dispatch, history, pathname, urlQuery],
);

const checkIfDataExists = (isDataAvailable: boolean): void => {
if (!isLogEventCalled.current) {
isLogEventCalled.current = true;
logEvent('Messaging Queues: Graph data fetched', {
isDataAvailable,
});
}
};
return (
<Card
isDarkMode={isDarkMode}
Expand All @@ -80,6 +91,7 @@ function MessagingQueuesGraph(): JSX.Element {
}}
onDragSelect={onDragSelect}
customTooltipElement={messagingQueueCustomTooltipText()}
dataAvailable={checkIfDataExists}
/>
</Card>
);
Expand Down
35 changes: 31 additions & 4 deletions frontend/src/pages/MessagingQueues/MessagingQueues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import './MessagingQueues.styles.scss';
import { ExclamationCircleFilled } from '@ant-design/icons';
import { Color } from '@signozhq/design-tokens';
import { Button, Modal } from 'antd';
import logEvent from 'api/common/logEvent';
import ROUTES from 'constants/routes';
import DateTimeSelectionV2 from 'container/TopNav/DateTimeSelectionV2';
import { Calendar, ListMinus } from 'lucide-react';
import { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { isCloudUser } from 'utils/app';

Expand All @@ -21,12 +23,20 @@ function MessagingQueues(): JSX.Element {
const { confirm } = Modal;

const showConfirm = (): void => {
logEvent('Messaging Queues: View details clicked', {
page: 'Messaging Queues Overview',
source: 'Consumer Latency view',
});

confirm({
icon: <ExclamationCircleFilled />,
content:
'Before navigating to the details page, please make sure you have configured all the required setup to ensure correct data monitoring.',
className: 'overview-confirm-modal',
onOk() {
logEvent('Messaging Queues: Proceed button clicked', {
page: 'Messaging Queues Overview',
});
history.push(ROUTES.MESSAGING_QUEUES_DETAIL);
},
okText: 'Proceed',
Expand All @@ -35,14 +45,22 @@ function MessagingQueues(): JSX.Element {

const isCloudUserVal = isCloudUser();

const getStartedRedirect = (link: string): void => {
const getStartedRedirect = (link: string, sourceCard: string): void => {
logEvent('Messaging Queues: Get started clicked', {
source: sourceCard,
link: isCloudUserVal ? link : KAFKA_SETUP_DOC_LINK,
});
if (isCloudUserVal) {
history.push(link);
} else {
window.open(KAFKA_SETUP_DOC_LINK, '_blank');
}
};

useEffect(() => {
logEvent('Messaging Queues: Overview page visited', {});
}, []);

return (
<div className="messaging-queue-container">
<div className="messaging-breadcrumb">
Expand Down Expand Up @@ -70,7 +88,10 @@ function MessagingQueues(): JSX.Element {
<Button
type="default"
onClick={(): void =>
getStartedRedirect(ROUTES.GET_STARTED_APPLICATION_MONITORING)
getStartedRedirect(
ROUTES.GET_STARTED_APPLICATION_MONITORING,
'Configure Consumer',
)
}
>
Get Started
Expand All @@ -88,7 +109,10 @@ function MessagingQueues(): JSX.Element {
<Button
type="default"
onClick={(): void =>
getStartedRedirect(ROUTES.GET_STARTED_APPLICATION_MONITORING)
getStartedRedirect(
ROUTES.GET_STARTED_APPLICATION_MONITORING,
'Configure Producer',
)
}
>
Get Started
Expand All @@ -106,7 +130,10 @@ function MessagingQueues(): JSX.Element {
<Button
type="default"
onClick={(): void =>
getStartedRedirect(ROUTES.GET_STARTED_INFRASTRUCTURE_MONITORING)
getStartedRedirect(
ROUTES.GET_STARTED_INFRASTRUCTURE_MONITORING,
'Monitor kafka',
)
}
>
Get Started
Expand Down

0 comments on commit 5dc5b2e

Please sign in to comment.