Skip to content

Commit

Permalink
CDR workflow UI counters
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenIdo authored Oct 15, 2024
1 parent ded2740 commit 489dc1d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';

export const APP_NAME = 'cloud-security';

export const ENTITY_FLYOUT_MISCONFIGURATION_VIEW_VISITS =
'entity-flyout-misconfiguration-view-visits';
export const ENTITY_FLYOUT_WITH_MISCONFIGURATION_VISIT =
'entity-flyout-with-misconfiguration-visits';
export const ENTITY_FLYOUT_WITH_VULNERABILITY_PREVIEW =
'entity-flyout-with-vulnerability-preview-visits';
export const ENTITY_FLYOUT_EXPAND_MISCONFIGURATION_VIEW_VISITS =
'entity-flyout-expand-misconfiguration-view-visits';
export const ENTITY_FLYOUT_EXPAND_VULNERABILITY_VIEW_VISITS =
'entity-flyout-expand-vulnerability-view-visits';
export const NAV_TO_FINDINGS_BY_HOST_NAME_FRPOM_ENTITY_FLYOUT =
'nav-to-findings-by-host-name-from-entity-flyout';
export const NAV_TO_FINDINGS_BY_RULE_NAME_FRPOM_ENTITY_FLYOUT =
Expand All @@ -22,18 +28,19 @@ export const VULNERABILITIES_FLYOUT_VISITS = 'vulnerabilities-flyout-visits';
export const OPEN_FINDINGS_FLYOUT = 'open-findings-flyout';
export const GROUP_BY_CLICK = 'group-by-click';
export const CHANGE_RULE_STATE = 'change-rule-state';
export const ENTITY_FLYOUT_VULNERABILITY_VIEW_VISITS = 'entity-flyout-vulnerability-view-visits';

type CloudSecurityUiCounters =
| typeof ENTITY_FLYOUT_MISCONFIGURATION_VIEW_VISITS
| typeof ENTITY_FLYOUT_WITH_MISCONFIGURATION_VISIT
| typeof ENTITY_FLYOUT_WITH_VULNERABILITY_PREVIEW
| typeof ENTITY_FLYOUT_EXPAND_MISCONFIGURATION_VIEW_VISITS
| typeof ENTITY_FLYOUT_EXPAND_VULNERABILITY_VIEW_VISITS
| typeof NAV_TO_FINDINGS_BY_HOST_NAME_FRPOM_ENTITY_FLYOUT
| typeof VULNERABILITIES_FLYOUT_VISITS
| typeof NAV_TO_FINDINGS_BY_RULE_NAME_FRPOM_ENTITY_FLYOUT
| typeof VULNERABILITIES_FLYOUT_VISITS
| typeof OPEN_FINDINGS_FLYOUT
| typeof CREATE_DETECTION_RULE_FROM_FLYOUT
| typeof CREATE_DETECTION_FROM_TABLE_ROW_ACTION
| typeof GROUP_BY_CLICK
| typeof ENTITY_FLYOUT_VULNERABILITY_VIEW_VISITS
| typeof CHANGE_RULE_STATE;

