Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report hostname for atlas COMPASS-8093 #2113

Merged
merged 22 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
53162e6
feat: report hostname for atlas COMPASS-8093
alenakhineika Jul 31, 2024
dcffd84
Merge remote-tracking branch 'origin/main' into COMPASS-8093-report-h…
alenakhineika Jul 31, 2024
9104962
fix: do not call on method in worker-thread environment
alenakhineika Jul 31, 2024
585a02e
refactor: dynamically import mongodb-cloud-info
alenakhineika Jul 31, 2024
18d288c
Merge branch 'main' into COMPASS-8093-report-hostname-for-atlas
alenakhineika Aug 1, 2024
6a90556
refactor: read resolved srv from topology
alenakhineika Aug 2, 2024
b18bb84
fix: add getTopology to service provider default functions
alenakhineika Aug 2, 2024
d4c7906
refactor: make s optional
alenakhineika Aug 2, 2024
82994dd
refactor: use uri if cannot resolve host
alenakhineika Aug 2, 2024
3b7f680
refactor: move mongodb-cloud-info
alenakhineika Aug 2, 2024
28e3e91
Merge remote-tracking branch 'origin/main' into COMPASS-8093-report-h…
alenakhineika Aug 9, 2024
86bbdb4
feat: handle IPv6 hostnames
alenakhineika Aug 9, 2024
dda499e
refactor: import mongodb-cloud-info at startup
alenakhineika Aug 9, 2024
e9e6e29
Merge remote-tracking branch 'origin/main' into COMPASS-8093-report-h…
alenakhineika Aug 9, 2024
5395570
refactor: remove mongodb-cloud-info
alenakhineika Aug 12, 2024
3cff763
Merge remote-tracking branch 'origin/main' into COMPASS-8093-report-h…
alenakhineika Aug 12, 2024
a425e88
refactor: listen on topologyDescriptionChanged
alenakhineika Aug 13, 2024
2af513f
Merge remote-tracking branch 'origin/main' into COMPASS-8093-report-h…
alenakhineika Aug 13, 2024
e3b6c79
refactor: move getHostnameForConnection to service-provider-server
alenakhineika Aug 13, 2024
b0f86fd
refactor: clean up
alenakhineika Aug 13, 2024
193de2e
fix: connectionInfo can be undefined
alenakhineika Aug 13, 2024
ca3dd1e
chore: add dependency
alenakhineika Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/browser-repl/src/sandbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class DemoServiceProvider {
extraInfo: {
uri: 'mongodb://localhost/',
},
topology: null,
};
}

Expand Down
3 changes: 0 additions & 3 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ describe('MongoshNodeRepl', function () {
buildInfo: {
version: '4.4.1',
},
topology: null,
});
sp.runCommandWithCheck.resolves({ ok: 1 });
serviceProvider = sp;
Expand Down Expand Up @@ -1259,7 +1258,6 @@ describe('MongoshNodeRepl', function () {
version: '4.4.1',
modules: ['enterprise'],
},
topology: null,
});

