[Monitoring] Fix 500 error from /api/stats (#36986) (#37082)

* Fix 500 and add test for it

* Return an empty object so the logic later will still execute

* Update tests
This commit is contained in:
Chris Roberson 2019-05-24 10:59:06 -04:00 committed by GitHub
parent a1d2643ad2
commit cf9fdaac5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -80,7 +80,7 @@ export function registerStatsApi(kbnServer, server, config) {
return boom.serverUnavailable(STATS_NOT_READY_MESSAGE); return boom.serverUnavailable(STATS_NOT_READY_MESSAGE);
} }
const usagePromise = shouldGetUsage ? getUsage(callCluster) : Promise.resolve(); const usagePromise = shouldGetUsage ? getUsage(callCluster) : Promise.resolve({});
try { try {
const [ usage, clusterUuid ] = await Promise.all([ const [ usage, clusterUuid ] = await Promise.all([
usagePromise, usagePromise,

View file

@ -120,13 +120,25 @@ export default function ({ getService }) {
}); });
describe('exclude usage', () => { describe('exclude usage', () => {
it('should exclude usage from the API response', () => { it('should include an empty usage object from the API response', () => {
return supertest return supertest
.get('/api/stats?extended&exclude_usage') .get('/api/stats?extended&exclude_usage')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200) .expect(200)
.then(({ body }) => { .then(({ body }) => {
expect(body).to.not.have.property('usage'); expect(body).to.have.property('usage');
expect(body.usage).to.eql({});
});
});
it('should include an empty usage object from the API response if `legacy` is provided', () => {
return supertest
.get('/api/stats?extended&exclude_usage&legacy')
.expect('Content-Type', /json/)
.expect(200)
.then(({ body }) => {
expect(body).to.have.property('usage');
expect(body.usage).to.eql({});
}); });
}); });
}); });