Skip to content

Commit 14d1aa3

Browse files
authored
chore(data-service): disable utf8 validation when retrieving metadata compass needs in order to function COMPASS-8517 (#6531)
* disable utf8 validation when retrieving metadata compass needs in order to function * { enableUtf8Validation: false } on each runCommand rather so we can argue about them one by one
1 parent ccdfa90 commit 14d1aa3

File tree

2 files changed

+98
-59
lines changed

2 files changed

+98
-59
lines changed

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

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,49 +1083,52 @@ class DataServiceImpl extends WithLogContext implements DataService {
10831083
try {
10841084
const coll = this._collection(ns, 'CRUD');
10851085
const collStats = await coll
1086-
.aggregate([
1087-
{ $collStats: { storageStats: {} } },
1088-
{
1089-
$group: {
1090-
_id: null,
1091-
capped: { $first: '$storageStats.capped' },
1092-
count: { $sum: '$storageStats.count' },
1093-
size: { $sum: { $toDouble: '$storageStats.size' } },
1094-
storageSize: {
1095-
$sum: { $toDouble: '$storageStats.storageSize' },
1096-
},
1097-
totalIndexSize: {
1098-
$sum: { $toDouble: '$storageStats.totalIndexSize' },
1099-
},
1100-
freeStorageSize: {
1101-
$sum: { $toDouble: '$storageStats.freeStorageSize' },
1102-
},
1103-
unscaledCollSize: {
1104-
$sum: {
1105-
$multiply: [
1106-
{ $toDouble: '$storageStats.avgObjSize' },
1107-
{ $toDouble: '$storageStats.count' },
1108-
],
1086+
.aggregate(
1087+
[
1088+
{ $collStats: { storageStats: {} } },
1089+
{
1090+
$group: {
1091+
_id: null,
1092+
capped: { $first: '$storageStats.capped' },
1093+
count: { $sum: '$storageStats.count' },
1094+
size: { $sum: { $toDouble: '$storageStats.size' } },
1095+
storageSize: {
1096+
$sum: { $toDouble: '$storageStats.storageSize' },
11091097
},
1098+
totalIndexSize: {
1099+
$sum: { $toDouble: '$storageStats.totalIndexSize' },
1100+
},
1101+
freeStorageSize: {
1102+
$sum: { $toDouble: '$storageStats.freeStorageSize' },
1103+
},
1104+
unscaledCollSize: {
1105+
$sum: {
1106+
$multiply: [
1107+
{ $toDouble: '$storageStats.avgObjSize' },
1108+
{ $toDouble: '$storageStats.count' },
1109+
],
1110+
},
1111+
},
1112+
nindexes: { $max: '$storageStats.nindexes' },
11101113
},
1111-
nindexes: { $max: '$storageStats.nindexes' },
11121114
},
1113-
},
1114-
{
1115-
$addFields: {
1116-
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
1117-
avgObjSize: {
1118-
$cond: {
1119-
if: { $ne: ['$count', 0] },
1120-
then: {
1121-
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
1115+
{
1116+
$addFields: {
1117+
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
1118+
avgObjSize: {
1119+
$cond: {
1120+
if: { $ne: ['$count', 0] },
1121+
then: {
1122+
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
1123+
},
1124+
else: 0,
11221125
},
1123-
else: 0,
11241126
},
11251127
},
11261128
},
1127-
},
1128-
])
1129+
],
1130+
{ enableUtf8Validation: false }
1131+
)
11291132
.toArray();
11301133

11311134
if (!collStats || collStats[0] === undefined) {
@@ -1165,7 +1168,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
11651168
@op(mongoLogId(1_001_000_031))
11661169
async killOp(id: number, comment?: string): Promise<Document> {
11671170
const db = this._database('admin', 'META');
1168-
return runCommand(db, { killOp: 1, id, comment });
1171+
return runCommand(
1172+
db,
1173+
{ killOp: 1, id, comment },
1174+
{ enableUtf8Validation: false }
1175+
);
11691176
}
11701177

11711178
isWritable(): boolean {
@@ -1183,10 +1190,14 @@ class DataServiceImpl extends WithLogContext implements DataService {
11831190
@op(mongoLogId(1_001_000_100))
11841191
private async _connectionStatus(): Promise<ConnectionStatusWithPrivileges> {
11851192
const adminDb = this._database('admin', 'META');
1186-
return await runCommand(adminDb, {
1187-
connectionStatus: 1,
1188-
showPrivileges: true,
1189-
});
1193+
return await runCommand(
1194+
adminDb,
1195+
{
1196+
connectionStatus: 1,
1197+
showPrivileges: true,
1198+
},
1199+
{ enableUtf8Validation: false }
1200+
);
11901201
}
11911202

11921203
private async _getPrivilegesOrFallback(
@@ -1341,12 +1352,16 @@ class DataServiceImpl extends WithLogContext implements DataService {
13411352

13421353
const listDatabases = async () => {
13431354
try {
1344-
const { databases } = await runCommand(adminDb, {
1345-
listDatabases: 1,
1346-
nameOnly,
1347-
} as {
1348-
listDatabases: 1;
1349-
});
1355+
const { databases } = await runCommand(
1356+
adminDb,
1357+
{
1358+
listDatabases: 1,
1359+
nameOnly,
1360+
} as {
1361+
listDatabases: 1;
1362+
},
1363+
{ enableUtf8Validation: false }
1364+
);
13501365
return databases;
13511366
} catch (err) {
13521367
// Currently Compass should not fail if listDatabase failed for any
@@ -2112,15 +2127,23 @@ class DataServiceImpl extends WithLogContext implements DataService {
21122127
})
21132128
async serverStatus(): Promise<Document> {
21142129
const admin = this._database('admin', 'META');
2115-
return await runCommand(admin, { serverStatus: 1 });
2130+
return await runCommand(
2131+
admin,
2132+
{ serverStatus: 1 },
2133+
{ enableUtf8Validation: false }
2134+
);
21162135
}
21172136

21182137
@op(mongoLogId(1_001_000_062), (_, result) => {
21192138
return result ? { result } : undefined;
21202139
})
21212140
async top(): Promise<{ totals: Record<string, unknown> }> {
21222141
const adminDb = this._database('admin', 'META');
2123-
return await runCommand(adminDb, { top: 1 });
2142+
return await runCommand(
2143+
adminDb,
2144+
{ top: 1 },
2145+
{ enableUtf8Validation: false }
2146+
);
21242147
}
21252148

21262149
@op(
@@ -2457,7 +2480,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
24572480
name: string
24582481
): Promise<ReturnType<typeof adaptDatabaseInfo> & { name: string }> {
24592482
const db = this._database(name, 'META');
2460-
const stats = await runCommand(db, { dbStats: 1 });
2483+
const stats = await runCommand(
2484+
db,
2485+
{ dbStats: 1 },
2486+
{ enableUtf8Validation: false }
2487+
);
24612488
const normalized = adaptDatabaseInfo(stats);
24622489
return { name, ...normalized };
24632490
}

packages/data-service/src/instance-detail-helper.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,34 @@ export async function getInstance(
121121
atlasVersionResult,
122122
isLocalAtlas,
123123
] = await Promise.all([
124-
runCommand(adminDb, { connectionStatus: 1, showPrivileges: true }).catch(
125-
ignoreNotAuthorized(null)
124+
runCommand(
125+
adminDb,
126+
{ connectionStatus: 1, showPrivileges: true },
127+
{ enableUtf8Validation: false }
128+
).catch(ignoreNotAuthorized(null)),
129+
runCommand(adminDb, { hostInfo: 1 }, { enableUtf8Validation: false }).catch(
130+
ignoreNotAuthorized({})
126131
),
127-
runCommand(adminDb, { hostInfo: 1 }).catch(ignoreNotAuthorized({})),
128132
// This command should always pass, if it throws, somethings is really off.
129133
// This is why it's the only one where we are not ignoring any types of
130134
// errors
131-
runCommand(adminDb, { buildInfo: 1 }),
135+
runCommand(adminDb, { buildInfo: 1 }, { enableUtf8Validation: false }),
132136
// This command is only here to get data for the logs and telemetry, if it
133137
// failed (e.g., not authorised or not supported) we should just ignore the
134138
// failure
135-
runCommand<{ featureCompatibilityVersion: { version: string } }>(adminDb, {
136-
getParameter: 1,
137-
featureCompatibilityVersion: 1,
138-
}).catch(() => null),
139-
runCommand(adminDb, { atlasVersion: 1 }).catch(() => {
139+
runCommand<{ featureCompatibilityVersion: { version: string } }>(
140+
adminDb,
141+
{
142+
getParameter: 1,
143+
featureCompatibilityVersion: 1,
144+
},
145+
{ enableUtf8Validation: false }
146+
).catch(() => null),
147+
runCommand(
148+
adminDb,
149+
{ atlasVersion: 1 },
150+
{ enableUtf8Validation: false }
151+
).catch(() => {
140152
return { atlasVersion: '', gitVersion: '' };
141153
}),
142154
checkIsLocalAtlas(

0 commit comments

Comments
 (0)