Skip to content

Commit

Permalink
chore(data-service): disable utf8 validation when retrieving metadata…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
lerouxb authored Nov 27, 2024
1 parent ccdfa90 commit 14d1aa3
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 59 deletions.
127 changes: 77 additions & 50 deletions packages/data-service/src/data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,49 +1083,52 @@ class DataServiceImpl extends WithLogContext implements DataService {
try {
const coll = this._collection(ns, 'CRUD');
const collStats = await coll
.aggregate([
{ $collStats: { storageStats: {} } },
{
$group: {
_id: null,
capped: { $first: '$storageStats.capped' },
count: { $sum: '$storageStats.count' },
size: { $sum: { $toDouble: '$storageStats.size' } },
storageSize: {
$sum: { $toDouble: '$storageStats.storageSize' },
},
totalIndexSize: {
$sum: { $toDouble: '$storageStats.totalIndexSize' },
},
freeStorageSize: {
$sum: { $toDouble: '$storageStats.freeStorageSize' },
},
unscaledCollSize: {
$sum: {
$multiply: [
{ $toDouble: '$storageStats.avgObjSize' },
{ $toDouble: '$storageStats.count' },
],
.aggregate(
[
{ $collStats: { storageStats: {} } },
{
$group: {
_id: null,
capped: { $first: '$storageStats.capped' },
count: { $sum: '$storageStats.count' },
size: { $sum: { $toDouble: '$storageStats.size' } },
storageSize: {
$sum: { $toDouble: '$storageStats.storageSize' },
},
totalIndexSize: {
$sum: { $toDouble: '$storageStats.totalIndexSize' },
},
freeStorageSize: {
$sum: { $toDouble: '$storageStats.freeStorageSize' },
},
unscaledCollSize: {
$sum: {
$multiply: [
{ $toDouble: '$storageStats.avgObjSize' },
{ $toDouble: '$storageStats.count' },
],
},
},
nindexes: { $max: '$storageStats.nindexes' },
},
nindexes: { $max: '$storageStats.nindexes' },
},
},
{
$addFields: {
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
avgObjSize: {
$cond: {
if: { $ne: ['$count', 0] },
then: {
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
{
$addFields: {
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
avgObjSize: {
$cond: {
if: { $ne: ['$count', 0] },
then: {
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
},
else: 0,
},
else: 0,
},
},
},
},
])
],
{ enableUtf8Validation: false }
)
.toArray();

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

isWritable(): boolean {
Expand All @@ -1183,10 +1190,14 @@ class DataServiceImpl extends WithLogContext implements DataService {
@op(mongoLogId(1_001_000_100))
private async _connectionStatus(): Promise<ConnectionStatusWithPrivileges> {
const adminDb = this._database('admin', 'META');
return await runCommand(adminDb, {
connectionStatus: 1,
showPrivileges: true,
});
return await runCommand(
adminDb,
{
connectionStatus: 1,
showPrivileges: true,
},
{ enableUtf8Validation: false }
);
}

private async _getPrivilegesOrFallback(
Expand Down Expand Up @@ -1341,12 +1352,16 @@ class DataServiceImpl extends WithLogContext implements DataService {

const listDatabases = async () => {
try {
const { databases } = await runCommand(adminDb, {
listDatabases: 1,
nameOnly,
} as {
listDatabases: 1;
});
const { databases } = await runCommand(
adminDb,
{
listDatabases: 1,
nameOnly,
} as {
listDatabases: 1;
},
{ enableUtf8Validation: false }
);
return databases;
} catch (err) {
// Currently Compass should not fail if listDatabase failed for any
Expand Down Expand Up @@ -2112,15 +2127,23 @@ class DataServiceImpl extends WithLogContext implements DataService {
})
async serverStatus(): Promise<Document> {
const admin = this._database('admin', 'META');
return await runCommand(admin, { serverStatus: 1 });
return await runCommand(
admin,
{ serverStatus: 1 },
{ enableUtf8Validation: false }
);
}

@op(mongoLogId(1_001_000_062), (_, result) => {
return result ? { result } : undefined;
})
async top(): Promise<{ totals: Record<string, unknown> }> {
const adminDb = this._database('admin', 'META');
return await runCommand(adminDb, { top: 1 });
return await runCommand(
adminDb,
{ top: 1 },
{ enableUtf8Validation: false }
);
}

@op(
Expand Down Expand Up @@ -2457,7 +2480,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
name: string
): Promise<ReturnType<typeof adaptDatabaseInfo> & { name: string }> {
const db = this._database(name, 'META');
const stats = await runCommand(db, { dbStats: 1 });
const stats = await runCommand(
db,
{ dbStats: 1 },
{ enableUtf8Validation: false }
);
const normalized = adaptDatabaseInfo(stats);
return { name, ...normalized };
}
Expand Down
30 changes: 21 additions & 9 deletions packages/data-service/src/instance-detail-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,34 @@ export async function getInstance(
atlasVersionResult,
isLocalAtlas,
] = await Promise.all([
runCommand(adminDb, { connectionStatus: 1, showPrivileges: true }).catch(
ignoreNotAuthorized(null)
runCommand(
adminDb,
{ connectionStatus: 1, showPrivileges: true },
{ enableUtf8Validation: false }
).catch(ignoreNotAuthorized(null)),
runCommand(adminDb, { hostInfo: 1 }, { enableUtf8Validation: false }).catch(
ignoreNotAuthorized({})
),
runCommand(adminDb, { hostInfo: 1 }).catch(ignoreNotAuthorized({})),
// This command should always pass, if it throws, somethings is really off.
// This is why it's the only one where we are not ignoring any types of
// errors
runCommand(adminDb, { buildInfo: 1 }),
runCommand(adminDb, { buildInfo: 1 }, { enableUtf8Validation: false }),
// This command is only here to get data for the logs and telemetry, if it
// failed (e.g., not authorised or not supported) we should just ignore the
// failure
runCommand<{ featureCompatibilityVersion: { version: string } }>(adminDb, {
getParameter: 1,
featureCompatibilityVersion: 1,
}).catch(() => null),
runCommand(adminDb, { atlasVersion: 1 }).catch(() => {
runCommand<{ featureCompatibilityVersion: { version: string } }>(
adminDb,
{
getParameter: 1,
featureCompatibilityVersion: 1,
},
{ enableUtf8Validation: false }
).catch(() => null),
runCommand(
adminDb,
{ atlasVersion: 1 },
{ enableUtf8Validation: false }
).catch(() => {
return { atlasVersion: '', gitVersion: '' };
}),
checkIsLocalAtlas(
Expand Down

0 comments on commit 14d1aa3

Please sign in to comment.