@@ -11,16 +11,11 @@ import { EventEmitter } from 'events';
11
11
import { StorageController , StorageVariables } from './storage' ;
12
12
import { SavedConnection , StorageScope } from './storage/storageController' ;
13
13
import { getNodeModule } from './utils/getNodeModule' ;
14
- import TelemetryController , {
15
- TelemetryEventTypes
16
- } from './telemetry/telemetryController' ;
17
- import { getCloudInfo } from 'mongodb-cloud-info' ;
14
+ import TelemetryController from './telemetry/telemetryController' ;
18
15
19
16
const { name, version } = require ( '../package.json' ) ;
20
17
const log = createLogger ( 'connection controller' ) ;
21
18
const MAX_CONNECTION_NAME_LENGTH = 512 ;
22
- const ATLAS_REGEX = / m o n g o d b .n e t [: / ] / i;
23
- const LOCALHOST_REGEX = / ( l o c a l h o s t | 1 2 7 \. 0 \. 0 \. 1 ) / i;
24
19
25
20
type KeyTar = typeof keytarType ;
26
21
@@ -245,6 +240,17 @@ export default class ConnectionController {
245
240
} ) ;
246
241
} ;
247
242
243
+ public sendTelemetry (
244
+ newDataService : DataServiceType ,
245
+ connectionType : ConnectionTypes
246
+ ) {
247
+ // Send metrics to Segment
248
+ this . _telemetryController . trackNewConnection (
249
+ newDataService ,
250
+ connectionType
251
+ ) ;
252
+ }
253
+
248
254
public parseNewConnectionAndConnect = (
249
255
newConnectionModel : ConnectionModelType
250
256
) : Promise < boolean > => {
@@ -309,82 +315,13 @@ export default class ConnectionController {
309
315
return resolve ( false ) ;
310
316
}
311
317
312
- resolve ( true ) ;
318
+ return resolve ( true ) ;
313
319
} ,
314
320
reject
315
321
) ;
316
322
} ) ;
317
323
} ;
318
324
319
- public async getCloudInfoFromDataService ( firstServerHostname : string ) {
320
- const cloudInfo = await getCloudInfo ( firstServerHostname ) ;
321
- let isPublicCloud = false ;
322
- let publicCloudName : string | null = null ;
323
-
324
- if ( cloudInfo . isAws ) {
325
- isPublicCloud = true ;
326
- publicCloudName = 'aws' ;
327
- } else if ( cloudInfo . isGcp ) {
328
- isPublicCloud = true ;
329
- publicCloudName = 'gcp' ;
330
- } else if ( cloudInfo . isAzure ) {
331
- isPublicCloud = true ;
332
- publicCloudName = 'azure' ;
333
- }
334
-
335
- return { isPublicCloud, publicCloudName } ;
336
- }
337
-
338
- private async sendTelemetry (
339
- dataService : DataServiceType ,
340
- connectionType : ConnectionTypes
341
- ) : Promise < void > {
342
- dataService . instance ( { } , async ( error : any , data : any ) => {
343
- if ( error ) {
344
- log . error ( 'TELEMETRY data service error' , error ) ;
345
- }
346
-
347
- if ( data ) {
348
- try {
349
- const firstServerHostname = dataService . client . model . hosts [ 0 ] . host ;
350
- const cloudInfo = await this . getCloudInfoFromDataService (
351
- firstServerHostname
352
- ) ;
353
- const nonGenuineServerName = data . genuineMongoDB . isGenuine
354
- ? null
355
- : data . genuineMongoDB . dbType ;
356
- const telemetryData = {
357
- is_atlas : ! ! data . client . s . url . match ( ATLAS_REGEX ) ,
358
- is_localhost : ! ! data . client . s . url . match ( LOCALHOST_REGEX ) ,
359
- is_data_lake : data . dataLake . isDataLake ,
360
- is_enterprise : data . build . enterprise_module ,
361
- is_public_cloud : cloudInfo . isPublicCloud ,
362
- public_cloud_name : cloudInfo . publicCloudName ,
363
- is_genuine : data . genuineMongoDB . isGenuine ,
364
- non_genuine_server_name : nonGenuineServerName ,
365
- server_version : data . build . version ,
366
- server_arch : data . build . raw . buildEnvironment . target_arch ,
367
- server_os : data . build . raw . buildEnvironment . target_os ,
368
- is_used_connect_screen :
369
- connectionType === ConnectionTypes . CONNECTION_FORM ,
370
- is_used_command_palette :
371
- connectionType === ConnectionTypes . CONNECTION_STRING ,
372
- is_used_saved_connection :
373
- connectionType === ConnectionTypes . CONNECTION_ID
374
- } ;
375
-
376
- // Send metrics to Segment
377
- this . _telemetryController . track (
378
- TelemetryEventTypes . NEW_CONNECTION ,
379
- telemetryData
380
- ) ;
381
- } catch ( error ) {
382
- log . error ( 'TELEMETRY cloud info error' , error ) ;
383
- }
384
- }
385
- } ) ;
386
- }
387
-
388
325
public connect = async (
389
326
connectionId : string ,
390
327
connectionModel : ConnectionModelType ,
@@ -449,9 +386,8 @@ export default class ConnectionController {
449
386
this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
450
387
this . eventEmitter . emit ( DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ) ;
451
388
452
- if ( this . _telemetryController . needTelemetry ( ) ) {
453
- this . sendTelemetry ( newDataService , connectionType ) ;
454
- }
389
+ // Send metrics to Segment
390
+ this . sendTelemetry ( newDataService , connectionType ) ;
455
391
456
392
return resolve ( true ) ;
457
393
} ) ;
@@ -659,13 +595,13 @@ export default class ConnectionController {
659
595
const connectionNameToRemove :
660
596
| string
661
597
| undefined = await vscode . window . showQuickPick (
662
- connectionIds . map (
663
- ( id , index ) => `${ index + 1 } : ${ this . _connections [ id ] . name } `
664
- ) ,
665
- {
666
- placeHolder : 'Choose a connection to remove...'
667
- }
668
- ) ;
598
+ connectionIds . map (
599
+ ( id , index ) => `${ index + 1 } : ${ this . _connections [ id ] . name } `
600
+ ) ,
601
+ {
602
+ placeHolder : 'Choose a connection to remove...'
603
+ }
604
+ ) ;
669
605
670
606
if ( ! connectionNameToRemove ) {
671
607
return Promise . resolve ( false ) ;
0 commit comments