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

chore(data-service): disable utf8 validation when retrieving metadata compass needs in order to function COMPASS-8517 #6531

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added this option which triggered the whole aggregation to be reformatted by prettier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this one here because the user's error log file contained a lot of aggregate failed commands and we have a hunch it might be this one.

)
.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
Loading