Skip to content

Commit fecf13e

Browse files
authored
fix(devtools-connect): include DNS resolution time in ConnectDnsResolutionDetail MONGOSH-1998 (#502)
1 parent b628e49 commit fecf13e

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

packages/devtools-connect/src/connect.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ async function resolveMongodbSrv(
170170
error,
171171
duringLoad: true,
172172
resolutionDetails,
173+
durationMs: null,
173174
});
174175
}
175176
if (resolveDnsHelpers !== undefined) {
177+
const dnsResolutionStart = Date.now();
176178
try {
177179
const {
178180
wasNativelyLookedUp,
@@ -181,6 +183,7 @@ async function resolveMongodbSrv(
181183
const resolved = await resolveDnsHelpers.resolve(uri, {
182184
dns: {
183185
resolveSrv(hostname: string, cb: Parameters<typeof resolveSrv>[1]) {
186+
const start = Date.now();
184187
resolveSrv(
185188
hostname,
186189
(...args: Parameters<Parameters<typeof resolveSrv>[1]>) => {
@@ -189,6 +192,7 @@ async function resolveMongodbSrv(
189192
hostname,
190193
error: args[0]?.message,
191194
wasNativelyLookedUp: wasNativelyLookedUp(args[1]),
195+
durationMs: Date.now() - start,
192196
});
193197
cb(...args);
194198
}
@@ -198,11 +202,13 @@ async function resolveMongodbSrv(
198202
resolveTxt(
199203
hostname,
200204
(...args: Parameters<Parameters<typeof resolveTxt>[1]>) => {
205+
const start = Date.now();
201206
resolutionDetails.push({
202207
query: 'TXT',
203208
hostname,
204209
error: args[0]?.message,
205210
wasNativelyLookedUp: wasNativelyLookedUp(args[1]),
211+
durationMs: Date.now() - start,
206212
});
207213
cb(...args);
208214
}
@@ -214,6 +220,7 @@ async function resolveMongodbSrv(
214220
from: uri,
215221
to: resolved,
216222
resolutionDetails,
223+
durationMs: Date.now() - dnsResolutionStart,
217224
});
218225
return resolved;
219226
} catch (error: any) {
@@ -222,6 +229,7 @@ async function resolveMongodbSrv(
222229
error,
223230
duringLoad: false,
224231
resolutionDetails,
232+
durationMs: Date.now() - dnsResolutionStart,
225233
});
226234
throw error;
227235
}

packages/devtools-connect/src/log-hook.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ describe('Logging setup', function () {
5555
hostname: 'hello.world',
5656
error: 'failed',
5757
wasNativelyLookedUp: false,
58+
durationMs: 1,
5859
},
5960
],
61+
durationMs: 2,
6062
});
6163
emitter.emit('devtools-connect:resolve-srv-succeeded', {
6264
from: 'mongodb+srv://foo:[email protected]/',
@@ -67,8 +69,10 @@ describe('Logging setup', function () {
6769
hostname: 'hello.world',
6870
error: undefined,
6971
wasNativelyLookedUp: true,
72+
durationMs: 3,
7073
},
7174
],
75+
durationMs: 4,
7276
});
7377
emitter.emit('devtools-connect:missing-optional-dependency', {
7478
name: 'kerberos',
@@ -169,8 +173,10 @@ describe('Logging setup', function () {
169173
error: 'failed',
170174
hostname: 'hello.world',
171175
wasNativelyLookedUp: false,
176+
durationMs: 1,
172177
},
173178
],
179+
durationMs: 2,
174180
},
175181
},
176182
{
@@ -189,8 +195,10 @@ describe('Logging setup', function () {
189195
error: null,
190196
hostname: 'hello.world',
191197
wasNativelyLookedUp: true,
198+
durationMs: 3,
192199
},
193200
],
201+
durationMs: 4,
194202
},
195203
},
196204
{

packages/devtools-connect/src/log-hook.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export function hookLogger(
120120
error: ev.error?.message,
121121
duringLoad: ev.duringLoad,
122122
resolutionDetails: ev.resolutionDetails,
123+
durationMs: ev.durationMs,
123124
}
124125
);
125126
}
@@ -137,6 +138,7 @@ export function hookLogger(
137138
from: redactURICredentials(ev.from),
138139
to: redactURICredentials(ev.to),
139140
resolutionDetails: ev.resolutionDetails,
141+
durationMs: ev.durationMs,
140142
}
141143
);
142144
}

packages/devtools-connect/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ export interface ConnectDnsResolutionDetail {
3131
hostname: string;
3232
error?: string;
3333
wasNativelyLookedUp?: boolean;
34+
durationMs: number;
3435
}
3536

3637
export interface ConnectResolveSrvErrorEvent {
3738
from: string;
3839
error: Error;
3940
duringLoad: boolean;
4041
resolutionDetails: ConnectDnsResolutionDetail[];
42+
durationMs: number | null;
4143
}
4244

4345
export interface ConnectResolveSrvSucceededEvent {
4446
from: string;
4547
to: string;
4648
resolutionDetails: ConnectDnsResolutionDetail[];
49+
durationMs: number | null;
4750
}
4851

4952
export interface ConnectMissingOptionalDependencyEvent {

0 commit comments

Comments
 (0)