From 05b93d143522a8ecad26e83fd26a6b0e28db9571 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Mon, 29 Jul 2024 13:08:14 +0200 Subject: [PATCH 1/3] feat(compass): report host_id for atlas in Compass COMPASS-8094 --- .../compass/src/app/utils/telemetry.spec.ts | 17 +++++++-- packages/compass/src/app/utils/telemetry.ts | 38 +++++++++++++------ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/packages/compass/src/app/utils/telemetry.spec.ts b/packages/compass/src/app/utils/telemetry.spec.ts index 3d46135a6b8..8e1d8d991a9 100644 --- a/packages/compass/src/app/utils/telemetry.spec.ts +++ b/packages/compass/src/app/utils/telemetry.spec.ts @@ -157,6 +157,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -200,6 +201,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -226,12 +228,12 @@ describe('connection tracking', function () { { url: 'mongodb://compass-data-sets-shard-00-00.e06dc.mongodb.net', is_srv: false, - title: 'is atlas, no srv', + title: 'no srv', }, { url: 'mongodb+srv://compass-data-sets.e06dc.mongodb.net', is_srv: true, - title: 'is atlas, is srv', + title: 'is srv', }, ]) { it(`tracks a new connection event - ${title}`, async function () { @@ -255,6 +257,7 @@ describe('connection tracking', function () { is_srv: is_srv, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -329,6 +332,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: true, is_dataLake: false, is_enterprise: false, @@ -373,6 +377,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -416,6 +421,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -458,6 +464,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -500,6 +507,7 @@ describe('connection tracking', function () { is_srv: true, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -632,13 +640,14 @@ describe('connection tracking', function () { const connection: ConnectionInfo = { ...connectionInfo, connectionOptions: { - connectionString: 'mongodb://127.0.0.1', + connectionString: 'mongodb://test-data-sets-a011bb.test.net', }, }; trackNewConnectionEvent(connection, mockDataService, logger, track); const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(true); + expect(properties.atlas_host_id).to.equal('test-data-sets-a011bb.test.net'); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(true); expect(properties.is_enterprise).to.equal(true); @@ -690,6 +699,7 @@ describe('connection tracking', function () { const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(false); + expect(properties.atlas_host_id).to.equal(null); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(false); expect(properties.is_enterprise).to.equal(false); @@ -772,6 +782,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_host_id: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index c6d1630747d..eb5a86009a4 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -101,8 +101,14 @@ function getCsfleInformation( } async function getHostnameForConnection( - connectionStringData: ConnectionString + connectionInfo: ConnectionInfo ): Promise { + let connectionStringData = new ConnectionString( + connectionInfo.connectionOptions.connectionString, + { + looseValidation: true, + } + ); if (connectionStringData.isSRV) { const uri = await resolveMongodbSrv(connectionStringData.toString()).catch( () => { @@ -120,11 +126,12 @@ async function getHostnameForConnection( return connectionStringData.hosts[0]; } -async function getConnectionData({ - connectionOptions: { connectionString, sshTunnel, fleOptions }, -}: Pick): Promise< - Record -> { +async function getConnectionData( + { + connectionOptions: { connectionString, sshTunnel, fleOptions }, + }: Pick, + resolvedHostname: string | null +): Promise> { const connectionStringData = new ConnectionString(connectionString, { looseValidation: true, }); @@ -139,8 +146,6 @@ async function getConnectionData({ : 'NONE'; const proxyHost = searchParams.get('proxyHost'); - const resolvedHostname = await getHostnameForConnection(connectionStringData); - return { ...(await getHostInformation(resolvedHostname)), auth_type: authType.toUpperCase(), @@ -179,10 +184,15 @@ export function trackNewConnectionEvent( const callback = async () => { const { dataLake, genuineMongoDB, host, build, isAtlas, isLocalAtlas } = await dataService.instance(); - const connectionData = await getConnectionData(connectionInfo); + const resolvedHostname = await getHostnameForConnection(connectionInfo); + const connectionData = await getConnectionData( + connectionInfo, + resolvedHostname + ); const trackEvent = { ...connectionData, is_atlas: isAtlas, + atlas_host_id: isAtlas ? resolvedHostname : null, is_local_atlas: isLocalAtlas, is_dataLake: dataLake.isDataLake, is_enterprise: build.isEnterprise, @@ -209,8 +219,14 @@ export function trackConnectionFailedEvent( ): void { try { const callback = async () => { - const connectionData = - connectionInfo !== null ? await getConnectionData(connectionInfo) : {}; + let connectionData: Record = {}; + if (connectionInfo !== null) { + const resolvedHostname = await getHostnameForConnection(connectionInfo); + connectionData = await getConnectionData( + connectionInfo, + resolvedHostname + ); + } const trackEvent = { ...connectionData, error_code: connectionError.code, From 5f0e071ec71136baf1ca0db9ed0e85678817d3e9 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Mon, 29 Jul 2024 17:08:38 +0200 Subject: [PATCH 2/3] refactor: make mongodb url --- packages/compass/src/app/utils/telemetry.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/compass/src/app/utils/telemetry.spec.ts b/packages/compass/src/app/utils/telemetry.spec.ts index 8e1d8d991a9..193255065d0 100644 --- a/packages/compass/src/app/utils/telemetry.spec.ts +++ b/packages/compass/src/app/utils/telemetry.spec.ts @@ -640,14 +640,16 @@ describe('connection tracking', function () { const connection: ConnectionInfo = { ...connectionInfo, connectionOptions: { - connectionString: 'mongodb://test-data-sets-a011bb.test.net', + connectionString: 'mongodb://test-data-sets-a011bb.mongodb.net', }, }; trackNewConnectionEvent(connection, mockDataService, logger, track); const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(true); - expect(properties.atlas_host_id).to.equal('test-data-sets-a011bb.test.net'); + expect(properties.atlas_host_id).to.equal( + 'test-data-sets-a011bb.mongodb.net' + ); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(true); expect(properties.is_enterprise).to.equal(true); From 50e40e9b4e68aacaf66ad69643086a41d172d572 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Mon, 29 Jul 2024 17:29:48 +0200 Subject: [PATCH 3/3] refactor: rename to atlas_hostname --- .../compass/src/app/utils/telemetry.spec.ts | 22 +++++++++---------- packages/compass/src/app/utils/telemetry.ts | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/compass/src/app/utils/telemetry.spec.ts b/packages/compass/src/app/utils/telemetry.spec.ts index 193255065d0..0b43bf256db 100644 --- a/packages/compass/src/app/utils/telemetry.spec.ts +++ b/packages/compass/src/app/utils/telemetry.spec.ts @@ -157,7 +157,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -201,7 +201,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -257,7 +257,7 @@ describe('connection tracking', function () { is_srv: is_srv, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -332,7 +332,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: true, is_dataLake: false, is_enterprise: false, @@ -377,7 +377,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -421,7 +421,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -464,7 +464,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -507,7 +507,7 @@ describe('connection tracking', function () { is_srv: true, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -647,7 +647,7 @@ describe('connection tracking', function () { const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(true); - expect(properties.atlas_host_id).to.equal( + expect(properties.atlas_hostname).to.equal( 'test-data-sets-a011bb.mongodb.net' ); expect(properties.is_local_atlas).to.equal(false); @@ -701,7 +701,7 @@ describe('connection tracking', function () { const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(false); - expect(properties.atlas_host_id).to.equal(null); + expect(properties.atlas_hostname).to.equal(null); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(false); expect(properties.is_enterprise).to.equal(false); @@ -784,7 +784,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, - atlas_host_id: null, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index eb5a86009a4..62c9aa66b23 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -192,7 +192,7 @@ export function trackNewConnectionEvent( const trackEvent = { ...connectionData, is_atlas: isAtlas, - atlas_host_id: isAtlas ? resolvedHostname : null, + atlas_hostname: isAtlas ? resolvedHostname : null, is_local_atlas: isLocalAtlas, is_dataLake: dataLake.isDataLake, is_enterprise: build.isEnterprise,