Skip to content

Commit 239cb82

Browse files
[9.0] [Cloud Security] Adding telemetry collection condition based on render condition (#208758) (#210636)
# Backport This will backport the following commits from `main` to `9.0`: - [[Cloud Security] Adding telemetry collection condition based on render condition (#208758)](#208758) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jordan","email":"51442161+JordanSh@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-11T16:33:02Z","message":"[Cloud Security] Adding telemetry collection condition based on render condition (#208758)","sha":"c1aaf6f38cfbe5c4093c7ffd7a1a3ec56b2787dc","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud Security","backport:prev-minor","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[Cloud Security] Adding telemetry collection condition based on render condition","number":208758,"url":"https://github.com/elastic/kibana/pull/208758","mergeCommit":{"message":"[Cloud Security] Adding telemetry collection condition based on render condition (#208758)","sha":"c1aaf6f38cfbe5c4093c7ffd7a1a3ec56b2787dc"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208758","number":208758,"mergeCommit":{"message":"[Cloud Security] Adding telemetry collection condition based on render condition (#208758)","sha":"c1aaf6f38cfbe5c4093c7ffd7a1a3ec56b2787dc"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jordan <51442161+JordanSh@users.noreply.github.com>
1 parent 53379ff commit 239cb82

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

x-pack/platform/packages/shared/kbn-cloud-security-posture/common/utils/ui_metrics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
1010

1111
export const APP_NAME = 'cloud-security';
1212

13-
export const MISCONFIGURATION_INSIGHT = 'misconfiguration-insight' as const;
14-
export const VULNERABILITIES_INSIGHT = 'vulnerabilities-insight' as const;
13+
export const MISCONFIGURATION_INSIGHT = 'misconfiguration-insight-v2' as const;
14+
export const VULNERABILITIES_INSIGHT = 'vulnerabilities-insight-v2' as const;
1515
export const MISCONFIGURATION_INSIGHT_HOST_DETAILS =
1616
`${MISCONFIGURATION_INSIGHT}-host-details` as const;
1717
export const MISCONFIGURATION_INSIGHT_USER_DETAILS =

x-pack/solutions/security/plugins/security_solution/public/flyout/document_details/shared/components/misconfiguration_insight.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ export const MisconfigurationsInsight: React.FC<MisconfigurationsInsightProps> =
8787
'newExpandableFlyoutNavigationEnabled'
8888
);
8989

90-
useEffect(() => {
91-
if (telemetryKey) {
92-
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, telemetryKey);
93-
}
94-
}, [telemetryKey, renderingId]);
95-
9690
const passedFindings = data?.count.passed || 0;
9791
const failedFindings = data?.count.failed || 0;
9892
const totalFindings = useMemo(
9993
() => passedFindings + failedFindings,
10094
[passedFindings, failedFindings]
10195
);
102-
const hasMisconfigurationFindings = totalFindings > 0;
96+
const shouldRender = totalFindings > 0; // this component only renders if there are findings
97+
98+
useEffect(() => {
99+
if (shouldRender && telemetryKey) {
100+
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, telemetryKey);
101+
}
102+
}, [shouldRender, telemetryKey, renderingId]);
103103

104104
const misconfigurationsStats = useMemo(
105105
() => getFindingsStats(passedFindings, failedFindings),
@@ -161,7 +161,7 @@ export const MisconfigurationsInsight: React.FC<MisconfigurationsInsightProps> =
161161
]
162162
);
163163

164-
if (!hasMisconfigurationFindings) return null;
164+
if (!shouldRender) return null;
165165

166166
return (
167167
<EuiFlexItem data-test-subj={dataTestSubj}>

x-pack/solutions/security/plugins/security_solution/public/flyout/document_details/shared/components/vulnerabilities_insight.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,14 @@ export const VulnerabilitiesInsight: React.FC<VulnerabilitiesInsightProps> = ({
8484
'newExpandableFlyoutNavigationEnabled'
8585
);
8686

87-
useEffect(() => {
88-
if (telemetryKey) {
89-
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, telemetryKey);
90-
}
91-
}, [telemetryKey, renderingId]);
92-
9387
const { CRITICAL = 0, HIGH = 0, MEDIUM = 0, LOW = 0, NONE = 0 } = data?.count || {};
9488
const totalVulnerabilities = useMemo(
9589
() => CRITICAL + HIGH + MEDIUM + LOW + NONE,
9690
[CRITICAL, HIGH, MEDIUM, LOW, NONE]
9791
);
9892

99-
const hasVulnerabilitiesFindings = useMemo(
93+
// this component only renders if there are findings
94+
const shouldRender = useMemo(
10095
() =>
10196
hasVulnerabilitiesData({
10297
critical: CRITICAL,
@@ -108,6 +103,12 @@ export const VulnerabilitiesInsight: React.FC<VulnerabilitiesInsightProps> = ({
108103
[CRITICAL, HIGH, MEDIUM, LOW, NONE]
109104
);
110105

106+
useEffect(() => {
107+
if (shouldRender && telemetryKey) {
108+
uiMetricService.trackUiMetric(METRIC_TYPE.COUNT, telemetryKey);
109+
}
110+
}, [shouldRender, telemetryKey, renderingId]);
111+
111112
const vulnerabilitiesStats = useMemo(
112113
() =>
113114
getVulnerabilityStats(
@@ -177,7 +178,7 @@ export const VulnerabilitiesInsight: React.FC<VulnerabilitiesInsightProps> = ({
177178
]
178179
);
179180

180-
if (!hasVulnerabilitiesFindings) return null;
181+
if (!shouldRender) return null;
181182

182183
return (
183184
<EuiFlexItem data-test-subj={dataTestSubj}>

0 commit comments

Comments
 (0)