const initialized = await mongoshRepl.initialize(serviceProvider);
Expand Down Expand Up @@ -1421,7 +1419,6 @@ describe('MongoshNodeRepl', function () {
buildInfo: {
version: '4.4.1',
},
topology: null,
});
mongoshReplOptions.shellCliOptions = {
nodb: false,
Expand Down
126 changes: 99 additions & 27 deletions packages/logging/src/setup-logger-and-telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('setupLoggerAndTelemetry', function () {
bus = new EventEmitter();
});

it('works', function () {
it('tracks new local connection events', function () {
setupLoggerAndTelemetry(
bus,
logger,
Expand All @@ -78,14 +78,108 @@ describe('setupLoggerAndTelemetry', function () {
expect(logOutput).to.have.lengthOf(0);
expect(analyticsOutput).to.be.empty;

bus.emit('mongosh:new-user', { userId, anonymousId: userId });
bus.emit('mongosh:update-user', { userId, anonymousId: userId });
bus.emit('mongosh:connect', {
uri: 'mongodb://localhost/',
is_localhost: true,
is_atlas: false,
resolved_hostname: 'localhost',
node_version: 'v12.19.0',
});

expect(logOutput[0].msg).to.equal('Connecting to server');
expect(logOutput[0].attr.connectionUri).to.equal('mongodb://localhost/');
expect(logOutput[0].attr.is_localhost).to.equal(true);
expect(logOutput[0].attr.is_atlas).to.equal(false);
expect(logOutput[0].attr.atlas_hostname).to.equal(null);
expect(logOutput[0].attr.node_version).to.equal('v12.19.0');

expect(analyticsOutput).to.deep.equal([
[
'track',
{
anonymousId: undefined,
event: 'New Connection',
properties: {
mongosh_version: '1.0.0',
session_id: '5fb3c20ee1507e894e5340f3',
is_localhost: true,
is_atlas: false,
atlas_hostname: null,
node_version: 'v12.19.0',
},
},
],
]);
});

it('tracks new atlas connection events', function () {
setupLoggerAndTelemetry(
bus,
logger,
analytics,
{
platform: process.platform,
arch: process.arch,
},
'1.0.0'
);
expect(logOutput).to.have.lengthOf(0);
expect(analyticsOutput).to.be.empty;

bus.emit('mongosh:connect', {
uri: 'mongodb://test-data-sets-a011bb.mongodb.net/',
is_localhost: false,
is_atlas: true,
resolved_hostname: 'test-data-sets-00-02-a011bb.mongodb.net',
node_version: 'v12.19.0',
} as any);
});

expect(logOutput[0].msg).to.equal('Connecting to server');
expect(logOutput[0].attr.connectionUri).to.equal(
'mongodb://test-data-sets-a011bb.mongodb.net/'
);
expect(logOutput[0].attr.is_localhost).to.equal(false);
expect(logOutput[0].attr.is_atlas).to.equal(true);
expect(logOutput[0].attr.atlas_hostname).to.equal(
'test-data-sets-00-02-a011bb.mongodb.net'
);
expect(logOutput[0].attr.node_version).to.equal('v12.19.0');

expect(analyticsOutput).to.deep.equal([
[
'track',
{
anonymousId: undefined,
event: 'New Connection',
properties: {
mongosh_version: '1.0.0',
session_id: '5fb3c20ee1507e894e5340f3',
is_localhost: false,
is_atlas: true,
atlas_hostname: 'test-data-sets-00-02-a011bb.mongodb.net',
node_version: 'v12.19.0',
},
},
],
]);
});

it('tracks a sequence of events', function () {
setupLoggerAndTelemetry(
bus,
logger,
analytics,
{
platform: process.platform,
arch: process.arch,
},
'1.0.0'
);
expect(logOutput).to.have.lengthOf(0);
expect(analyticsOutput).to.be.empty;

bus.emit('mongosh:new-user', { userId, anonymousId: userId });
bus.emit('mongosh:update-user', { userId, anonymousId: userId });
bus.emit('mongosh:start-session', {
isInteractive: true,
jsContext: 'foo',
Expand Down Expand Up @@ -230,16 +324,8 @@ describe('setupLoggerAndTelemetry', function () {
});

let i = 0;

expect(logOutput[i++].msg).to.equal('User updated');
expect(logOutput[i].msg).to.equal('Connecting to server');
expect(logOutput[i].attr.session_id).to.equal('5fb3c20ee1507e894e5340f3');
expect(logOutput[i].attr.telemetryAnonymousId).to.equal(
'53defe995fa47e6c13102d9d'
);
expect(logOutput[i].attr.connectionUri).to.equal('mongodb://localhost/');
expect(logOutput[i].attr.is_localhost).to.equal(true);
expect(logOutput[i].attr.is_atlas).to.equal(false);
expect(logOutput[i++].attr.node_version).to.equal('v12.19.0');
expect(logOutput[i].s).to.equal('E');
expect(logOutput[i++].attr.message).to.match(/meow/);
expect(logOutput[i].s).to.equal('F');
Expand Down Expand Up @@ -401,20 +487,6 @@ describe('setupLoggerAndTelemetry', function () {
},
},
],
[
'track',
{
anonymousId: '53defe995fa47e6c13102d9d',
event: 'New Connection',
properties: {
mongosh_version: '1.0.0',
session_id: '5fb3c20ee1507e894e5340f3',
is_localhost: true,
is_atlas: false,
node_version: 'v12.19.0',
},
},
],
[
'track',
{
Expand Down
31 changes: 17 additions & 14 deletions packages/logging/src/setup-logger-and-telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,34 @@ export function setupLoggerAndTelemetry(
);

bus.on('mongosh:connect', function (args: ConnectEvent) {
const connectionUri = args.uri && redactURICredentials(args.uri);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { uri: _uri, ...argsWithoutUri } = args;
const params = {
session_id,
userId,
telemetryAnonymousId,
connectionUri,
...argsWithoutUri,
const { uri, resolved_hostname, ...argsWithoutUriAndHostname } = args;
const connectionUri = uri && redactURICredentials(uri);
const atlasHostname = {
atlas_hostname: args.is_atlas ? resolved_hostname : null,
};
const properties = {
...trackProperties,
...argsWithoutUriAndHostname,
...atlasHostname,
};

log.info(
'MONGOSH',
mongoLogId(1_000_000_004),
'connect',
'Connecting to server',
params
{
userId,
telemetryAnonymousId,
connectionUri,
...properties,
}
);

analytics.track({
...getTelemetryUserIdentity(),
event: 'New Connection',
properties: {
...trackProperties,
...argsWithoutUri,
},
properties,
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/service-provider-core/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface CheckMetadataConsistencyOptions {

export interface ConnectionInfo {
buildInfo: Document | null;
topology: any | null;
resolvedHostname?: string;
extraInfo: (ConnectionExtraInfo & { fcv?: string }) | null;
}

Expand Down
Loading
Loading