Skip to content

Commit

Permalink
feat: display local Atlas dev environments as such COMPASS-7156 (#4875)
Browse files Browse the repository at this point in the history
- Display “AtlasLocalDev” under the “Edition” section of the connection
  info modal. Also display “Atlas” for Atlas now, to be consistent
  with mongosh.
- Report telemetry for local Atlas dev environments.
  • Loading branch information
addaleax authored Sep 20, 2023
1 parent 9db281d commit 1e5ee31
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 23 deletions.
6 changes: 3 additions & 3 deletions packages/compass-collection/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ store.onActivated = (appRegistry: AppRegistry) => {
}
);

instance.on('change:isAtlas', (_model: unknown, value: boolean) => {
store.dispatch(isAtlasChanged(value));
instance.on('change:env', (_model: unknown, value: string) => {
store.dispatch(isAtlasChanged(value === 'atlas'));
});
store.dispatch(isAtlasChanged(instance.isAtlas));
store.dispatch(isAtlasChanged(instance.env === 'atlas'));

instance.dataLake.on(
'change:isDataLake',
Expand Down
86 changes: 84 additions & 2 deletions packages/compass-connections/src/modules/telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const dataService: Pick<DataService, 'instance' | 'getCurrentTopologyType'> = {
version: 'na',
},
isAtlas: false,
isLocalAtlas: false,
featureCompatibilityVersion: null,
});
},
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand All @@ -175,7 +178,7 @@ describe('connection tracking', function () {
});

