-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Simple check if ES body-size is smaller than KBN report size
- Loading branch information
1 parent
00ab45a
commit e69ca8d
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/reporting/server/lib/__tests__/validate_max_content_length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import expect from 'expect.js'; | ||
import sinon from 'sinon'; | ||
import { validateMaxContentLength } from '../validate_max_content_length'; | ||
|
||
const FIVE_HUNDRED_MEGABYTES = 524288000; | ||
const ONE_HUNDRED_MEGABYTES = 104857600; | ||
|
||
describe('Reporting: Validate Max Content Length', () => { | ||
const log = sinon.spy(); | ||
|
||
beforeEach(() => { | ||
log.resetHistory(); | ||
}); | ||
|
||
it('should log warning messages when reporting has a higher max-size than elasticsearch', async () => { | ||
const server = { | ||
config: () => ({ | ||
get: sinon.stub().returns(FIVE_HUNDRED_MEGABYTES), | ||
}), | ||
plugins: { | ||
elasticsearch: { | ||
getCluster: () => ({ | ||
callWithInternalUser: () => ({ | ||
defaults: { | ||
http: { | ||
max_content_length: '100mb', | ||
}, | ||
}, | ||
}), | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
await validateMaxContentLength(server, log); | ||
|
||
sinon.assert.calledWithMatch(log, `xpack.reporting.csv.maxSizeBytes (524288000) is higher`); | ||
sinon.assert.calledWithMatch(log, `than ElasticSearch's http.max_content_length (104857600)`); | ||
sinon.assert.calledWithMatch(log, 'Please set http.max_content_length in ElasticSearch to match'); | ||
sinon.assert.calledWithMatch(log, 'or lower your xpack.reporting.csv.maxSizeBytes in Kibana'); | ||
}); | ||
|
||
it('should do nothing when reporting has the same max-size as elasticsearch', async () => { | ||
const server = { | ||
config: () => ({ | ||
get: sinon.stub().returns(ONE_HUNDRED_MEGABYTES), | ||
}), | ||
plugins: { | ||
elasticsearch: { | ||
getCluster: () => ({ | ||
callWithInternalUser: () => ({ | ||
defaults: { | ||
http: { | ||
max_content_length: '100mb', | ||
}, | ||
}, | ||
}), | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
expect(async () => validateMaxContentLength(server, log)).not.to.throwError(); | ||
sinon.assert.notCalled(log); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/reporting/server/lib/validate_max_content_length.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import numeral from '@elastic/numeral'; | ||
import { defaults, get } from 'lodash'; | ||
const KIBANA_MAX_SIZE_BYTES_PATH = 'xpack.reporting.csv.maxSizeBytes'; | ||
const ES_MAX_SIZE_BYTES_PATH = 'http.max_content_length'; | ||
|
||
export async function validateMaxContentLength(server: any, log: (message: string) => any) { | ||
const config = server.config(); | ||
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('data'); | ||
|
||
const elasticClusterSettingsResponse = await callWithInternalUser('cluster.getSettings', { | ||
includeDefaults: true, | ||
}); | ||
const { persistent, transient, defaults: defaultSettings } = elasticClusterSettingsResponse; | ||
const elasticClusterSettings = defaults({}, persistent, transient, defaultSettings); | ||
|
||
const elasticSearchMaxContent = get(elasticClusterSettings, 'http.max_content_length', '100mb'); | ||
const elasticSearchMaxContentBytes = numeral().unformat(elasticSearchMaxContent.toUpperCase()); | ||
const kibanaMaxContentBytes = config.get(KIBANA_MAX_SIZE_BYTES_PATH); | ||
|
||
if (kibanaMaxContentBytes > elasticSearchMaxContentBytes) { | ||
log( | ||
`${KIBANA_MAX_SIZE_BYTES_PATH} (${kibanaMaxContentBytes}) is higher than ElasticSearch's ${ES_MAX_SIZE_BYTES_PATH} (${elasticSearchMaxContentBytes}). ` + | ||
`Please set ${ES_MAX_SIZE_BYTES_PATH} in ElasticSearch to match, or lower your ${KIBANA_MAX_SIZE_BYTES_PATH} in Kibana to avoid this warning.` | ||
); | ||
} | ||
} |