diff --git a/frontend/@types/console/index.d.ts b/frontend/@types/console/index.d.ts index 6e157fdf33..63f8e7b151 100644 --- a/frontend/@types/console/index.d.ts +++ b/frontend/@types/console/index.d.ts @@ -59,7 +59,9 @@ declare interface Window { // One of the following should be always available on prod env. SEGMENT_API_KEY: string; SEGMENT_PUBLIC_API_KEY: string; + // DevSandbox-specific configuration DEVSANDBOX_SEGMENT_API_KEY: string; + DEVSANDBOX: 'true' | 'false'; // Optional override for analytics.min.js script URL SEGMENT_JS_URL: string; // Additional telemetry options passed to Console frontend diff --git a/frontend/packages/console-dynamic-plugin-sdk/src/api/segment-analytics.ts b/frontend/packages/console-dynamic-plugin-sdk/src/api/segment-analytics.ts index 49298112c2..179e38f676 100644 --- a/frontend/packages/console-dynamic-plugin-sdk/src/api/segment-analytics.ts +++ b/frontend/packages/console-dynamic-plugin-sdk/src/api/segment-analytics.ts @@ -1,10 +1,12 @@ import { GetSegmentAnalytics } from '../extensions/console-types'; // Segment API key. Must be present for telemetry to be enabled. +// When running in DevSandbox mode, prefer the DevSandbox-specific key. const TELEMETRY_API_KEY = + (window.SERVER_FLAGS.telemetry?.DEVSANDBOX === 'true' && + window.SERVER_FLAGS.telemetry?.DEVSANDBOX_SEGMENT_API_KEY) || window.SERVER_FLAGS.telemetry?.SEGMENT_API_KEY || window.SERVER_FLAGS.telemetry?.SEGMENT_PUBLIC_API_KEY || - window.SERVER_FLAGS.telemetry?.DEVSANDBOX_SEGMENT_API_KEY || ''; // Segment "apiHost" parameter, should be like "api.segment.io/v1" diff --git a/frontend/packages/console-shared/src/hooks/__tests__/useTelemetry.spec.ts b/frontend/packages/console-shared/src/hooks/__tests__/useTelemetry.spec.ts index d8916b714d..f0c0e1c614 100644 --- a/frontend/packages/console-shared/src/hooks/__tests__/useTelemetry.spec.ts +++ b/frontend/packages/console-shared/src/hooks/__tests__/useTelemetry.spec.ts @@ -105,28 +105,28 @@ describe('getClusterProperties', () => { expect(getClusterProperties().clusterType).toBe('TEST'); }); - it('returns DEVSANDBOX when CLUSTER_TYPE is "OSD" but and DEVSANDBOX is "true"', () => { + it('returns DEVSANDBOX when DEVSANDBOX is "true" regardless of CLUSTER_TYPE', () => { window.SERVER_FLAGS = { ...originServerFlags, - telemetry: { CLUSTER_TYPE: 'OSD', DEVSANDBOX: 'true' }, + telemetry: { CLUSTER_TYPE: 'ROSA', DEVSANDBOX: 'true' }, }; expect(getClusterProperties().clusterType).toBe('DEVSANDBOX'); }); - it('returns the clusterType that it is configured if CLUSTER_TYPE is not OSD (in the future) but DEVSANDBOX is still "true"', () => { + it('returns DEVSANDBOX when DEVSANDBOX is "true" even if CLUSTER_TYPE is a different value', () => { window.SERVER_FLAGS = { ...originServerFlags, telemetry: { CLUSTER_TYPE: 'a_FUTURE_DEVSANDBOX_KEY', DEVSANDBOX: 'true' }, }; - expect(getClusterProperties().clusterType).toBe('a_FUTURE_DEVSANDBOX_KEY'); + expect(getClusterProperties().clusterType).toBe('DEVSANDBOX'); }); - it('returns the clusterType that it is configured if CLUSTER_TYPE is OSD but DEVSANDBOX is not exactly "true"', () => { + it('returns the configured clusterType when DEVSANDBOX is not exactly "true"', () => { window.SERVER_FLAGS = { ...originServerFlags, - telemetry: { CLUSTER_TYPE: 'OSD', DEVSANDBOX: 'false' }, + telemetry: { CLUSTER_TYPE: 'ROSA', DEVSANDBOX: 'false' }, }; - expect(getClusterProperties().clusterType).toBe('OSD'); + expect(getClusterProperties().clusterType).toBe('ROSA'); }); }); @@ -207,12 +207,12 @@ describe('useTelemetry', () => { }); }); - it('calls the listener with clusterType DEVSANDBOX when CLUSTER_TYPE is OSD and DEVSANDBOX is "true"', () => { + it('calls the listener with clusterType DEVSANDBOX when DEVSANDBOX is "true"', () => { window.SERVER_FLAGS = { ...originServerFlags, consoleVersion: 'x.y.z', telemetry: { - CLUSTER_TYPE: 'OSD', + CLUSTER_TYPE: 'ROSA', DEVSANDBOX: 'true', STATE: CLUSTER_TELEMETRY_ANALYTICS.ENFORCE, }, diff --git a/frontend/packages/console-shared/src/hooks/useTelemetry.ts b/frontend/packages/console-shared/src/hooks/useTelemetry.ts index dcd7090206..959427fd77 100644 --- a/frontend/packages/console-shared/src/hooks/useTelemetry.ts +++ b/frontend/packages/console-shared/src/hooks/useTelemetry.ts @@ -40,10 +40,7 @@ export const getClusterProperties = () => { const clusterProperties: ClusterProperties = {}; clusterProperties.clusterId = window.SERVER_FLAGS.telemetry?.CLUSTER_ID; clusterProperties.clusterType = window.SERVER_FLAGS.telemetry?.CLUSTER_TYPE; - if ( - window.SERVER_FLAGS.telemetry?.CLUSTER_TYPE === 'OSD' && - window.SERVER_FLAGS.telemetry?.DEVSANDBOX === 'true' - ) { + if (window.SERVER_FLAGS.telemetry?.DEVSANDBOX === 'true') { clusterProperties.clusterType = 'DEVSANDBOX'; } // Prefer to report the OCP version (releaseVersion) if available.