Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Security] Fixes SVG flickering and adding insight telemetry #198812

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';

export const APP_NAME = 'cloud-security';

export const MISCONFIGURATION_INSIGHT = 'misconfiguration-insight';
export const VULNERABILITIES_INSIGHT = 'vulnerabilities-insight';
export const ENTITY_FLYOUT_WITH_MISCONFIGURATION_VISIT =
'entity-flyout-with-misconfiguration-visits';
export const ENTITY_FLYOUT_WITH_VULNERABILITY_PREVIEW =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

// dimensions of the SVGs used in the empty states illustrations
// e.g. x-pack/plugins/cloud_security_posture/public/assets/illustrations/clouds.svg
const SVG_HEIGHT = 209;
const SVG_WIDTH = 376;

/**
* A container component that maintains a fixed size for child elements.
* used for displaying the empty state illustrations and prevent flickering while the SVGs are loading.
*/
export const EmptyStatesIllustrationContainer: React.FC<{ children: React.ReactNode }> = ({
children,
}) => <div style={{ height: SVG_HEIGHT, width: SVG_WIDTH }}>{children}</div>;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { IndexDetails, CspStatusCode } from '@kbn/cloud-security-posture-co
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
import { useLocation } from 'react-router-dom';
import { findingsNavigation } from '@kbn/cloud-security-posture';
import { EmptyStatesIllustrationContainer } from '../empty_states_illustration_container';
import { useAdd3PIntegrationRoute } from '../../common/api/use_wiz_integration_route';
import { FullSizeCenteredPage } from '../full_size_centered_page';
import { useCISIntegrationPoliciesLink } from '../../common/navigation/use_navigate_to_cis_integration_policies';
Expand Down Expand Up @@ -191,7 +192,11 @@ const EmptySecurityFindingsPrompt = () => {
<EuiEmptyPrompt
style={{ padding: euiTheme.size.l }}
data-test-subj={PACKAGE_NOT_INSTALLED_TEST_SUBJECT}
icon={<EuiImage size="fullWidth" src={cloudsSVG} alt="clouds" role="presentation" />}
icon={
<EmptyStatesIllustrationContainer>
<EuiImage size="fullWidth" src={cloudsSVG} alt="clouds" role="presentation" />
</EmptyStatesIllustrationContainer>
}
title={
<h2>
<FormattedMessage
Expand Down Expand Up @@ -264,12 +269,14 @@ const EmptySecurityFindingsPrompt = () => {
style={{ padding: euiTheme.size.l }}
data-test-subj={THIRD_PARTY_INTEGRATIONS_NO_MISCONFIGURATIONS_FINDINGS_PROMPT}
icon={
<EuiImage
size="fullWidth"
src={misconfigurationsVendorsSVG}
alt="misconfigurationsVendorsSVG"
role="presentation"
/>
<EmptyStatesIllustrationContainer>
<EuiImage
size="fullWidth"
src={misconfigurationsVendorsSVG}
alt="misconfigurationsVendorsSVG"
role="presentation"
/>
</EmptyStatesIllustrationContainer>
}
title={
<h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { IndexDetails } from '@kbn/cloud-security-posture-common';
import { useCspSetupStatusApi } from '@kbn/cloud-security-posture/src/hooks/use_csp_setup_status_api';
import { useLocation } from 'react-router-dom';
import { findingsNavigation } from '@kbn/cloud-security-posture';
import { EmptyStatesIllustrationContainer } from './empty_states_illustration_container';
import { VULN_MGMT_POLICY_TEMPLATE } from '../../common/constants';
import { FullSizeCenteredPage } from './full_size_centered_page';
import { CloudPosturePage } from './cloud_posture_page';
Expand Down Expand Up @@ -84,7 +85,11 @@ const CnvmIntegrationNotInstalledEmptyPrompt = ({
<EuiEmptyPrompt
style={{ padding: euiTheme.size.l }}
data-test-subj={NO_VULNERABILITIES_STATUS_TEST_SUBJ.NOT_INSTALLED}
icon={<EuiImage size="fullWidth" src={cloudsSVG} alt="clouds" role="presentation" />}
icon={
<EmptyStatesIllustrationContainer>
<EuiImage size="fullWidth" src={cloudsSVG} alt="clouds" role="presentation" />
</EmptyStatesIllustrationContainer>
}
title={
<h2>
<FormattedMessage
Expand Down Expand Up @@ -144,12 +149,14 @@ const CnvmIntegrationNotInstalledEmptyPrompt = ({
style={{ padding: euiTheme.size.l }}
data-test-subj={THIRD_PARTY_INTEGRATIONS_NO_VULNERABILITIES_FINDINGS_PROMPT}
icon={
<EuiImage
size="fullWidth"
src={vulnerabilitiesVendorsSVG}
alt="vulnerabilitiesVendorsSVG"
role="presentation"
/>
<EmptyStatesIllustrationContainer>
<EuiImage
size="fullWidth"
src={vulnerabilitiesVendorsSVG}
alt="vulnerabilitiesVendorsSVG"
role="presentation"
/>
</EmptyStatesIllustrationContainer>
}
title={
<h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* 2.0.
*/

import React, { useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';
import { EuiFlexItem, type EuiFlexGroupProps, useEuiTheme } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { css } from '@emotion/css';
import { useMisconfigurationPreview } from '@kbn/cloud-security-posture/src/hooks/use_misconfiguration_preview';
import { buildEntityFlyoutPreviewQuery } from '@kbn/cloud-security-posture-common';
import {
MISCONFIGURATION_INSIGHT,
uiMetricService,
} from '@kbn/cloud-security-posture-common/utils/ui_metrics';
import { METRIC_TYPE } from '@kbn/analytics';
import { InsightDistributionBar } from './insight_distribution_bar';
import { getFindingsStats } from '../../../../cloud_security_posture/components/misconfiguration/misconfiguration_preview';
import { FormattedCount } from '../../../../common/components/formatted_number';
Expand Down Expand Up @@ -54,6 +59,14 @@ export const MisconfigurationsInsight: React.FC<MisconfigurationsInsightProps> =
pageSize: 1,
});

useEffect(() => {
uiMetricService.trackUiMetric(
METRIC_TYPE.COUNT,
`${MISCONFIGURATION_INSIGHT} instance id: ${dataTestSubj}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't couple the test id with the tracking tbh, let's introduce a prop dedicated to tracking. If we change the test id for some reason, the tracking info will also change which might affect reports and numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. @CohenIdo would we also want to insert the field (user/host) to the id? so we can track which is more used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a telemetrySuffix prop. left the values as plain texts rather than constants because if this component will be moved i prefer it to be clear that the suffix might need to change as well.

);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const passedFindings = data?.count.passed || 0;
const failedFindings = data?.count.failed || 0;
const totalFindings = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
* 2.0.
*/

import React, { useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';
import { EuiFlexItem, type EuiFlexGroupProps, useEuiTheme } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { css } from '@emotion/css';
import { useVulnerabilitiesPreview } from '@kbn/cloud-security-posture/src/hooks/use_vulnerabilities_preview';
import { buildEntityFlyoutPreviewQuery } from '@kbn/cloud-security-posture-common';
import { getVulnerabilityStats, hasVulnerabilitiesData } from '@kbn/cloud-security-posture';
import {
uiMetricService,
VULNERABILITIES_INSIGHT,
} from '@kbn/cloud-security-posture-common/utils/ui_metrics';
import { METRIC_TYPE } from '@kbn/analytics';
import { InsightDistributionBar } from './insight_distribution_bar';
import { FormattedCount } from '../../../../common/components/formatted_number';
import { PreviewLink } from '../../../shared/components/preview_link';
Expand Down Expand Up @@ -49,6 +54,14 @@ export const VulnerabilitiesInsight: React.FC<VulnerabilitiesInsightProps> = ({
pageSize: 1,
});

useEffect(() => {
uiMetricService.trackUiMetric(
METRIC_TYPE.COUNT,
`${VULNERABILITIES_INSIGHT} instance id: ${dataTestSubj}`
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { CRITICAL = 0, HIGH = 0, MEDIUM = 0, LOW = 0, NONE = 0 } = data?.count || {};
const totalVulnerabilities = useMemo(
() => CRITICAL + HIGH + MEDIUM + LOW + NONE,
Expand Down