Skip to content

Commit

Permalink
handle error when querying nouveau info + fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Dec 12, 2024
1 parent 856045f commit a1bba0d
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 26 deletions.
12 changes: 3 additions & 9 deletions api/src/services/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ const mapDbInfo = (dbInfo, viewIndexInfos, nouveauIndexInfos) => {
file: defaultNumber(viewIndexInfo.view_index?.sizes?.file),
},
})),
nouveau_indexes: nouveauIndexInfos ? nouveauIndexInfos.map(nouveauIndexInfo => ({
nouveau_indexes: nouveauIndexInfos?.map(nouveauIndexInfo => ({
name: nouveauIndexInfo.name || '',
update_sequence: nouveauIndexInfo.search_index.update_seq,
num_docs: defaultNumber(nouveauIndexInfo.search_index.num_docs),
disk_size: defaultNumber(nouveauIndexInfo.search_index.disk_size),
})) : undefined,
})),
};
};

Expand Down Expand Up @@ -198,7 +198,7 @@ const fetchNouveauIndexInfosForDdoc = (db, ddoc) => NOUVEAU_INDEXES_TO_MONITOR[d

const fetchNouveauIndexInfosForDb = (db) => Promise.all(Object.keys(NOUVEAU_INDEXES_TO_MONITOR[db]).flatMap(
ddoc => fetchNouveauIndexInfosForDdoc(db, ddoc),
));
)).then((nouveauIndexInfos) => nouveauIndexInfos.filter(info => info));

const fetchAllNouveauIndexInfos = () => Promise.all(
Object.keys(NOUVEAU_INDEXES_TO_MONITOR).map(fetchNouveauIndexInfosForDb),
Expand All @@ -210,16 +210,10 @@ const getDbInfos = async () => {
fetchAllViewIndexInfos(),
fetchAllNouveauIndexInfos(),
]);
// console.log("dbInfos", dbInfos);
// console.log("viewIndexInfos", viewIndexInfos);
// console.log("nouveauInfos", nouveauIndexInfos);
const result = {};
Object.keys(DBS_TO_MONITOR).forEach((dbKey, i) => {
// console.log("dbInfos[i]", dbInfos[i]);
// console.log("viewIndexInfos[i]", viewIndexInfos[i]);
result[dbKey] = mapDbInfo(dbInfos[i], viewIndexInfos[i], nouveauIndexInfos[i]);
});
// console.log("result", result);
return result;
};

Expand Down
147 changes: 130 additions & 17 deletions api/tests/mocha/services/monitoring.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,35 @@ const VIEW_INDEX_INFO_BY_DESIGN = {
}
};

const NOUVEAU_DDOCS_BY_DB = {
[environment.db]: ['medic-nouveau'],
};

const NOUVEAU_INDEX_INFO_BY_DDOC = {
'medic-nouveau': {
reports_by_freetext: {
name: '_design/medic-nouveau/reports_by_freetext',
search_index: {
update_seq: 1956891,
purge_seq: 0,
num_docs: 183741,
disk_size: 157258510,
signature: 'cfd67cbb4800308021b6547bcf21cbf99b9476186b5251f317b221225714c5d3',
},
},
contacts_by_freetext: {
name: '_design/medic-nouveau/contacts_by_freetext',
search_index: {
update_seq: 1956891,
purge_seq: 0,
num_docs: 207734,
disk_size: 76815351,
signature: '46de1dfc576838494f798264571dc59658db7ea164915dd459a7752c31591ae6',
},
},
},
};