export class UiMetricService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { memo, useState } from 'react';
import React, { memo, useEffect, useState } from 'react';
import type { Criteria, EuiBasicTableColumn } from '@elastic/eui';
import { EuiSpacer, EuiIcon, EuiPanel, EuiLink, EuiText, EuiBasicTable } from '@elastic/eui';
import { useMisconfigurationFindings } from '@kbn/cloud-security-posture/src/hooks/use_misconfiguration_findings';
Expand All @@ -18,7 +18,7 @@ import { useNavigateFindings } from '@kbn/cloud-security-posture/src/hooks/use_n
import type { CspBenchmarkRuleMetadata } from '@kbn/cloud-security-posture-common/schema/rules/latest';
import { CspEvaluationBadge } from '@kbn/cloud-security-posture';
import {
ENTITY_FLYOUT_MISCONFIGURATION_VIEW_VISITS,
ENTITY_FLYOUT_EXPAND_MISCONFIGURATION_VIEW_VISITS,
NAV_TO_FINDINGS_BY_HOST_NAME_FRPOM_ENTITY_FLYOUT,
NAV_TO_FINDINGS_BY_RULE_NAME_FRPOM_ENTITY_FLYOUT,
uiMetricService,
Expand Down Expand Up @@ -58,7 +58,13 @@ const getFindingsStats = (passedFindingsStats: number, failedFindingsStats: numb
*/
export const MisconfigurationFindingsDetailsTable = memo(
({ fieldName, queryName }: { fieldName: 'host.name' | 'user.name'; queryName: string }) => {
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, ENTITY_FLYOUT_MISCONFIGURATION_VIEW_VISITS);
useEffect(() => {
uiMetricService.trackUiMetric(
METRIC_TYPE.COUNT,
ENTITY_FLYOUT_EXPAND_MISCONFIGURATION_VIEW_VISITS
);
}, []);

const { data } = useMisconfigurationFindings({
query: buildEntityFlyoutPreviewQuery(fieldName, queryName),
sort: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { memo, useState } from 'react';
import React, { memo, useEffect, useState } from 'react';
import type { Criteria, EuiBasicTableColumn } from '@elastic/eui';
import { EuiSpacer, EuiIcon, EuiPanel, EuiLink, EuiText, EuiBasicTable } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
Expand All @@ -24,7 +24,7 @@ import {
SeverityStatusBadge,
} from '@kbn/cloud-security-posture';
import {
ENTITY_FLYOUT_VULNERABILITY_VIEW_VISITS,
ENTITY_FLYOUT_EXPAND_VULNERABILITY_VIEW_VISITS,
NAV_TO_FINDINGS_BY_HOST_NAME_FRPOM_ENTITY_FLYOUT,
uiMetricService,
} from '@kbn/cloud-security-posture-common/utils/ui_metrics';
Expand All @@ -42,7 +42,13 @@ interface VulnerabilitiesPackage extends Vulnerability {
}

export const VulnerabilitiesFindingsDetailsTable = memo(({ queryName }: { queryName: string }) => {
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, ENTITY_FLYOUT_VULNERABILITY_VIEW_VISITS);
useEffect(() => {
uiMetricService.trackUiMetric(
METRIC_TYPE.COUNT,
ENTITY_FLYOUT_EXPAND_VULNERABILITY_VIEW_VISITS
);
}, []);

const { data } = useVulnerabilitiesFindings({
query: buildEntityFlyoutPreviewQuery('host.name', queryName),
sort: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';
import { css } from '@emotion/react';
import type { EuiThemeComputed } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText, useEuiTheme, EuiTitle } from '@elastic/eui';
Expand All @@ -19,6 +19,11 @@ import { buildEntityFlyoutPreviewQuery } from '@kbn/cloud-security-posture-commo
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import { useVulnerabilitiesPreview } from '@kbn/cloud-security-posture/src/hooks/use_vulnerabilities_preview';
import { hasVulnerabilitiesData } from '@kbn/cloud-security-posture';
import { METRIC_TYPE } from '@kbn/analytics';
import {
ENTITY_FLYOUT_WITH_MISCONFIGURATION_VISIT,
uiMetricService,
} from '@kbn/cloud-security-posture-common/utils/ui_metrics';
import {
CspInsightLeftPanelSubTab,
EntityDetailsLeftPanelTab,
Expand Down Expand Up @@ -120,6 +125,9 @@ export const MisconfigurationsPreview = ({
const passedFindings = data?.count.passed || 0;
const failedFindings = data?.count.failed || 0;

useEffect(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, ENTITY_FLYOUT_WITH_MISCONFIGURATION_VISIT);
}, []);
const { euiTheme } = useEuiTheme();
const hasMisconfigurationFindings = passedFindings > 0 || failedFindings > 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';
import { css } from '@emotion/react';
import type { EuiThemeComputed } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText, useEuiTheme, EuiTitle } from '@elastic/eui';
Expand All @@ -20,6 +20,11 @@ import {
import { getVulnerabilityStats, hasVulnerabilitiesData } from '@kbn/cloud-security-posture';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import { useMisconfigurationPreview } from '@kbn/cloud-security-posture/src/hooks/use_misconfiguration_preview';
import {
ENTITY_FLYOUT_WITH_VULNERABILITY_PREVIEW,
uiMetricService,
} from '@kbn/cloud-security-posture-common/utils/ui_metrics';
import { METRIC_TYPE } from '@kbn/analytics';
import { EntityDetailsLeftPanelTab } from '../../../flyout/entity_details/shared/components/left_panel/left_panel_header';
import { HostDetailsPanelKey } from '../../../flyout/entity_details/host_details_left';
import { useRiskScore } from '../../../entity_analytics/api/hooks/use_risk_score';
Expand Down Expand Up @@ -71,6 +76,10 @@ export const VulnerabilitiesPreview = ({
name: string;
isPreviewMode?: boolean;
}) => {
useEffect(() => {
uiMetricService.trackUiMetric(METRIC_TYPE.CLICK, ENTITY_FLYOUT_WITH_VULNERABILITY_PREVIEW);
}, []);

const { data } = useVulnerabilitiesPreview({
query: buildEntityFlyoutPreviewQuery('host.name', name),
sort: [],
Expand Down

0 comments on commit 489dc1d

Please sign in to comment.