From 0035ae0072463e787b2e399484008d966ed59864 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 13 Mar 2025 11:34:44 +0530 Subject: [PATCH] chore: update infra monitoring events (#7268) --- .../HostMetricsDetail/HostMetricsDetails.tsx | 43 +++++++---- frontend/src/constants/events.ts | 31 ++++++++ .../InfraMonitoringHosts/HostsList.tsx | 19 +++-- .../InfraMonitoringHosts/HostsListTable.tsx | 6 +- .../ClusterDetails/ClusterDetails.tsx | 64 +++++++++++----- .../Clusters/K8sClustersList.tsx | 54 ++++++++------ .../DaemonSetDetails/DaemonSetDetails.tsx | 70 +++++++++++------- .../DaemonSets/K8sDaemonSetsList.tsx | 53 +++++++++----- .../DeploymentDetails/DeploymentDetails.tsx | 73 ++++++++++++------- .../Deployments/K8sDeploymentsList.tsx | 53 +++++++++----- .../InfraMonitoringK8s/InfraMonitoringK8s.tsx | 11 ++- .../Jobs/JobDetails/JobDetails.tsx | 64 +++++++++++----- .../InfraMonitoringK8s/Jobs/K8sJobsList.tsx | 53 +++++++++----- .../Namespaces/K8sNamespacesList.tsx | 53 +++++++++----- .../NamespaceDetails/NamespaceDetails.tsx | 70 +++++++++++------- .../InfraMonitoringK8s/Nodes/K8sNodesList.tsx | 53 +++++++++----- .../Nodes/NodeDetails/NodeDetails.tsx | 64 +++++++++++----- .../InfraMonitoringK8s/Pods/K8sPodLists.tsx | 53 +++++++++----- .../Pods/PodDetails/PodDetails.tsx | 64 +++++++++++----- .../StatefulSets/K8sStatefulSetsList.tsx | 54 ++++++++------ .../StatefulSetDetails/StatefulSetDetails.tsx | 73 ++++++++++++------- .../Volumes/K8sVolumesList.tsx | 54 ++++++++------ .../Volumes/VolumeDetails/VolumeDetails.tsx | 19 +++-- 23 files changed, 753 insertions(+), 398 deletions(-) diff --git a/frontend/src/components/HostMetricsDetail/HostMetricsDetails.tsx b/frontend/src/components/HostMetricsDetail/HostMetricsDetails.tsx index ee61e687cb..9858a98763 100644 --- a/frontend/src/components/HostMetricsDetail/HostMetricsDetails.tsx +++ b/frontend/src/components/HostMetricsDetail/HostMetricsDetails.tsx @@ -12,6 +12,7 @@ import { } from 'antd'; import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -56,7 +57,6 @@ import HostMetricLogsDetailedView from './HostMetricsLogs/HostMetricLogsDetailed import HostMetricTraces from './HostMetricTraces/HostMetricTraces'; import Metrics from './Metrics/Metrics'; import Processes from './Processes/Processes'; - // eslint-disable-next-line sonarjs/cognitive-complexity function HostMetricsDetails({ host, @@ -120,11 +120,14 @@ function HostMetricsDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Hosts list details page visited', { - host: host?.hostName, - }); + if (host) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.HostEntity, + page: InfraMonitoringEvents.DetailedPage, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [host]); useEffect(() => { setLogFilters(initialFilters); @@ -166,9 +169,10 @@ function HostMetricsDetails({ }); } - logEvent('Infra Monitoring: Hosts list details time updated', { - host: host?.hostName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.HostEntity, interval, + page: InfraMonitoringEvents.DetailedPage, }); }, // eslint-disable-next-line react-hooks/exhaustive-deps @@ -186,9 +190,13 @@ function HostMetricsDetails({ (item) => item.key?.key !== 'id' && item.key?.key !== 'host.name', ); - logEvent('Infra Monitoring: Hosts list details logs filters applied', { - host: host?.hostName, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.HostEntity, + view: InfraMonitoringEvents.LogsView, + page: InfraMonitoringEvents.DetailedPage, + }); + } return { op: 'AND', @@ -211,9 +219,13 @@ function HostMetricsDetails({ (item) => item.key?.key === 'host.name', ); - logEvent('Infra Monitoring: Hosts list details traces filters applied', { - host: host?.hostName, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.HostEntity, + view: InfraMonitoringEvents.TracesView, + page: InfraMonitoringEvents.DetailedPage, + }); + } return { op: 'AND', @@ -237,9 +249,10 @@ function HostMetricsDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Hosts list details explore clicked', { - host: host?.hostName, + logEvent(InfraMonitoringEvents.ExploreClicked, { view: selectedView, + entity: InfraMonitoringEvents.HostEntity, + page: InfraMonitoringEvents.DetailedPage, }); if (selectedView === VIEW_TYPES.LOGS) { diff --git a/frontend/src/constants/events.ts b/frontend/src/constants/events.ts index fe16e83d92..ea7df29a1f 100644 --- a/frontend/src/constants/events.ts +++ b/frontend/src/constants/events.ts @@ -4,3 +4,34 @@ export enum Events { TABLE_COLUMNS_DATA = 'TABLE_COLUMNS_DATA', SLOW_API_WARNING = 'SLOW_API_WARNING', } + +export enum InfraMonitoringEvents { + PageVisited = 'Infra Monitoring: page visited', + PageNumberChanged = 'Infra Monitoring: page number changed', + GroupByChanged = 'Infra Monitoring: group by changed', + FilterApplied = 'Infra Monitoring: filter applied', + ItemClicked = 'Infra Monitoring: item clicked', + TabChanged = 'Infra Monitoring: tab changed', + TimeUpdated = 'Infra Monitoring: time updated', + ExploreClicked = 'Infra Monitoring: explore clicked', + HostEntity = 'host', + K8sEntity = 'k8s', + ListPage = 'list', + DetailedPage = 'detailed', + LogsView = 'logs', + TracesView = 'traces', + EventsView = 'events', + QuickFiltersView = 'quick filters', + MetricsView = 'metrics', + Total = 'total', + Cluster = 'cluster', + DaemonSet = 'daemonSet', + Deployment = 'deployment', + Job = 'job', + Namespace = 'namespace', + Node = 'node', + Volume = 'volume', + Pod = 'pod', + StatefulSet = 'statefulSet', + Volumes = 'volumes', +} diff --git a/frontend/src/container/InfraMonitoringHosts/HostsList.tsx b/frontend/src/container/InfraMonitoringHosts/HostsList.tsx index bdacb99b8f..c06f63a4b0 100644 --- a/frontend/src/container/InfraMonitoringHosts/HostsList.tsx +++ b/frontend/src/container/InfraMonitoringHosts/HostsList.tsx @@ -7,6 +7,7 @@ import { HostListPayload } from 'api/infraMonitoring/getHostLists'; import HostMetricDetail from 'components/HostMetricsDetail'; import QuickFilters from 'components/QuickFilters/QuickFilters'; import { QuickFiltersSource } from 'components/QuickFilters/types'; +import { InfraMonitoringEvents } from 'constants/events'; import { usePageSize } from 'container/InfraMonitoringK8s/utils'; import { useGetHostList } from 'hooks/infraMonitoring/useGetHostList'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -21,7 +22,6 @@ import { GlobalReducer } from 'types/reducer/globalTime'; import HostsListControls from './HostsListControls'; import HostsListTable from './HostsListTable'; import { getHostListsQuery, HostsQuickFiltersConfig } from './utils'; - // eslint-disable-next-line sonarjs/cognitive-complexity function HostsList(): JSX.Element { const { maxTime, minTime } = useSelector( @@ -85,9 +85,12 @@ function HostsList(): JSX.Element { if (isNewFilterAdded) { setCurrentPage(1); - logEvent('Infra Monitoring: Hosts list filters applied', { - filters: value, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.HostEntity, + page: InfraMonitoringEvents.ListPage, + }); + } } }, // eslint-disable-next-line react-hooks/exhaustive-deps @@ -95,8 +98,12 @@ function HostsList(): JSX.Element { ); useEffect(() => { - logEvent('Infra Monitoring: Hosts list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + total: data?.payload?.data?.total, + entity: InfraMonitoringEvents.HostEntity, + page: InfraMonitoringEvents.ListPage, + }); + }, [data?.payload?.data?.total]); const selectedHostData = useMemo(() => { if (!selectedHostName) return null; diff --git a/frontend/src/container/InfraMonitoringHosts/HostsListTable.tsx b/frontend/src/container/InfraMonitoringHosts/HostsListTable.tsx index 841fe52da1..ba9b35143b 100644 --- a/frontend/src/container/InfraMonitoringHosts/HostsListTable.tsx +++ b/frontend/src/container/InfraMonitoringHosts/HostsListTable.tsx @@ -9,6 +9,7 @@ import { } from 'antd'; import { SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; +import { InfraMonitoringEvents } from 'constants/events'; import { useCallback, useMemo } from 'react'; import HostsEmptyOrIncorrectMetrics from './HostsEmptyOrIncorrectMetrics'; @@ -77,8 +78,9 @@ export default function HostsListTable({ const handleRowClick = (record: HostRowData): void => { setSelectedHostName(record.hostName); - logEvent('Infra Monitoring: Hosts list item clicked', { - host: record.hostName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.HostEntity, + page: InfraMonitoringEvents.ListPage, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Clusters/ClusterDetails/ClusterDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Clusters/ClusterDetails/ClusterDetails.tsx index b897b55441..4f14377353 100644 --- a/frontend/src/container/InfraMonitoringK8s/Clusters/ClusterDetails/ClusterDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Clusters/ClusterDetails/ClusterDetails.tsx @@ -7,6 +7,7 @@ import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { K8sClustersData } from 'api/infraMonitoring/getK8sClustersList'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -150,11 +151,15 @@ function ClusterDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Clusters list details page visited', { - cluster: cluster?.clusterUID, - }); + if (cluster) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Cluster, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [cluster]); useEffect(() => { setLogsAndTracesFilters(initialFilters); @@ -176,8 +181,10 @@ function ClusterDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Clusters list details tab changed', { - cluster: cluster?.clusterUID, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Cluster, view: e.target.value, }); }; @@ -200,8 +207,10 @@ function ClusterDetails({ }); } - logEvent('Infra Monitoring: Clusters list details time updated', { - cluster: cluster?.clusterUID, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Cluster, interval, view: selectedView, }); @@ -222,9 +231,14 @@ function ClusterDetails({ item.key?.key !== 'id' && item.key?.key !== QUERY_KEYS.K8S_CLUSTER_NAME, ); - logEvent('Infra Monitoring: Clusters list details logs filters applied', { - cluster: cluster?.clusterUID, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + view: InfraMonitoringEvents.LogsView, + category: InfraMonitoringEvents.Cluster, + }); + } return { op: 'AND', @@ -249,9 +263,14 @@ function ClusterDetails({ [QUERY_KEYS.K8S_CLUSTER_NAME].includes(item.key?.key ?? ''), ); - logEvent('Infra Monitoring: Clusters list details traces filters applied', { - cluster: cluster?.clusterUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + view: InfraMonitoringEvents.TracesView, + category: InfraMonitoringEvents.Cluster, + }); + } return { op: 'AND', @@ -280,9 +299,14 @@ function ClusterDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent('Infra Monitoring: Clusters list details events filters applied', { - cluster: cluster?.clusterUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + view: InfraMonitoringEvents.EventsView, + category: InfraMonitoringEvents.Cluster, + }); + } return { op: 'AND', @@ -313,8 +337,10 @@ function ClusterDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Clusters list details explore clicked', { - cluster: cluster?.clusterUID, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Cluster, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Clusters/K8sClustersList.tsx b/frontend/src/container/InfraMonitoringK8s/Clusters/K8sClustersList.tsx index 59b9082dc2..19e920ffe9 100644 --- a/frontend/src/container/InfraMonitoringK8s/Clusters/K8sClustersList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Clusters/K8sClustersList.tsx @@ -15,6 +15,7 @@ import { import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sClustersListPayload } from 'api/infraMonitoring/getK8sClustersList'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sClustersList } from 'hooks/infraMonitoring/useGetK8sClustersList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -41,7 +42,6 @@ import { getK8sClustersListQuery, K8sClustersRowData, } from './utils'; - // eslint-disable-next-line sonarjs/cognitive-complexity function K8sClustersList({ isFiltersVisible, @@ -240,11 +240,6 @@ function K8sClustersList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -255,10 +250,10 @@ function K8sClustersList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s clusters list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Cluster, }); } @@ -271,7 +266,7 @@ function K8sClustersList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -285,14 +280,25 @@ function K8sClustersList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s clusters list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + category: InfraMonitoringEvents.Cluster, + page: InfraMonitoringEvents.ListPage, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s clusters list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + category: InfraMonitoringEvents.Cluster, + page: InfraMonitoringEvents.ListPage, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedClusterData = useMemo(() => { if (!selectedClusterName) return null; @@ -320,8 +326,10 @@ function K8sClustersList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s cluster list item clicked', { - clusterName: record.clusterName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Cluster, }); }; @@ -450,7 +458,11 @@ function K8sClustersList({ setCurrentPage(1); setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s clusters list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Cluster, + }); }, [groupByFiltersData], ); @@ -469,10 +481,10 @@ function K8sClustersList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s clusters list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Cluster, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/DaemonSets/DaemonSetDetails/DaemonSetDetails.tsx b/frontend/src/container/InfraMonitoringK8s/DaemonSets/DaemonSetDetails/DaemonSetDetails.tsx index 391090e384..01b2f3ced0 100644 --- a/frontend/src/container/InfraMonitoringK8s/DaemonSets/DaemonSetDetails/DaemonSetDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/DaemonSets/DaemonSetDetails/DaemonSetDetails.tsx @@ -6,6 +6,7 @@ import { Button, Divider, Drawer, Radio, Tooltip, Typography } from 'antd'; import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -164,11 +165,15 @@ function DaemonSetDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: DaemonSets list details page visited', { - daemonSet: daemonSet?.daemonSetName, - }); + if (daemonSet) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [daemonSet]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -190,8 +195,10 @@ function DaemonSetDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: DaemonSets list details tab changed', { - daemonSet: daemonSet?.daemonSetName, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, view: e.target.value, }); }; @@ -214,8 +221,10 @@ function DaemonSetDetails({ }); } - logEvent('Infra Monitoring: DaemonSets list details time updated', { - daemonSet: daemonSet?.daemonSetName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, interval, view: selectedView, }); @@ -239,9 +248,14 @@ function DaemonSetDetails({ item.key?.key !== QUERY_KEYS.K8S_DAEMON_SET_NAME, ); - logEvent('Infra Monitoring: DaemonSets list details logs filters applied', { - daemonSet: daemonSet?.daemonSetName, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, + view: InfraMonitoringEvents.LogsView, + }); + } return { op: 'AND', @@ -266,12 +280,14 @@ function DaemonSetDetails({ ), ); - logEvent( - 'Infra Monitoring: DaemonSets list details traces filters applied', - { - daemonSet: daemonSet?.daemonSetName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, + view: InfraMonitoringEvents.TracesView, + }); + } return { op: 'AND', @@ -298,12 +314,14 @@ function DaemonSetDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent( - 'Infra Monitoring: DaemonSets list details events filters applied', - { - daemonSet: daemonSet?.daemonSetName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, + view: InfraMonitoringEvents.EventsView, + }); + } return { op: 'AND', @@ -332,8 +350,10 @@ function DaemonSetDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: DaemonSets list details explore clicked', { - daemonSet: daemonSet?.daemonSetName, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.DaemonSet, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/DaemonSets/K8sDaemonSetsList.tsx b/frontend/src/container/InfraMonitoringK8s/DaemonSets/K8sDaemonSetsList.tsx index 4921590215..8518a470c3 100644 --- a/frontend/src/container/InfraMonitoringK8s/DaemonSets/K8sDaemonSetsList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/DaemonSets/K8sDaemonSetsList.tsx @@ -16,6 +16,7 @@ import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sDaemonSetsListPayload } from 'api/infraMonitoring/getK8sDaemonSetsList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sDaemonSetsList } from 'hooks/infraMonitoring/useGetK8sDaemonSetsList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -243,11 +244,6 @@ function K8sDaemonSetsList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -258,10 +254,10 @@ function K8sDaemonSetsList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s daemonSets list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, }); } @@ -274,7 +270,7 @@ function K8sDaemonSetsList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -288,14 +284,25 @@ function K8sDaemonSetsList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s daemonSets list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s daemonSets list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedDaemonSetData = useMemo(() => { if (groupBy.length > 0) { @@ -327,8 +334,10 @@ function K8sDaemonSetsList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s daemonSet list item clicked', { - daemonSetName: record.daemonsetName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, }); }; @@ -457,7 +466,11 @@ function K8sDaemonSetsList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s daemonSets list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, + }); }, [groupByFiltersData], ); @@ -476,10 +489,10 @@ function K8sDaemonSetsList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s daemonSets list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.DaemonSet, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Deployments/DeploymentDetails/DeploymentDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Deployments/DeploymentDetails/DeploymentDetails.tsx index 953c6f069a..35543753c4 100644 --- a/frontend/src/container/InfraMonitoringK8s/Deployments/DeploymentDetails/DeploymentDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Deployments/DeploymentDetails/DeploymentDetails.tsx @@ -7,6 +7,7 @@ import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { K8sDeploymentsData } from 'api/infraMonitoring/getK8sDeploymentsList'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -166,11 +167,15 @@ function DeploymentDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Deployments list details page visited', { - deployment: deployment?.deploymentName, - }); + if (deployment) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [deployment]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -192,8 +197,10 @@ function DeploymentDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Deployments list details tab changed', { - deployment: deployment?.deploymentName, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, view: e.target.value, }); }; @@ -216,8 +223,10 @@ function DeploymentDetails({ }); } - logEvent('Infra Monitoring: Deployments list details time updated', { - deployment: deployment?.deploymentName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, interval, view: selectedView, }); @@ -241,12 +250,14 @@ function DeploymentDetails({ item.key?.key !== QUERY_KEYS.K8S_DEPLOYMENT_NAME, ); - logEvent( - 'Infra Monitoring: Deployments list details logs filters applied', - { - deployment: deployment?.deploymentName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, + view: InfraMonitoringEvents.LogsView, + }); + } return { op: 'AND', @@ -273,12 +284,14 @@ function DeploymentDetails({ ), ); - logEvent( - 'Infra Monitoring: Deployments list details traces filters applied', - { - deployment: deployment?.deploymentName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, + view: InfraMonitoringEvents.TracesView, + }); + } return { op: 'AND', @@ -307,12 +320,14 @@ function DeploymentDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent( - 'Infra Monitoring: Deployments list details events filters applied', - { - deployment: deployment?.deploymentName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, + view: InfraMonitoringEvents.EventsView, + }); + } return { op: 'AND', @@ -343,8 +358,10 @@ function DeploymentDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Deployments list details explore clicked', { - deployment: deployment?.deploymentName, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Deployment, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Deployments/K8sDeploymentsList.tsx b/frontend/src/container/InfraMonitoringK8s/Deployments/K8sDeploymentsList.tsx index e764cc71d5..7b463bf4af 100644 --- a/frontend/src/container/InfraMonitoringK8s/Deployments/K8sDeploymentsList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Deployments/K8sDeploymentsList.tsx @@ -16,6 +16,7 @@ import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sDeploymentsListPayload } from 'api/infraMonitoring/getK8sDeploymentsList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sDeploymentsList } from 'hooks/infraMonitoring/useGetK8sDeploymentsList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -245,11 +246,6 @@ function K8sDeploymentsList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -260,10 +256,10 @@ function K8sDeploymentsList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s deployments list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, }); } @@ -276,7 +272,7 @@ function K8sDeploymentsList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -290,14 +286,25 @@ function K8sDeploymentsList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s deployments list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s deployments list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedDeploymentData = useMemo(() => { if (!selectedDeploymentUID) return null; @@ -330,8 +337,10 @@ function K8sDeploymentsList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s deployment list item clicked', { - deploymentUID: record.deploymentName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, }); }; @@ -461,7 +470,11 @@ function K8sDeploymentsList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s deployments list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, + }); }, [groupByFiltersData], ); @@ -480,10 +493,10 @@ function K8sDeploymentsList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s deployments list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Deployment, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/InfraMonitoringK8s.tsx b/frontend/src/container/InfraMonitoringK8s/InfraMonitoringK8s.tsx index 39683e01a9..a3f520629d 100644 --- a/frontend/src/container/InfraMonitoringK8s/InfraMonitoringK8s.tsx +++ b/frontend/src/container/InfraMonitoringK8s/InfraMonitoringK8s.tsx @@ -7,6 +7,7 @@ import { Collapse, Tooltip, Typography } from 'antd'; import logEvent from 'api/common/logEvent'; import QuickFilters from 'components/QuickFilters/QuickFilters'; import { QuickFiltersSource } from 'components/QuickFilters/types'; +import { InfraMonitoringEvents } from 'constants/events'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; import { useQueryOperations } from 'hooks/queryBuilder/useQueryBuilderOperations'; import { @@ -70,10 +71,12 @@ export default function InfraMonitoringK8s(): JSX.Element { handleChangeQueryData('filters', query.builder.queryData[0].filters); setQuickFiltersLastUpdated(Date.now()); - logEvent( - `Infra Monitoring: K8s ${selectedCategory} list quick filters applied`, - {}, - ); + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: selectedCategory, + view: InfraMonitoringEvents.QuickFiltersView, + }); }; const items: CollapseProps['items'] = [ diff --git a/frontend/src/container/InfraMonitoringK8s/Jobs/JobDetails/JobDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Jobs/JobDetails/JobDetails.tsx index 216f3a9dce..e66f2931eb 100644 --- a/frontend/src/container/InfraMonitoringK8s/Jobs/JobDetails/JobDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Jobs/JobDetails/JobDetails.tsx @@ -6,6 +6,7 @@ import { Button, Divider, Drawer, Radio, Tooltip, Typography } from 'antd'; import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -161,11 +162,15 @@ function JobDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Jobs list details page visited', { - job: job?.jobName, - }); + if (job) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [job]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -187,8 +192,10 @@ function JobDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Jobs list details tab changed', { - job: job?.jobName, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, view: e.target.value, }); }; @@ -211,8 +218,10 @@ function JobDetails({ }); } - logEvent('Infra Monitoring: Jobs list details time updated', { - job: job?.jobName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, interval, view: selectedView, }); @@ -235,9 +244,14 @@ function JobDetails({ item.key?.key !== 'id' && item.key?.key !== QUERY_KEYS.K8S_JOB_NAME, ); - logEvent('Infra Monitoring: Jobs list details logs filters applied', { - job: job?.jobName, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, + view: 'logs', + }); + } return { op: 'AND', @@ -262,9 +276,14 @@ function JobDetails({ ), ); - logEvent('Infra Monitoring: Jobs list details traces filters applied', { - job: job?.jobName, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, + view: 'traces', + }); + } return { op: 'AND', @@ -291,9 +310,14 @@ function JobDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent('Infra Monitoring: Jobs list details events filters applied', { - job: job?.jobName, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, + view: 'events', + }); + } return { op: 'AND', @@ -322,8 +346,10 @@ function JobDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Jobs list details explore clicked', { - job: job?.jobName, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Job, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Jobs/K8sJobsList.tsx b/frontend/src/container/InfraMonitoringK8s/Jobs/K8sJobsList.tsx index e3a5971f98..397d9b0488 100644 --- a/frontend/src/container/InfraMonitoringK8s/Jobs/K8sJobsList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Jobs/K8sJobsList.tsx @@ -16,6 +16,7 @@ import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sJobsListPayload } from 'api/infraMonitoring/getK8sJobsList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sJobsList } from 'hooks/infraMonitoring/useGetK8sJobsList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -234,11 +235,6 @@ function K8sJobsList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -247,10 +243,10 @@ function K8sJobsList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s jobs list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, }); } @@ -263,7 +259,7 @@ function K8sJobsList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -277,14 +273,25 @@ function K8sJobsList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s jobs list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s jobs list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedJobData = useMemo(() => { if (groupBy.length > 0) { @@ -303,8 +310,10 @@ function K8sJobsList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s job list item clicked', { - jobName: record.jobName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, }); }; @@ -433,7 +442,11 @@ function K8sJobsList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s jobs list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, + }); }, [groupByFiltersData], ); @@ -452,10 +465,10 @@ function K8sJobsList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s jobs list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Job, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Namespaces/K8sNamespacesList.tsx b/frontend/src/container/InfraMonitoringK8s/Namespaces/K8sNamespacesList.tsx index 0b30383c55..5181b3ac80 100644 --- a/frontend/src/container/InfraMonitoringK8s/Namespaces/K8sNamespacesList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Namespaces/K8sNamespacesList.tsx @@ -15,6 +15,7 @@ import { import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sNamespacesListPayload } from 'api/infraMonitoring/getK8sNamespacesList'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sNamespacesList } from 'hooks/infraMonitoring/useGetK8sNamespacesList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -242,11 +243,6 @@ function K8sNamespacesList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -257,10 +253,10 @@ function K8sNamespacesList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s namespaces list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, }); } @@ -273,7 +269,7 @@ function K8sNamespacesList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -287,14 +283,25 @@ function K8sNamespacesList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s namespaces list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s namespaces list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedNamespaceData = useMemo(() => { if (!selectedNamespaceUID) return null; @@ -327,8 +334,10 @@ function K8sNamespacesList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s namespace list item clicked', { - namespaceUID: record.namespaceUID, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, }); }; @@ -458,7 +467,11 @@ function K8sNamespacesList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s namespaces list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, + }); }, [groupByFiltersData], ); @@ -477,10 +490,10 @@ function K8sNamespacesList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s namespaces list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Namespace, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Namespaces/NamespaceDetails/NamespaceDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Namespaces/NamespaceDetails/NamespaceDetails.tsx index ce48b3ea0a..dd42956c57 100644 --- a/frontend/src/container/InfraMonitoringK8s/Namespaces/NamespaceDetails/NamespaceDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Namespaces/NamespaceDetails/NamespaceDetails.tsx @@ -7,6 +7,7 @@ import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { K8sNamespacesData } from 'api/infraMonitoring/getK8sNamespacesList'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -152,11 +153,15 @@ function NamespaceDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Namespaces list details page visited', { - namespace: namespace?.namespaceName, - }); + if (namespace) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [namespace]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -178,8 +183,10 @@ function NamespaceDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Namespaces list details tab changed', { - namespace: namespace?.namespaceName, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, view: e.target.value, }); }; @@ -202,8 +209,10 @@ function NamespaceDetails({ }); } - logEvent('Infra Monitoring: Namespaces list details time updated', { - namespace: namespace?.namespaceName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, interval, view: selectedView, }); @@ -226,9 +235,14 @@ function NamespaceDetails({ item.key?.key !== 'id' && item.key?.key !== QUERY_KEYS.K8S_NAMESPACE_NAME, ); - logEvent('Infra Monitoring: Namespaces list details logs filters applied', { - namespace: namespace?.namespaceName, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, + view: InfraMonitoringEvents.LogsView, + }); + } return { op: 'AND', @@ -253,12 +267,14 @@ function NamespaceDetails({ ), ); - logEvent( - 'Infra Monitoring: Namespaces list details traces filters applied', - { - namespace: namespace?.namespaceName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, + view: InfraMonitoringEvents.TracesView, + }); + } return { op: 'AND', @@ -285,12 +301,14 @@ function NamespaceDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent( - 'Infra Monitoring: Namespaces list details events filters applied', - { - namespace: namespace?.namespaceName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, + view: InfraMonitoringEvents.EventsView, + }); + } return { op: 'AND', @@ -319,8 +337,10 @@ function NamespaceDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Namespaces list details explore clicked', { - namespace: namespace?.namespaceName, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Namespace, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Nodes/K8sNodesList.tsx b/frontend/src/container/InfraMonitoringK8s/Nodes/K8sNodesList.tsx index f96b4057a8..d27f5d9196 100644 --- a/frontend/src/container/InfraMonitoringK8s/Nodes/K8sNodesList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Nodes/K8sNodesList.tsx @@ -15,6 +15,7 @@ import { import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sNodesListPayload } from 'api/infraMonitoring/getK8sNodesList'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sNodesList } from 'hooks/infraMonitoring/useGetK8sNodesList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -233,11 +234,6 @@ function K8sNodesList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -246,10 +242,10 @@ function K8sNodesList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s nodes list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, }); } @@ -262,7 +258,7 @@ function K8sNodesList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -276,14 +272,25 @@ function K8sNodesList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s nodes list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s nodes list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedNodeData = useMemo(() => { if (!selectedNodeUID) return null; @@ -305,8 +312,10 @@ function K8sNodesList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s node list item clicked', { - nodeUID: record.nodeUID, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, }); }; @@ -436,7 +445,11 @@ function K8sNodesList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s nodes list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, + }); }, [groupByFiltersData], ); @@ -455,10 +468,10 @@ function K8sNodesList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s nodes list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Node, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Nodes/NodeDetails/NodeDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Nodes/NodeDetails/NodeDetails.tsx index 18f96ea9ec..9e9b12b213 100644 --- a/frontend/src/container/InfraMonitoringK8s/Nodes/NodeDetails/NodeDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Nodes/NodeDetails/NodeDetails.tsx @@ -7,6 +7,7 @@ import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { K8sNodesData } from 'api/infraMonitoring/getK8sNodesList'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -150,11 +151,15 @@ function NodeDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Nodes list details page visited', { - node: node?.nodeUID, - }); + if (node) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [node]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -176,8 +181,10 @@ function NodeDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Nodes list details tab changed', { - node: node?.nodeUID, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, view: e.target.value, }); }; @@ -200,8 +207,10 @@ function NodeDetails({ }); } - logEvent('Infra Monitoring: Nodes list details time updated', { - node: node?.nodeUID, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, interval, view: selectedView, }); @@ -224,9 +233,14 @@ function NodeDetails({ item.key?.key !== 'id' && item.key?.key !== QUERY_KEYS.K8S_NODE_NAME, ); - logEvent('Infra Monitoring: Nodes list details logs filters applied', { - node: node?.nodeUID, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, + view: InfraMonitoringEvents.LogsView, + }); + } return { op: 'AND', @@ -253,9 +267,14 @@ function NodeDetails({ ), ); - logEvent('Infra Monitoring: Nodes list details traces filters applied', { - node: node?.nodeUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, + view: InfraMonitoringEvents.TracesView, + }); + } return { op: 'AND', @@ -284,9 +303,14 @@ function NodeDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent('Infra Monitoring: Nodes list details events filters applied', { - node: node?.nodeUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, + view: InfraMonitoringEvents.EventsView, + }); + } return { op: 'AND', @@ -315,8 +339,10 @@ function NodeDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Nodes list details explore clicked', { - node: node?.nodeUID, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Node, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Pods/K8sPodLists.tsx b/frontend/src/container/InfraMonitoringK8s/Pods/K8sPodLists.tsx index 4269e4f1a3..08d8a2ddc4 100644 --- a/frontend/src/container/InfraMonitoringK8s/Pods/K8sPodLists.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Pods/K8sPodLists.tsx @@ -16,6 +16,7 @@ import set from 'api/browser/localstorage/set'; import logEvent from 'api/common/logEvent'; import { K8sPodsListPayload } from 'api/infraMonitoring/getK8sPodsList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sPodsList } from 'hooks/infraMonitoring/useGetK8sPodsList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -248,11 +249,6 @@ function K8sPodsList({ groupBy, ]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -261,10 +257,10 @@ function K8sPodsList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s pods list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, }); } @@ -277,7 +273,7 @@ function K8sPodsList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -291,7 +287,13 @@ function K8sPodsList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s pods list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, + }); + } }, [handleChangeQueryData], ); @@ -317,14 +319,23 @@ function K8sPodsList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s pods list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, + }); }, [groupByFiltersData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s pods list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedPodData = useMemo(() => { if (!selectedPodUID) return null; @@ -360,8 +371,10 @@ function K8sPodsList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s pods list item clicked', { - podUID: record.podUID, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, }); }; @@ -512,10 +525,10 @@ function K8sPodsList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s pods list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Pod, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Pods/PodDetails/PodDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Pods/PodDetails/PodDetails.tsx index fbec26acef..cb123e6ae3 100644 --- a/frontend/src/container/InfraMonitoringK8s/Pods/PodDetails/PodDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Pods/PodDetails/PodDetails.tsx @@ -8,6 +8,7 @@ import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { K8sPodsData } from 'api/infraMonitoring/getK8sPodsList'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -167,11 +168,15 @@ function PodDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: Pods list details page visited', { - pod: pod?.podUID, - }); + if (pod) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [pod]); useEffect(() => { setLogsAndTracesFilters(initialFilters); @@ -193,8 +198,10 @@ function PodDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: Pods list details tab changed', { - pod: pod?.podUID, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, view: e.target.value, }); }; @@ -217,8 +224,10 @@ function PodDetails({ }); } - logEvent('Infra Monitoring: Pods list details time updated', { - pod: pod?.podUID, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, interval, view: selectedView, }); @@ -243,9 +252,14 @@ function PodDetails({ item.key?.key !== 'id' && item.key?.key !== QUERY_KEYS.K8S_CLUSTER_NAME, ); - logEvent('Infra Monitoring: Pods list details logs filters applied', { - pod: pod?.podUID, - }); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, + view: selectedView, + }); + } return { op: 'AND', @@ -274,9 +288,14 @@ function PodDetails({ ].includes(item.key?.key ?? ''), ); - logEvent('Infra Monitoring: Pods list details traces filters applied', { - pod: pod?.podUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, + view: selectedView, + }); + } return { op: 'AND', @@ -305,9 +324,14 @@ function PodDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent('Infra Monitoring: Pods list details events filters applied', { - pod: pod?.podUID, - }); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, + view: selectedView, + }); + } return { op: 'AND', @@ -336,8 +360,10 @@ function PodDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: Pods list details explore clicked', { - pod: pod?.podUID, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Pod, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/StatefulSets/K8sStatefulSetsList.tsx b/frontend/src/container/InfraMonitoringK8s/StatefulSets/K8sStatefulSetsList.tsx index 6818f65434..f3bdb46ec5 100644 --- a/frontend/src/container/InfraMonitoringK8s/StatefulSets/K8sStatefulSetsList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/StatefulSets/K8sStatefulSetsList.tsx @@ -16,6 +16,7 @@ import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sStatefulSetsListPayload } from 'api/infraMonitoring/getsK8sStatefulSetsList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sStatefulSetsList } from 'hooks/infraMonitoring/useGetK8sStatefulSetsList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -42,7 +43,6 @@ import { getK8sStatefulSetsListQuery, K8sStatefulSetsRowData, } from './utils'; - // eslint-disable-next-line sonarjs/cognitive-complexity function K8sStatefulSetsList({ isFiltersVisible, @@ -245,11 +245,6 @@ function K8sStatefulSetsList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -260,10 +255,10 @@ function K8sStatefulSetsList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s statefulSets list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, }); } @@ -276,7 +271,7 @@ function K8sStatefulSetsList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -290,14 +285,25 @@ function K8sStatefulSetsList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s statefulSets list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s statefulSets list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedStatefulSetData = useMemo(() => { if (!selectedStatefulSetUID) return null; @@ -328,8 +334,10 @@ function K8sStatefulSetsList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s statefulSet list item clicked', { - statefulSetName: record.statefulsetName, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, }); }; @@ -458,7 +466,11 @@ function K8sStatefulSetsList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s statefulSets list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, + }); }, [groupByFiltersData], ); @@ -477,10 +489,10 @@ function K8sStatefulSetsList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s statefulSets list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.StatefulSet, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/StatefulSets/StatefulSetDetails/StatefulSetDetails.tsx b/frontend/src/container/InfraMonitoringK8s/StatefulSets/StatefulSetDetails/StatefulSetDetails.tsx index f4fc996012..218ddffac4 100644 --- a/frontend/src/container/InfraMonitoringK8s/StatefulSets/StatefulSetDetails/StatefulSetDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/StatefulSets/StatefulSetDetails/StatefulSetDetails.tsx @@ -6,6 +6,7 @@ import { Button, Divider, Drawer, Radio, Tooltip, Typography } from 'antd'; import { RadioChangeEvent } from 'antd/lib'; import logEvent from 'api/common/logEvent'; import { VIEW_TYPES, VIEWS } from 'components/HostMetricsDetail/constants'; +import { InfraMonitoringEvents } from 'constants/events'; import { QueryParams } from 'constants/query'; import { initialQueryBuilderFormValuesMap, @@ -167,11 +168,15 @@ function StatefulSetDetails({ ); useEffect(() => { - logEvent('Infra Monitoring: StatefulSets list details page visited', { - statefulSet: statefulSet?.statefulSetName, - }); + if (statefulSet) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [statefulSet]); useEffect(() => { setLogAndTracesFilters(initialFilters); @@ -193,8 +198,10 @@ function StatefulSetDetails({ const handleTabChange = (e: RadioChangeEvent): void => { setSelectedView(e.target.value); - logEvent('Infra Monitoring: StatefulSets list details tab changed', { - statefulSet: statefulSet?.statefulSetName, + logEvent(InfraMonitoringEvents.TabChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, view: e.target.value, }); }; @@ -217,8 +224,10 @@ function StatefulSetDetails({ }); } - logEvent('Infra Monitoring: StatefulSets list details time updated', { - statefulSet: statefulSet?.statefulSetName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, interval, view: selectedView, }); @@ -242,12 +251,14 @@ function StatefulSetDetails({ item.key?.key !== QUERY_KEYS.K8S_STATEFUL_SET_NAME, ); - logEvent( - 'Infra Monitoring: StatefulSets list details logs filters applied', - { - statefulSet: statefulSet?.statefulSetName, - }, - ); + if (newFilters.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, + view: 'logs', + }); + } return { op: 'AND', @@ -272,12 +283,14 @@ function StatefulSetDetails({ ), ); - logEvent( - 'Infra Monitoring: StatefulSets list details traces filters applied', - { - statefulSet: statefulSet?.statefulSetName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, + view: 'traces', + }); + } return { op: 'AND', @@ -304,12 +317,14 @@ function StatefulSetDetails({ (item) => item.key?.key === QUERY_KEYS.K8S_OBJECT_NAME, ); - logEvent( - 'Infra Monitoring: StatefulSets list details events filters applied', - { - statefulSet: statefulSet?.statefulSetName, - }, - ); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, + view: 'logs', + }); + } return { op: 'AND', @@ -338,8 +353,10 @@ function StatefulSetDetails({ urlQuery.set(QueryParams.endTime, modalTimeRange.endTime.toString()); } - logEvent('Infra Monitoring: StatefulSets list details explore clicked', { - statefulSet: statefulSet?.statefulSetName, + logEvent(InfraMonitoringEvents.ExploreClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.StatefulSet, view: selectedView, }); diff --git a/frontend/src/container/InfraMonitoringK8s/Volumes/K8sVolumesList.tsx b/frontend/src/container/InfraMonitoringK8s/Volumes/K8sVolumesList.tsx index a61094c2f1..9ade0544ec 100644 --- a/frontend/src/container/InfraMonitoringK8s/Volumes/K8sVolumesList.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Volumes/K8sVolumesList.tsx @@ -16,6 +16,7 @@ import { ColumnType, SorterResult } from 'antd/es/table/interface'; import logEvent from 'api/common/logEvent'; import { K8sVolumesListPayload } from 'api/infraMonitoring/getK8sVolumesList'; import classNames from 'classnames'; +import { InfraMonitoringEvents } from 'constants/events'; import { useGetK8sVolumesList } from 'hooks/infraMonitoring/useGetK8sVolumesList'; import { useGetAggregateKeys } from 'hooks/queryBuilder/useGetAggregateKeys'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; @@ -42,7 +43,6 @@ import { K8sVolumesRowData, } from './utils'; import VolumeDetails from './VolumeDetails'; - // eslint-disable-next-line sonarjs/cognitive-complexity function K8sVolumesList({ isFiltersVisible, @@ -237,11 +237,6 @@ function K8sVolumesList({ } }, [selectedRowData, fetchGroupedByRowData]); - const numberOfPages = useMemo(() => Math.ceil(totalCount / pageSize), [ - totalCount, - pageSize, - ]); - const handleTableChange: TableProps['onChange'] = useCallback( ( pagination: TablePaginationConfig, @@ -250,10 +245,10 @@ function K8sVolumesList({ ): void => { if (pagination.current) { setCurrentPage(pagination.current); - logEvent('Infra Monitoring: K8s volumes list page number changed', { - page: pagination.current, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, }); } @@ -266,7 +261,7 @@ function K8sVolumesList({ setOrderBy(null); } }, - [numberOfPages, pageSize], + [], ); const { handleChangeQueryData } = useQueryOperations({ @@ -280,14 +275,25 @@ function K8sVolumesList({ handleChangeQueryData('filters', value); setCurrentPage(1); - logEvent('Infra Monitoring: K8s volumes list filters applied', {}); + if (value.items.length > 0) { + logEvent(InfraMonitoringEvents.FilterApplied, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, + }); + } }, [handleChangeQueryData], ); useEffect(() => { - logEvent('Infra Monitoring: K8s volumes list page visited', {}); - }, []); + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, + total: data?.payload?.data?.total, + }); + }, [data?.payload?.data?.total]); const selectedVolumeData = useMemo(() => { if (!selectedVolumeUID) return null; @@ -313,8 +319,10 @@ function K8sVolumesList({ handleGroupByRowClick(record); } - logEvent('Infra Monitoring: K8s volume list item clicked', { - volumeUID: record.volumeUID, + logEvent(InfraMonitoringEvents.ItemClicked, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, }); }; @@ -443,7 +451,11 @@ function K8sVolumesList({ setGroupBy(groupBy); setExpandedRowKeys([]); - logEvent('Infra Monitoring: K8s volumes list group by changed', {}); + logEvent(InfraMonitoringEvents.GroupByChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, + }); }, [groupByFiltersData], ); @@ -462,10 +474,10 @@ function K8sVolumesList({ const onPaginationChange = (page: number, pageSize: number): void => { setCurrentPage(page); setPageSize(pageSize); - logEvent('Infra Monitoring: K8s volumes list page number changed', { - page, - pageSize, - numberOfPages, + logEvent(InfraMonitoringEvents.PageNumberChanged, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.ListPage, + category: InfraMonitoringEvents.Volumes, }); }; diff --git a/frontend/src/container/InfraMonitoringK8s/Volumes/VolumeDetails/VolumeDetails.tsx b/frontend/src/container/InfraMonitoringK8s/Volumes/VolumeDetails/VolumeDetails.tsx index b5bae03aee..480a131043 100644 --- a/frontend/src/container/InfraMonitoringK8s/Volumes/VolumeDetails/VolumeDetails.tsx +++ b/frontend/src/container/InfraMonitoringK8s/Volumes/VolumeDetails/VolumeDetails.tsx @@ -4,6 +4,7 @@ import '../../EntityDetailsUtils/entityDetails.styles.scss'; import { Color, Spacing } from '@signozhq/design-tokens'; import { Divider, Drawer, Tooltip, Typography } from 'antd'; import logEvent from 'api/common/logEvent'; +import { InfraMonitoringEvents } from 'constants/events'; import { K8sCategory } from 'container/InfraMonitoringK8s/constants'; import { CustomTimeType, @@ -50,11 +51,15 @@ function VolumeDetails({ const isDarkMode = useIsDarkMode(); useEffect(() => { - logEvent('Infra Monitoring: Volumes list details page visited', { - volume: volume?.persistentVolumeClaimName, - }); + if (volume) { + logEvent(InfraMonitoringEvents.PageVisited, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Volume, + }); + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [volume]); useEffect(() => { setSelectedInterval(selectedTime as Time); @@ -87,8 +92,10 @@ function VolumeDetails({ }); } - logEvent('Infra Monitoring: Volumes list details time updated', { - volume: volume?.persistentVolumeClaimName, + logEvent(InfraMonitoringEvents.TimeUpdated, { + entity: InfraMonitoringEvents.K8sEntity, + page: InfraMonitoringEvents.DetailedPage, + category: InfraMonitoringEvents.Volume, interval, }); },