const setUpMocks = () => {
sinon.stub(deployInfo, 'get').resolves({ version: '5.3.2' });
sinon.stub(request, 'get')
Expand All @@ -173,6 +202,16 @@ const setUpMocks = () => {
.resolves(VIEW_INDEX_INFO_BY_DESIGN[designDoc]);
});
});
Object.keys(NOUVEAU_DDOCS_BY_DB).forEach(dbName => {
NOUVEAU_DDOCS_BY_DB[dbName].forEach(designDoc => {
Object.keys(NOUVEAU_INDEX_INFO_BY_DDOC[designDoc]).forEach(indexName => {
request.get
.withArgs(
sinon.match({ url: `${environment.serverUrl}/${dbName}/_design/${designDoc}/_nouveau_info/${indexName}` }),
).resolves(NOUVEAU_INDEX_INFO_BY_DDOC[designDoc][indexName]);
});
});
});
sinon.stub(request, 'post').withArgs(sinon.match({ url: `${environment.serverUrl}/_dbs_info` }))
.resolves(dbInfos);
sinon.stub(db.sentinel, 'get').withArgs('_local/transitions-seq')
Expand Down Expand Up @@ -284,9 +323,23 @@ describe('Monitoring service', () => {
update_sequence: 100,
sizes: {
active: 600,
file: 700
file: 700,
},
view_indexes: getExpectedViewIndexes(environment.db)
view_indexes: getExpectedViewIndexes(environment.db),
nouveau_indexes: [
{
disk_size: 76815351,
name: '_design/medic-nouveau/contacts_by_freetext',
num_docs: 207734,
update_sequence: 1956891,
},
{
disk_size: 157258510,
name: '_design/medic-nouveau/reports_by_freetext',
num_docs: 183741,
update_sequence: 1956891,
},
],
},
sentinel: {
doc_count: 30,
Expand All @@ -298,7 +351,8 @@ describe('Monitoring service', () => {
active: 500,
file: 500
},
view_indexes: getExpectedViewIndexes(`${environment.db}-sentinel`)
view_indexes: getExpectedViewIndexes(`${environment.db}-sentinel`),
nouveau_indexes: undefined,
},
users: {
doc_count: 50,
Expand All @@ -310,7 +364,8 @@ describe('Monitoring service', () => {
active: 500,
file: 501
},
view_indexes: getExpectedViewIndexes('_users')
view_indexes: getExpectedViewIndexes('_users'),
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: 40,
Expand All @@ -322,7 +377,8 @@ describe('Monitoring service', () => {
active: 500,
file: 5000
},
view_indexes: getExpectedViewIndexes(`${environment.db}-users-meta`)
view_indexes: getExpectedViewIndexes(`${environment.db}-users-meta`),
nouveau_indexes: undefined,
}
});
chai.expect(actual.messaging).to.deep.equal({
Expand All @@ -348,6 +404,14 @@ describe('Monitoring service', () => {
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-admin/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-client/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-conflicts/_info` }],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/contacts_by_freetext`,
}],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/reports_by_freetext`,
}],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-scripts/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-sms/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}-sentinel/_design/sentinel/_info` }],
Expand Down Expand Up @@ -395,7 +459,21 @@ describe('Monitoring service', () => {
active: 600,
file: 700
},
view_indexes: getExpectedViewIndexes(environment.db)
view_indexes: getExpectedViewIndexes(environment.db),
nouveau_indexes: [
{
disk_size: 76815351,
name: '_design/medic-nouveau/contacts_by_freetext',
num_docs: 207734,
update_sequence: 1956891,
},
{
disk_size: 157258510,
name: '_design/medic-nouveau/reports_by_freetext',
num_docs: 183741,
update_sequence: 1956891,
},
],
},
sentinel: {
doc_count: 30,
Expand All @@ -407,7 +485,8 @@ describe('Monitoring service', () => {
active: 500,
file: 500
},
view_indexes: getExpectedViewIndexes(`${environment.db}-sentinel`)
view_indexes: getExpectedViewIndexes(`${environment.db}-sentinel`),
nouveau_indexes: undefined,
},
users: {
doc_count: 50,
Expand All @@ -419,7 +498,8 @@ describe('Monitoring service', () => {
active: 500,
file: 501
},
view_indexes: getExpectedViewIndexes('_users')
view_indexes: getExpectedViewIndexes('_users'),
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: 40,
Expand All @@ -431,7 +511,8 @@ describe('Monitoring service', () => {
active: 500,
file: 5000
},
view_indexes: getExpectedViewIndexes(`${environment.db}-users-meta`)
view_indexes: getExpectedViewIndexes(`${environment.db}-users-meta`),
nouveau_indexes: undefined,
}
});
chai.expect(actual.messaging).to.deep.equal({
Expand Down Expand Up @@ -484,6 +565,14 @@ describe('Monitoring service', () => {
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-admin/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-client/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-conflicts/_info` }],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/contacts_by_freetext`,
}],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/reports_by_freetext`,
}],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-scripts/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-sms/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}-sentinel/_design/sentinel/_info` }],
Expand Down Expand Up @@ -532,7 +621,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: [],
},
sentinel: {
doc_count: -1,
Expand All @@ -544,7 +634,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
users: {
doc_count: -1,
Expand All @@ -556,7 +647,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: -1,
Expand All @@ -568,7 +660,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
}
});
chai.expect(actual.messaging).to.deep.equal({
Expand All @@ -592,6 +685,14 @@ describe('Monitoring service', () => {
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-admin/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-client/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-conflicts/_info` }],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/contacts_by_freetext`,
}],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/reports_by_freetext`,
}],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-scripts/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-sms/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}-sentinel/_design/sentinel/_info` }],
Expand Down Expand Up @@ -628,7 +729,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: [],
},
sentinel: {
doc_count: -1,
Expand All @@ -640,7 +742,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
users: {
doc_count: -1,
Expand All @@ -652,7 +755,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: -1,
Expand All @@ -664,7 +768,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
}
});
chai.expect(actual.messaging).to.deep.equal({
Expand Down Expand Up @@ -715,6 +820,14 @@ describe('Monitoring service', () => {
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-admin/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-client/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-conflicts/_info` }],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/contacts_by_freetext`,
}],
[{
json: true,
url: `${environment.serverUrl}/${environment.db}/_design/medic-nouveau/_nouveau_info/reports_by_freetext`,
}],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-scripts/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}/_design/medic-sms/_info` }],
[{ json: true, url: `${environment.serverUrl}/${environment.db}-sentinel/_design/sentinel/_info` }],
Expand Down

0 comments on commit a1bba0d

Please sign in to comment.