Skip to content

Commit 114a080

Browse files
authored
chore(data-service): log maxTimeMS along with find(), aggregate() and estimatedCount(), always set a default maxTimeMS COMPASS-7747 (#5630)
* log maxTimeMS along with find() and aggregate() * make sure we always set a maxTimeMS for estimatedCount * reduce the default maxTimeMS for estimatedCount
1 parent 266bbb6 commit 114a080

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

packages/compass-aggregations/src/modules/input-documents.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,23 @@ export const refreshInputDocuments = (): PipelineBuilderThunkAction<
122122
| undefined,
123123
};
124124

125+
// maxTimeMS defaults to null here because the aggregation options field's
126+
// maxTimeMS defaults to empty and the preference defaults to undefined.
127+
// We need a timeout on count because for timeseries estimatedCount() seems
128+
// to just do a colscan and we need that timeout to be low compared to the
129+
// aggregation one anyway. For aggregations it is less critical because we
130+
// $limit to the first few records.
131+
const countOptions = { ...options, maxTimeMS: 500 };
132+
const aggregateOptions = { ...options };
133+
125134
const exampleDocumentsPipeline = [{ $limit: sampleSize }];
126135

127136
dispatch(loadingInputDocuments());
128137

129138
try {
130139
const data = await Promise.allSettled([
131-
dataService.estimatedCount(ns, options),
132-
dataService.aggregate(ns, exampleDocumentsPipeline, options),
140+
dataService.estimatedCount(ns, countOptions),
141+
dataService.aggregate(ns, exampleDocumentsPipeline, aggregateOptions),
133142
]);
134143

135144
const count = data[0].status === 'fulfilled' ? data[0].value : null;

packages/data-service/src/data-service.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,16 +1497,20 @@ class DataServiceImpl extends WithLogContext implements DataService {
14971497
}
14981498
}
14991499

1500-
@op(mongoLogId(1_001_000_034))
1500+
@op(mongoLogId(1_001_000_034), ([ns, options]) => {
1501+
return { ns, maxTimeMS: options?.maxTimeMS };
1502+
})
15011503
estimatedCount(
15021504
ns: string,
15031505
options: EstimatedDocumentCountOptions = {},
15041506
executionOptions?: ExecutionOptions
15051507
): Promise<number> {
1508+
const maxTimeMS = options.maxTimeMS ?? 500;
15061509
return this._cancellableOperation(
15071510
async (session) => {
15081511
return this._collection(ns, 'CRUD').estimatedDocumentCount({
15091512
...options,
1513+
maxTimeMS,
15101514
session,
15111515
});
15121516
},
@@ -1725,8 +1729,12 @@ class DataServiceImpl extends WithLogContext implements DataService {
17251729

17261730
// @ts-expect-error generic in the method trips up TS here resulting in
17271731
// Promise<unknown> is not assignable to Promise<Document[]>
1728-
@op(mongoLogId(1_001_000_181), ([ns, pipeline]) => {
1729-
return { ns, stages: pipeline.map((stage) => Object.keys(stage)[0]) };
1732+
@op(mongoLogId(1_001_000_181), ([ns, pipeline, options]) => {
1733+
return {
1734+
ns,
1735+
stages: pipeline.map((stage) => Object.keys(stage)[0]),
1736+
maxTimeMS: options?.maxTimeMS,
1737+
};
17301738
})
17311739
aggregate<T = Document>(
17321740
ns: string,
@@ -1750,7 +1758,9 @@ class DataServiceImpl extends WithLogContext implements DataService {
17501758
);
17511759
}
17521760

1753-
@op(mongoLogId(1_001_000_060))
1761+
@op(mongoLogId(1_001_000_060), ([ns, , options]) => {
1762+
return { ns, maxTimeMS: options?.maxTimeMS };
1763+
})
17541764
find(
17551765
ns: string,
17561766
filter: Filter<Document>,

0 commit comments

Comments
 (0)