-
Bug
-
Resolution: Unresolved
-
Normal
-
None
-
4.18.0
-
None
-
None
-
False
-
Description of problem:
See https://github.com/openshift/console/blob/d60f090b5499f76bf6c49dde6bd1469f4c2c3995/frontend/packages/console-shared/src/hooks/useTelemetry.ts#L44-L45
Required changes to useTelemetry.ts:
diff --git a/frontend/packages/console-shared/src/hooks/useTelemetry.ts b/frontend/packages/console-shared/src/hooks/useTelemetry.ts index cdac520fce..e25f25121e 100644 --- a/frontend/packages/console-shared/src/hooks/useTelemetry.ts +++ b/frontend/packages/console-shared/src/hooks/useTelemetry.ts @@ -5,6 +5,7 @@ import { TelemetryListener, TelemetryEventListener, } from '@console/dynamic-plugin-sdk'; +import { useDynamicPluginInfo } from '@console/plugin-sdk/src/api/useDynamicPluginInfo'; import { CLUSTER_TELEMETRY_ANALYTICS, PREFERRED_TELEMETRY_USER_SETTING_KEY, @@ -41,8 +42,8 @@ let clusterProperties = getClusterProperties(); export const updateClusterPropertiesFromTests = () => (clusterProperties = getClusterProperties()); export const useTelemetry = () => { - // TODO use useDynamicPluginInfo() hook to tell whether all dynamic plugins have been processed - // to avoid firing telemetry events multiple times whenever a dynamic plugin loads asynchronously + const [, allPluginsProcessed] = useDynamicPluginInfo(); + const [extensions] = useResolvedExtensions<TelemetryListener>(isTelemetryListener); const [currentUserPreferenceTelemetryValue] = useUserSettings<USER_TELEMETRY_ANALYTICS>( PREFERRED_TELEMETRY_USER_SETTING_KEY, @@ -50,7 +51,11 @@ export const useTelemetry = () => { true, ); - const [extensions] = useResolvedExtensions<TelemetryListener>(isTelemetryListener); + const telemetryDisabled = + window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.DISABLED || + (currentUserPreferenceTelemetryValue === USER_TELEMETRY_ANALYTICS.DENY && + (window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.OPTIN || + window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.OPTOUT)); React.useEffect(() => { if ( @@ -74,14 +79,11 @@ export const useTelemetry = () => { // This is required to ensure that the replayed events uses the right path. path: properties?.pathname, }; - if ( - window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.DISABLED || - (currentUserPreferenceTelemetryValue === USER_TELEMETRY_ANALYTICS.DENY && - (window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.OPTIN || - window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.OPTOUT)) - ) { + + if (telemetryDisabled || !allPluginsProcessed) { return; } + if ( !currentUserPreferenceTelemetryValue && window.SERVER_FLAGS.telemetry?.STATE === CLUSTER_TELEMETRY_ANALYTICS.OPTIN @@ -92,8 +94,9 @@ export const useTelemetry = () => { } return; } + extensions.forEach((e) => e.properties.listener(eventType, event)); }, - [extensions, currentUserPreferenceTelemetryValue], + [extensions, currentUserPreferenceTelemetryValue, allPluginsProcessed], ); };
And also update `frontend/packages/console-shared/src/hooks/_tests_/useTelemetry.spec.ts`