Skip to content

Commit ed2a43e

Browse files
feat(compass): report hostname for atlas COMPASS-8094 (#6067)
* feat(compass): report hostname for atlas in Compass COMPASS-8094
1 parent afbe04f commit ed2a43e

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

packages/compass/src/app/utils/telemetry.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ describe('connection tracking', function () {
157157
is_srv: false,
158158
topology_type: 'Unknown',
159159
is_atlas: false,
160+
atlas_hostname: null,
160161
is_local_atlas: false,
161162
is_dataLake: false,
162163
is_enterprise: false,
@@ -200,6 +201,7 @@ describe('connection tracking', function () {
200201
is_srv: false,
201202
topology_type: 'Unknown',
202203
is_atlas: false,
204+
atlas_hostname: null,
203205
is_local_atlas: false,
204206
is_dataLake: false,
205207
is_enterprise: false,
@@ -226,12 +228,12 @@ describe('connection tracking', function () {
226228
{
227229
url: 'mongodb://compass-data-sets-shard-00-00.e06dc.mongodb.net',
228230
is_srv: false,
229-
title: 'is atlas, no srv',
231+
title: 'no srv',
230232
},
231233
{
232234
url: 'mongodb+srv://compass-data-sets.e06dc.mongodb.net',
233235
is_srv: true,
234-
title: 'is atlas, is srv',
236+
title: 'is srv',
235237
},
236238
]) {
237239
it(`tracks a new connection event - ${title}`, async function () {
@@ -255,6 +257,7 @@ describe('connection tracking', function () {
255257
is_srv: is_srv,
256258
topology_type: 'Unknown',
257259
is_atlas: false,
260+
atlas_hostname: null,
258261
is_local_atlas: false,
259262
is_dataLake: false,
260263
is_enterprise: false,
@@ -329,6 +332,7 @@ describe('connection tracking', function () {
329332
is_srv: false,
330333
topology_type: 'Unknown',
331334
is_atlas: false,
335+
atlas_hostname: null,
332336
is_local_atlas: true,
333337
is_dataLake: false,
334338
is_enterprise: false,
@@ -373,6 +377,7 @@ describe('connection tracking', function () {
373377
is_srv: false,
374378
topology_type: 'Unknown',
375379
is_atlas: false,
380+
atlas_hostname: null,
376381
is_local_atlas: false,
377382
is_dataLake: false,
378383
is_enterprise: false,
@@ -416,6 +421,7 @@ describe('connection tracking', function () {
416421
is_srv: false,
417422
topology_type: 'Unknown',
418423
is_atlas: false,
424+
atlas_hostname: null,
419425
is_local_atlas: false,
420426
is_dataLake: false,
421427
is_enterprise: false,
@@ -458,6 +464,7 @@ describe('connection tracking', function () {
458464
is_srv: false,
459465
topology_type: 'Unknown',
460466
is_atlas: false,
467+
atlas_hostname: null,
461468
is_local_atlas: false,
462469
is_dataLake: false,
463470
is_enterprise: false,
@@ -500,6 +507,7 @@ describe('connection tracking', function () {
500507
is_srv: true,
501508
topology_type: 'Unknown',
502509
is_atlas: false,
510+
atlas_hostname: null,
503511
is_local_atlas: false,
504512
is_dataLake: false,
505513
is_enterprise: false,
@@ -632,13 +640,16 @@ describe('connection tracking', function () {
632640
const connection: ConnectionInfo = {
633641
...connectionInfo,
634642
connectionOptions: {
635-
connectionString: 'mongodb://127.0.0.1',
643+
connectionString: 'mongodb://test-data-sets-a011bb.mongodb.net',
636644
},
637645
};
638646
trackNewConnectionEvent(connection, mockDataService, logger, track);
639647
const [{ properties }] = await trackEvent;
640648

641649
expect(properties.is_atlas).to.equal(true);
650+
expect(properties.atlas_hostname).to.equal(
651+
'test-data-sets-a011bb.mongodb.net'
652+
);
642653
expect(properties.is_local_atlas).to.equal(false);
643654
expect(properties.is_dataLake).to.equal(true);
644655
expect(properties.is_enterprise).to.equal(true);
@@ -690,6 +701,7 @@ describe('connection tracking', function () {
690701
const [{ properties }] = await trackEvent;
691702

692703
expect(properties.is_atlas).to.equal(false);
704+
expect(properties.atlas_hostname).to.equal(null);
693705
expect(properties.is_local_atlas).to.equal(false);
694706
expect(properties.is_dataLake).to.equal(false);
695707
expect(properties.is_enterprise).to.equal(false);
@@ -772,6 +784,7 @@ describe('connection tracking', function () {
772784
is_srv: false,
773785
topology_type: 'Unknown',
774786
is_atlas: false,
787+
atlas_hostname: null,
775788
is_local_atlas: false,
776789
is_dataLake: false,
777790
is_enterprise: false,

packages/compass/src/app/utils/telemetry.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ function getCsfleInformation(
101101
}
102102

103103
async function getHostnameForConnection(
104-
connectionStringData: ConnectionString
104+
connectionInfo: ConnectionInfo
105105
): Promise<string | null> {
106+
let connectionStringData = new ConnectionString(
107+
connectionInfo.connectionOptions.connectionString,
108+
{
109+
looseValidation: true,
110+
}
111+
);
106112
if (connectionStringData.isSRV) {
107113
const uri = await resolveMongodbSrv(connectionStringData.toString()).catch(
108114
() => {
@@ -120,11 +126,12 @@ async function getHostnameForConnection(
120126
return connectionStringData.hosts[0];
121127
}
122128

123-
async function getConnectionData({
124-
connectionOptions: { connectionString, sshTunnel, fleOptions },
125-
}: Pick<ConnectionInfo, 'connectionOptions'>): Promise<
126-
Record<string, unknown>
127-
> {
129+
async function getConnectionData(
130+
{
131+
connectionOptions: { connectionString, sshTunnel, fleOptions },
132+
}: Pick<ConnectionInfo, 'connectionOptions'>,
133+
resolvedHostname: string | null
134+
): Promise<Record<string, unknown>> {
128135
const connectionStringData = new ConnectionString(connectionString, {
129136
looseValidation: true,
130137
});
@@ -139,8 +146,6 @@ async function getConnectionData({
139146
: 'NONE';
140147
const proxyHost = searchParams.get('proxyHost');
141148

142-
const resolvedHostname = await getHostnameForConnection(connectionStringData);
143-
144149
return {
145150
...(await getHostInformation(resolvedHostname)),
146151
auth_type: authType.toUpperCase(),
@@ -179,10 +184,15 @@ export function trackNewConnectionEvent(
179184
const callback = async () => {
180185
const { dataLake, genuineMongoDB, host, build, isAtlas, isLocalAtlas } =
181186
await dataService.instance();
182-
const connectionData = await getConnectionData(connectionInfo);
187+
const resolvedHostname = await getHostnameForConnection(connectionInfo);
188+
const connectionData = await getConnectionData(
189+
connectionInfo,
190+
resolvedHostname
191+
);
183192
const trackEvent = {
184193
...connectionData,
185194
is_atlas: isAtlas,
195+
atlas_hostname: isAtlas ? resolvedHostname : null,
186196
is_local_atlas: isLocalAtlas,
187197
is_dataLake: dataLake.isDataLake,
188198
is_enterprise: build.isEnterprise,
@@ -209,8 +219,14 @@ export function trackConnectionFailedEvent(
209219
): void {
210220
try {
211221
const callback = async () => {
212-
const connectionData =
213-
connectionInfo !== null ? await getConnectionData(connectionInfo) : {};
222+
let connectionData: Record<string, unknown> = {};
223+
if (connectionInfo !== null) {
224+
const resolvedHostname = await getHostnameForConnection(connectionInfo);
225+
connectionData = await getConnectionData(
226+
connectionInfo,
227+
resolvedHostname
228+
);
229+
}
214230
const trackEvent = {
215231
...connectionData,
216232
error_code: connectionError.code,

0 commit comments

Comments
 (0)