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

feat(#9690): monitor nouveau #9700

Merged
merged 4 commits into from
Dec 16, 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
50 changes: 45 additions & 5 deletions api/src/services/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const VIEW_INDEXES_TO_MONITOR = {
users: ['users'],
};

const NOUVEAU_INDEXES_TO_MONITOR = {
medic: {
'medic-nouveau': [
'contacts_by_freetext',
'reports_by_freetext',
],
},
};

const MESSAGE_QUEUE_STATUS_KEYS = ['due', 'scheduled', 'muted', 'failed', 'delivered'];
const fromEntries = (keys, value) => {
// "shim" of Object.fromEntries
Expand Down Expand Up @@ -115,7 +124,7 @@ const getFragmentation = ({ sizes }, viewIndexInfos) => {
return totalFile / totalActive;
};

const mapDbInfo = (dbInfo, viewIndexInfos) => {
const mapDbInfo = (dbInfo, viewIndexInfos, nouveauIndexInfos) => {
return {
name: dbInfo.db_name || '',
update_sequence: getSequenceNumber(dbInfo.update_seq),
Expand All @@ -131,8 +140,13 @@ const mapDbInfo = (dbInfo, viewIndexInfos) => {
sizes: {
active: defaultNumber(viewIndexInfo.view_index?.sizes?.active),
file: defaultNumber(viewIndexInfo.view_index?.sizes?.file),
}
}))
},
})),
nouveau_indexes: nouveauIndexInfos?.map(nouveauIndexInfo => ({
name: nouveauIndexInfo.name || '',
num_docs: defaultNumber(nouveauIndexInfo.search_index.num_docs),
disk_size: defaultNumber(nouveauIndexInfo.search_index.disk_size),
})),
};
};

Expand Down Expand Up @@ -167,11 +181,37 @@ const fetchViewIndexInfosForDb = (db) => Promise.all(

const fetchAllViewIndexInfos = () => Promise.all(Object.keys(VIEW_INDEXES_TO_MONITOR).map(fetchViewIndexInfosForDb));

const fetchNouveauIndexInfo = (db, designDoc, indexName) => request
.get({
url: `${environment.serverUrl}/${db}/_design/${designDoc}/_nouveau_info/${indexName}`,
json: true
})
.catch(err => {
logger.error('Error fetching nouveau index info: %o', err);
return null;
});

const fetchNouveauIndexInfosForDdoc = (db, ddoc) => NOUVEAU_INDEXES_TO_MONITOR[db][ddoc].map(
indexName => fetchNouveauIndexInfo(DBS_TO_MONITOR[db], ddoc, indexName),
);

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),
);

const getDbInfos = async () => {
const [dbInfos, viewIndexInfos] = await Promise.all([fetchDbsInfo(), fetchAllViewIndexInfos()]);
const [dbInfos, viewIndexInfos, nouveauIndexInfos] = await Promise.all([
fetchDbsInfo(),
fetchAllViewIndexInfos(),
fetchAllNouveauIndexInfos(),
]);
const result = {};
Object.keys(DBS_TO_MONITOR).forEach((dbKey, i) => {
result[dbKey] = mapDbInfo(dbInfos[i], viewIndexInfos[i]);
result[dbKey] = mapDbInfo(dbInfos[i], viewIndexInfos[i], nouveauIndexInfos[i]);
});
return result;
};
Expand Down
143 changes: 126 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,21 @@ 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,
},
{
disk_size: 157258510,
name: '_design/medic-nouveau/reports_by_freetext',
num_docs: 183741,
},
],
},
sentinel: {
doc_count: 30,
Expand All @@ -298,7 +349,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 +362,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 +375,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 +402,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 +457,19 @@ 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,
},
{
disk_size: 157258510,
name: '_design/medic-nouveau/reports_by_freetext',
num_docs: 183741,
},
],
},
sentinel: {
doc_count: 30,
Expand All @@ -407,7 +481,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 +494,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 +507,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 +561,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 +617,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: [],
},
sentinel: {
doc_count: -1,
Expand All @@ -544,7 +630,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
users: {
doc_count: -1,
Expand All @@ -556,7 +643,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: -1,
Expand All @@ -568,7 +656,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 +681,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 +725,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: [],
},
sentinel: {
doc_count: -1,
Expand All @@ -640,7 +738,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
users: {
doc_count: -1,
Expand All @@ -652,7 +751,8 @@ describe('Monitoring service', () => {
active: -1,
file: -1
},
view_indexes: []
view_indexes: [],
nouveau_indexes: undefined,
},
usersmeta: {
doc_count: -1,
Expand All @@ -664,7 +764,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 +816,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
Loading
Loading