Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-56104
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jan 28, 2020
2 parents 59f4f53 + aa2cb48 commit 16726d5
Show file tree
Hide file tree
Showing 73 changed files with 1,126 additions and 541 deletions.
50 changes: 50 additions & 0 deletions src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,56 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({
renameFromRoot('xpack.telemetry.config', 'telemetry.config'),
renameFromRoot('xpack.telemetry.banner', 'telemetry.banner'),
renameFromRoot('xpack.telemetry.url', 'telemetry.url'),
// Monitoring renames
// TODO: Remove these from here once the monitoring plugin is migrated to NP
renameFromRoot('xpack.monitoring.enabled', 'monitoring.enabled'),
renameFromRoot('xpack.monitoring.ui.enabled', 'monitoring.ui.enabled'),
renameFromRoot(
'xpack.monitoring.kibana.collection.enabled',
'monitoring.kibana.collection.enabled'
),
renameFromRoot('xpack.monitoring.max_bucket_size', 'monitoring.ui.max_bucket_size'),
renameFromRoot('xpack.monitoring.min_interval_seconds', 'monitoring.ui.min_interval_seconds'),
renameFromRoot(
'xpack.monitoring.show_license_expiration',
'monitoring.ui.show_license_expiration'
),
renameFromRoot(
'xpack.monitoring.ui.container.elasticsearch.enabled',
'monitoring.ui.container.elasticsearch.enabled'
),
renameFromRoot(
'xpack.monitoring.ui.container.logstash.enabled',
'monitoring.ui.container.logstash.enabled'
),
renameFromRoot(
'xpack.monitoring.tests.cloud_detector.enabled',
'monitoring.tests.cloud_detector.enabled'
),
renameFromRoot(
'xpack.monitoring.kibana.collection.interval',
'monitoring.kibana.collection.interval'
),
renameFromRoot('xpack.monitoring.elasticsearch.hosts', 'monitoring.ui.elasticsearch.hosts'),
renameFromRoot('xpack.monitoring.elasticsearch.username', 'monitoring.ui.elasticsearch.username'),
renameFromRoot('xpack.monitoring.elasticsearch.password', 'monitoring.ui.elasticsearch.password'),
renameFromRoot(
'xpack.monitoring.xpack_api_polling_frequency_millis',
'monitoring.xpack_api_polling_frequency_millis'
),
renameFromRoot(
'xpack.monitoring.cluster_alerts.email_notifications.enabled',
'monitoring.cluster_alerts.email_notifications.enabled'
),
renameFromRoot(
'xpack.monitoring.cluster_alerts.email_notifications.email_address',
'monitoring.cluster_alerts.email_notifications.email_address'
),
renameFromRoot('xpack.monitoring.ccs.enabled', 'monitoring.ui.ccs.enabled'),
renameFromRoot(
'xpack.monitoring.elasticsearch.logFetchCount',
'monitoring.ui.elasticsearch.logFetchCount'
),
configPathDeprecation,
dataPathDeprecation,
rewriteBasePathDeprecation,
Expand Down
6 changes: 6 additions & 0 deletions src/core/server/legacy/logging/appenders/legacy_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export class LegacyAppender implements DisposableAppender {
legacyLoggingConfig: schema.any(),
});

/**
* Sets {@link Appender.receiveAllLevels} because legacy does its own filtering based on the legacy logging
* configuration.
*/
public readonly receiveAllLevels = true;

private readonly loggingServer: LegacyLoggingServer;

constructor(legacyLoggingConfig: Readonly<LegacyVars>) {
Expand Down
6 changes: 6 additions & 0 deletions src/core/server/logging/appenders/appenders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export type AppenderConfigType = TypeOf<typeof appendersSchema>;
*/
export interface Appender {
append(record: LogRecord): void;

/**
* Used to signal to `Logger` that log level filtering should be ignored for this appender. Defaults to `false`.
* @deprecated Should be removed once the `LegacyAppender` is removed.
*/
receiveAllLevels?: boolean;
}

/**
Expand Down
82 changes: 82 additions & 0 deletions src/core/server/logging/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,85 @@ test('passes log record to appenders only if log level is supported.', () => {
});
}
});

test('passes log record to appender with receiveAllLevels: true, regardless if log level is supported', () => {
const receiveAllAppender = { append: jest.fn(), receiveAllLevels: true };
const warnLogger = new BaseLogger(context, LogLevel.Warn, [receiveAllAppender], factory);

warnLogger.trace('trace-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(1);
expect(receiveAllAppender.append.mock.calls[0][0]).toMatchObject({
level: LogLevel.Trace,
message: 'trace-message',
});

warnLogger.debug('debug-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(2);
expect(receiveAllAppender.append.mock.calls[1][0]).toMatchObject({
level: LogLevel.Debug,
message: 'debug-message',
});

warnLogger.info('info-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(3);
expect(receiveAllAppender.append.mock.calls[2][0]).toMatchObject({
level: LogLevel.Info,
message: 'info-message',
});

warnLogger.warn('warn-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(4);
expect(receiveAllAppender.append.mock.calls[3][0]).toMatchObject({
level: LogLevel.Warn,
message: 'warn-message',
});

warnLogger.error('error-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(5);
expect(receiveAllAppender.append.mock.calls[4][0]).toMatchObject({
level: LogLevel.Error,
message: 'error-message',
});

warnLogger.fatal('fatal-message');
expect(receiveAllAppender.append).toHaveBeenCalledTimes(6);
expect(receiveAllAppender.append.mock.calls[5][0]).toMatchObject({
level: LogLevel.Fatal,
message: 'fatal-message',
});
});

test('passes log record to appender with receiveAllLevels: false, only if log level is supported', () => {
const notReceiveAllAppender = { append: jest.fn(), receiveAllLevels: false };
const warnLogger = new BaseLogger(context, LogLevel.Warn, [notReceiveAllAppender], factory);

warnLogger.trace('trace-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(0);

warnLogger.debug('debug-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(0);

warnLogger.info('info-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(0);

warnLogger.warn('warn-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(1);
expect(notReceiveAllAppender.append.mock.calls[0][0]).toMatchObject({
level: LogLevel.Warn,
message: 'warn-message',
});

warnLogger.error('error-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(2);
expect(notReceiveAllAppender.append.mock.calls[1][0]).toMatchObject({
level: LogLevel.Error,
message: 'error-message',
});

warnLogger.fatal('fatal-message');
expect(notReceiveAllAppender.append).toHaveBeenCalledTimes(3);
expect(notReceiveAllAppender.append.mock.calls[2][0]).toMatchObject({
level: LogLevel.Fatal,
message: 'fatal-message',
});
});
8 changes: 4 additions & 4 deletions src/core/server/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export class BaseLogger implements Logger {
}

public log(record: LogRecord) {
if (!this.level.supports(record.level)) {
return;
}
const supportedLevel = this.level.supports(record.level);

for (const appender of this.appenders) {
appender.append(record);
if (supportedLevel || appender.receiveAllLevels) {
appender.append(record);
}
}
}

Expand Down
96 changes: 48 additions & 48 deletions x-pack/legacy/plugins/monitoring/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const config = Joi => {
const DEFAULT_REQUEST_HEADERS = ['authorization'];

return Joi.object({
ccs: Joi.object({
enabled: Joi.boolean().default(true),
}).default(),
enabled: Joi.boolean().default(true),
ui: Joi.object({
enabled: Joi.boolean().default(true),
ccs: Joi.object({
enabled: Joi.boolean().default(true),
}).default(),
container: Joi.object({
elasticsearch: Joi.object({
enabled: Joi.boolean().default(false),
Expand All @@ -29,6 +29,51 @@ export const config = Joi => {
enabled: Joi.boolean().default(false),
}).default(),
}).default(),
max_bucket_size: Joi.number().default(10000),
min_interval_seconds: Joi.number().default(10),
show_license_expiration: Joi.boolean().default(true),
elasticsearch: Joi.object({
customHeaders: Joi.object().default({}),
logQueries: Joi.boolean().default(false),
requestHeadersWhitelist: Joi.array()
.items()
.single()
.default(DEFAULT_REQUEST_HEADERS),
sniffOnStart: Joi.boolean().default(false),
sniffInterval: Joi.number()
.allow(false)
.default(false),
sniffOnConnectionFault: Joi.boolean().default(false),
hosts: Joi.array()
.items(Joi.string().uri({ scheme: ['http', 'https'] }))
.single(), // if empty, use Kibana's connection config
username: Joi.string(),
password: Joi.string(),
requestTimeout: Joi.number().default(30000),
pingTimeout: Joi.number().default(30000),
ssl: Joi.object({
verificationMode: Joi.string()
.valid('none', 'certificate', 'full')
.default('full'),
certificateAuthorities: Joi.array()
.single()
.items(Joi.string()),
certificate: Joi.string(),
key: Joi.string(),
keyPassphrase: Joi.string(),
keystore: Joi.object({
path: Joi.string(),
password: Joi.string(),
}).default(),
truststore: Joi.object({
path: Joi.string(),
password: Joi.string(),
}).default(),
alwaysPresentCertificate: Joi.boolean().default(false),
}).default(),
apiVersion: Joi.string().default('master'),
logFetchCount: Joi.number().default(10),
}).default(),
}).default(),
kibana: Joi.object({
collection: Joi.object({
Expand All @@ -46,56 +91,11 @@ export const config = Joi => {
xpack_api_polling_frequency_millis: Joi.number().default(
XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS
),
max_bucket_size: Joi.number().default(10000),
min_interval_seconds: Joi.number().default(10),
show_license_expiration: Joi.boolean().default(true),
agent: Joi.object({
interval: Joi.string()
.regex(/[\d\.]+[yMwdhms]/)
.default('10s'),
}).default(),
elasticsearch: Joi.object({
customHeaders: Joi.object().default({}),
logQueries: Joi.boolean().default(false),
requestHeadersWhitelist: Joi.array()
.items()
.single()
.default(DEFAULT_REQUEST_HEADERS),
sniffOnStart: Joi.boolean().default(false),
sniffInterval: Joi.number()
.allow(false)
.default(false),
sniffOnConnectionFault: Joi.boolean().default(false),
hosts: Joi.array()
.items(Joi.string().uri({ scheme: ['http', 'https'] }))
.single(), // if empty, use Kibana's connection config
username: Joi.string(),
password: Joi.string(),
requestTimeout: Joi.number().default(30000),
pingTimeout: Joi.number().default(30000),
ssl: Joi.object({
verificationMode: Joi.string()
.valid('none', 'certificate', 'full')
.default('full'),
certificateAuthorities: Joi.array()
.single()
.items(Joi.string()),
certificate: Joi.string(),
key: Joi.string(),
keyPassphrase: Joi.string(),
keystore: Joi.object({
path: Joi.string(),
password: Joi.string(),
}).default(),
truststore: Joi.object({
path: Joi.string(),
password: Joi.string(),
}).default(),
alwaysPresentCertificate: Joi.boolean().default(false),
}).default(),
apiVersion: Joi.string().default('master'),
logFetchCount: Joi.number().default(10),
}).default(),
tests: Joi.object({
cloud_detector: Joi.object({
enabled: Joi.boolean().default(true),
Expand Down
34 changes: 17 additions & 17 deletions x-pack/legacy/plugins/monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ export const monitoring = kibana =>
new kibana.Plugin({
require: ['kibana', 'elasticsearch', 'xpack_main'],
id: 'monitoring',
configPrefix: 'xpack.monitoring',
configPrefix: 'monitoring',
publicDir: resolve(__dirname, 'public'),
init(server) {
const configs = [
'xpack.monitoring.ui.enabled',
'xpack.monitoring.kibana.collection.enabled',
'xpack.monitoring.max_bucket_size',
'xpack.monitoring.min_interval_seconds',
'monitoring.ui.enabled',
'monitoring.kibana.collection.enabled',
'monitoring.ui.max_bucket_size',
'monitoring.ui.min_interval_seconds',
'kibana.index',
'pkg.version',
'xpack.monitoring.show_license_expiration',
'xpack.monitoring.ui.container.elasticsearch.enabled',
'xpack.monitoring.ui.container.logstash.enabled',
'xpack.monitoring.tests.cloud_detector.enabled',
'xpack.monitoring.kibana.collection.interval',
'xpack.monitoring.elasticsearch.hosts',
'xpack.monitoring.elasticsearch',
'xpack.monitoring.xpack_api_polling_frequency_millis',
'monitoring.ui.show_license_expiration',
'monitoring.ui.container.elasticsearch.enabled',
'monitoring.ui.container.logstash.enabled',
'monitoring.tests.cloud_detector.enabled',
'monitoring.kibana.collection.interval',
'monitoring.ui.elasticsearch.hosts',
'monitoring.ui.elasticsearch',
'monitoring.xpack_api_polling_frequency_millis',
'server.uuid',
'server.name',
'server.host',
'server.port',
'xpack.monitoring.cluster_alerts.email_notifications.enabled',
'xpack.monitoring.cluster_alerts.email_notifications.email_address',
'xpack.monitoring.ccs.enabled',
'xpack.monitoring.elasticsearch.logFetchCount',
'monitoring.cluster_alerts.email_notifications.enabled',
'monitoring.cluster_alerts.email_notifications.email_address',
'monitoring.ui.ccs.enabled',
'monitoring.ui.elasticsearch.logFetchCount',
];

const serverConfig = server.config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function alertsClusterSearch(req, alertsIndex, cluster, checkLicense, opt

if (prodLicenseInfo.clusterAlerts.enabled) {
const config = req.server.config();
const size = options.size || config.get('xpack.monitoring.max_bucket_size');
const size = options.size || config.get('monitoring.ui.max_bucket_size');

const params = {
index: alertsIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function verifyMonitoringLicense(server) {
const config = server.config();

// if cluster alerts are enabled, then ensure that we can use it according to the license
if (config.get('xpack.monitoring.cluster_alerts.enabled')) {
if (config.get('monitoring.cluster_alerts.enabled')) {
const xpackInfo = get(server.plugins.monitoring, 'info');
if (xpackInfo) {
const monitoringCluster = xpackInfo.feature('monitoring').getLicenseCheckResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { exposeClient, hasMonitoringCluster } from '../instantiate_client';

function getMockServerFromConnectionUrl(monitoringClusterUrl) {
const server = {
xpack: {
monitoring: {
monitoring: {
ui: {
elasticsearch: {
hosts: monitoringClusterUrl ? [monitoringClusterUrl] : [],
username: 'monitoring-user-internal-test',
Expand All @@ -27,7 +27,7 @@ function getMockServerFromConnectionUrl(monitoringClusterUrl) {
};

return {
elasticsearchConfig: server.xpack.monitoring.elasticsearch,
elasticsearchConfig: server.monitoring.ui.elasticsearch,
elasticsearchPlugin: {
getCluster: sinon
.stub()
Expand Down
Loading

0 comments on commit 16726d5

Please sign in to comment.