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

fix(shell-api): sh.status() should show full list of tag ranges in verbose mode only MONGOSH-1327 #2048

Merged
merged 13 commits into from
Jul 19, 2024
Merged
28 changes: 20 additions & 8 deletions packages/shell-api/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,30 @@ export async function getPrintableShardStatus(
);
}

const tagsRes: any[] = [];
for await (const tag of (
const tags = await (
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
await configDB.getCollection('tags').find({
ns: coll._id,
})
).sort({ min: 1 })) {
tagsRes.push({
tag: tag.tag,
min: tag.min,
max: tag.max,
});
)
.sort({ min: 1 })
.toArray();
const tagsRes: any[] = [];

// NOTE: this will return tags as a string, and will print ugly BSON
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
if (tags.length < 20 || verbose) {
for (const tag of tags) {
tagsRes.push({
tag: tag.tag,
min: tag.min,
max: tag.max,
});
}
} else {
tagsRes.push(
'too many tags to print, use verbose if you want to force print'
);
}

collRes.chunks = chunksRes;
collRes.tags = tagsRes;
return [coll._id, collRes] as const;
Expand Down
36 changes: 36 additions & 0 deletions packages/shell-api/src/shard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,42 @@ describe('Shard', function () {
);
expect((await sh.status()).value.shards[0].tags).to.deep.equal([]);
});
it('shows a full array if tags less than 20', async function () {
const db = instanceState.currentDb.getSiblingDB(dbName);
await db.getCollection('coll').createIndex({ key: 1 });
for (let i = 0; i < 19; i++) {
await db.getCollection('coll').insertOne({ key: 'A', value: i * 10 });
await sh.addShardToZone(`${shardId}-0`, `zone${i}`);
await sh.updateZoneKeyRange(
ns,
{ key: i * 10 },
{ key: i * 10 + 10 },
`zone${i}`
);
await sh.addShardTag(`${shardId}-0`, `zone${i}`);
}

const tags = (await sh.status()).value.databases.find(
(d) => d.database._id === 'test'
).collections[ns].tags;
expect(tags.length).to.equal(19);
});
it('shows tags as a string when there are too many', async function () {
await sh.addShardToZone(`${shardId}-0`, 'zone19');
await sh.updateZoneKeyRange(ns, { key: 190 }, { key: 200 }, 'zone19');
await sh.addShardTag(`${shardId}-0`, 'zone19');

const databases = (await sh.status()).value.databases;
const collections = databases.find(
(d) => d.database._id === 'test'
).collections;
const tags = collections[ns].tags;

expect(tags.length).to.equal(1);
expect(tags[0]).to.equal(
'too many tags to print, use verbose if you want to force print'
);
});
});
describe('balancer', function () {
it('reports balancer state', async function () {
Expand Down
Loading