// eslint-disable-next-line mocha/no-setup-in-describe
[
for (const { url, is_srv, title } of [
{
url: 'mongodb://compass-data-sets-shard-00-00.e06dc.mongodb.net',
is_srv: false,
Expand All @@ -186,7 +189,7 @@ describe('connection tracking', function () {
is_srv: true,
title: 'is atlas, is srv',
},
].forEach(({ url, is_srv, title }) => {
]) {
it(`tracks a new connection event - ${title}`, async function () {
const trackEvent = once(process, 'compass:track');
const connectionInfo = {
Expand All @@ -207,6 +210,7 @@ describe('connection tracking', function () {
is_srv: is_srv,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand All @@ -227,6 +231,75 @@ describe('connection tracking', function () {

expect(properties).to.deep.equal(expected);
});
}

it('tracks a new connection event - atlas local dev', async function () {
const trackEvent = once(process, 'compass:track');

const mockDataService: Pick<
DataService,
'instance' | 'getCurrentTopologyType'
> = {
instance: () => {
return Promise.resolve({
dataLake: {
isDataLake: false,
version: 'na',
},
genuineMongoDB: {
dbType: 'na',
isGenuine: true,
},
host: {},
build: {
isEnterprise: false,
version: 'na',
},
isAtlas: false,
isLocalAtlas: true,
featureCompatibilityVersion: null,
});
},
getCurrentTopologyType: () => 'Unknown',
};

const connectionInfo = {
connectionOptions: {
connectionString: 'mongodb://localhost:27017/',
},
};

trackNewConnectionEvent(connectionInfo, mockDataService);
const [{ properties }] = await trackEvent;

const expected = {
is_localhost: true,
is_public_cloud: false,
is_do_url: false,
is_atlas_url: false,
auth_type: 'NONE',
tunnel: 'none',
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: true,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
non_genuine_server_name: 'na',
server_version: 'na',
server_arch: undefined,
server_os_family: undefined,
is_csfle: false,
has_csfle_schema: false,
has_kms_aws: false,
has_kms_local: false,
has_kms_gcp: false,
has_kms_kmip: false,
has_kms_azure: false,
};

expect(properties).to.deep.equal(expected);
});

it('tracks a new connection event - public cloud', async function () {
Expand All @@ -251,6 +324,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down Expand Up @@ -291,6 +365,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down Expand Up @@ -330,6 +405,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down Expand Up @@ -369,6 +445,7 @@ describe('connection tracking', function () {
is_srv: true,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down Expand Up @@ -484,6 +561,7 @@ describe('connection tracking', function () {
version: '4.3.2',
},
isAtlas: true,
isLocalAtlas: false,
featureCompatibilityVersion: null,
});
},
Expand All @@ -499,6 +577,7 @@ describe('connection tracking', function () {
const [{ properties }] = await trackEvent;

expect(properties.is_atlas).to.equal(true);
expect(properties.is_local_atlas).to.equal(false);
expect(properties.is_dataLake).to.equal(true);
expect(properties.is_enterprise).to.equal(true);
expect(properties.is_genuine).to.equal(false);
Expand Down Expand Up @@ -532,6 +611,7 @@ describe('connection tracking', function () {
version: '4.3.9',
},
isAtlas: false,
isLocalAtlas: false,
featureCompatibilityVersion: null,
});
},
Expand All @@ -547,6 +627,7 @@ describe('connection tracking', function () {
const [{ properties }] = await trackEvent;

expect(properties.is_atlas).to.equal(false);
expect(properties.is_local_atlas).to.equal(false);
expect(properties.is_dataLake).to.equal(false);
expect(properties.is_enterprise).to.equal(false);
expect(properties.is_genuine).to.equal(true);
Expand Down Expand Up @@ -625,6 +706,7 @@ describe('connection tracking', function () {
is_srv: false,
topology_type: 'Unknown',
is_atlas: false,
is_local_atlas: false,
is_dataLake: false,
is_enterprise: false,
is_genuine: true,
Expand Down
12 changes: 4 additions & 8 deletions packages/compass-connections/src/modules/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,13 @@ export function trackNewConnectionEvent(
): void {
try {
const callback = async () => {
const {
dataLake,
genuineMongoDB,
host,
build,
isAtlas: isAtlasInstance,
} = await dataService.instance();
const { dataLake, genuineMongoDB, host, build, isAtlas, isLocalAtlas } =
await dataService.instance();
const connectionData = await getConnectionData(connectionInfo);
const trackEvent = {
...connectionData,
is_atlas: isAtlasInstance,
is_atlas: isAtlas,
is_local_atlas: isLocalAtlas,
is_dataLake: dataLake.isDataLake,
is_enterprise: build.isEnterprise,
is_genuine: genuineMongoDB.isGenuine,
Expand Down
29 changes: 23 additions & 6 deletions packages/compass-sidebar/src/components/connection-info-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { InfoModal, Body, css, spacing } from '@mongodb-js/compass-components';
import { ServerType, TopologyType } from 'mongodb-instance-model';
import type { MongoDBInstance } from 'mongodb-instance-model';
import type { ConnectionOptions } from '../modules/connection-options';
import { ENTERPRISE, COMMUNITY } from '../constants/server-version';

type Collection = {
id: string;
Expand Down Expand Up @@ -83,13 +82,29 @@ export function ConnectionInfoModal({
);
}

function getVersionDistro(isEnterprise?: boolean): string {
function getVersionDistro({
isEnterprise,
isAtlas,
isLocalAtlas,
}: {
isEnterprise?: boolean;
isAtlas?: boolean;
isLocalAtlas?: boolean;
}): string {
if (isAtlas) {
return 'Atlas';
}

if (isLocalAtlas) {
return 'AtlasLocalDev';
}

// it is unknown until instance details are loaded
if (typeof isEnterprise === 'undefined') {
return '';
}

return isEnterprise ? ENTERPRISE : COMMUNITY;
return isEnterprise ? 'Enterprise' : 'Community';
}

type InfoParameters = {
Expand Down Expand Up @@ -192,9 +207,11 @@ function getVersionInfo({ instance }: InfoParameters): ConnectionInfo {
term: 'Edition',
description: instance.dataLake.isDataLake
? `Atlas Data Federation ${instance.dataLake.version ?? ''}`
: `MongoDB ${instance.build.version} ${getVersionDistro(
instance.build.isEnterprise
)}`,
: `MongoDB ${instance.build.version} ${getVersionDistro({
isEnterprise: instance.build.isEnterprise,
isLocalAtlas: instance.isLocalAtlas,
isAtlas: instance.isAtlas,
})}`,
};
}

Expand Down
4 changes: 0 additions & 4 deletions packages/compass-sidebar/src/constants/server-version.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/compass-sidebar/src/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ store.onActivated = (appRegistry) => {
isWritable: instance.isWritable,
env: instance.env,
isAtlas: instance.isAtlas,
isLocalAtlas: instance.isLocalAtlas,
})
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/compass-sidebar/src/stores/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('SidebarStore [Store]', function () {
isGenuine: true,
},
isAtlas: false,
isLocalAtlas: false,
isWritable: false,
refreshingStatus: 'initial',
topologyDescription: {
Expand Down

0 comments on commit 1e5ee31

Please sign in to comment.