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

Logging when max-bytes is larger than what's set in ES #26482

Merged
merged 4 commits into from
Dec 7, 2018
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
1 change: 1 addition & 0 deletions x-pack/plugins/apm/typings/numeral.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
interface Numeral {
(value?: unknown): Numeral;
format: (pattern: string) => string;
unformat: (pattern: string) => number;
}

declare var numeral: Numeral;
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/reporting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createQueueFactory } from './server/lib/create_queue';
import { config as appConfig } from './server/config/config';
import { checkLicenseFactory } from './server/lib/check_license';
import { validateConfig } from './server/lib/validate_config';
import { validateMaxContentLength } from './server/lib/validate_max_content_length';
import { exportTypesRegistryFactory } from './server/lib/export_types_registry';
import { PHANTOM, createBrowserDriverFactory, getDefaultBrowser, getDefaultChromiumSandboxDisabled } from './server/browsers';
import { logConfiguration } from './log_configuration';
Expand Down Expand Up @@ -148,7 +149,10 @@ export const reporting = (kibana) => {
server.expose('exportTypesRegistry', exportTypesRegistry);

const config = server.config();
validateConfig(config, message => server.log(['reporting', 'warning'], message));
const logWarning = message => server.log(['reporting', 'warning'], message);

validateConfig(config, logWarning);
validateMaxContentLength(server, logWarning);
logConfiguration(config, message => server.log(['reporting', 'debug'], message));

const { xpack_main: xpackMainPlugin } = server.plugins;
Expand Down
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 x-pack/plugins/reporting/server/lib/validate_max_content_length.ts
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.`
);
}
}