Skip to content

Commit

Permalink
Merge branch 'master' into feature-ingestmanager-fleet-api-renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 5, 2020
2 parents 6515f6a + 3d6f150 commit 8c46687
Show file tree
Hide file tree
Showing 384 changed files with 8,755 additions and 821 deletions.
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ using the CURL scripts in the scripts folder.
|WARNING: Missing README.
|{kib-repo}blob/{branch}/x-pack/plugins/triggers_actions_ui/README.md[triggers_actions_ui]
|{kib-repo}blob/{branch}/x-pack/plugins/triggers_actions_ui/README.md[triggersActionsUi]
|The Kibana alerts and actions UI plugin provides a user interface for managing alerts and actions.
As a developer you can reuse and extend built-in alerts and actions UI functionality:
Expand Down
5 changes: 3 additions & 2 deletions packages/kbn-apm-config-loader/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ describe('ApmConfiguration', () => {
resetAllMocks();
});

it('sets the correct service name', () => {
it('sets the correct service name and version', () => {
packageMock.raw = {
version: '9.2.1',
};
const config = new ApmConfiguration(mockedRootDir, {}, false);
expect(config.getConfig('myservice').serviceName).toBe('myservice-9_2_1');
expect(config.getConfig('myservice').serviceName).toBe('myservice');
expect(config.getConfig('myservice').serviceVersion).toBe('9.2.1');
});

it('sets the git revision from `git rev-parse` command in non distribution mode', () => {
Expand Down
29 changes: 26 additions & 3 deletions packages/kbn-apm-config-loader/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ const getDefaultConfig = (isDistributable: boolean): ApmAgentConfig => {
return {
active: false,
globalLabels: {},
// Do not use a centralized controlled config
centralConfig: false,
// Capture all exceptions that are not caught
logUncaughtExceptions: true,
// Can be performance intensive, disabling by default
breakdownMetrics: false,
};
}

return {
active: false,
serverUrl: 'https://f1542b814f674090afd914960583265f.apm.us-central1.gcp.cloud.es.io:443',
Expand Down Expand Up @@ -60,14 +67,14 @@ export class ApmConfiguration {
) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version, build } = require(join(this.rootDir, 'package.json'));
this.kibanaVersion = version.replace(/\./g, '_');
this.kibanaVersion = version;
this.pkgBuild = build;
}

public getConfig(serviceName: string): ApmAgentConfig {
return {
...this.getBaseConfig(),
serviceName: `${serviceName}-${this.kibanaVersion}`,
serviceName,
};
}

Expand All @@ -76,7 +83,8 @@ export class ApmConfiguration {
const apmConfig = merge(
getDefaultConfig(this.isDistributable),
this.getConfigFromKibanaConfig(),
this.getDevConfig()
this.getDevConfig(),
this.getDistConfig()
);

const rev = this.getGitRev();
Expand All @@ -88,6 +96,8 @@ export class ApmConfiguration {
if (uuid) {
apmConfig.globalLabels.kibana_uuid = uuid;
}

apmConfig.serviceVersion = this.kibanaVersion;
this.baseConfig = apmConfig;
}

Expand Down Expand Up @@ -123,6 +133,19 @@ export class ApmConfiguration {
}
}

/** Config keys that cannot be overridden in production builds */
private getDistConfig(): ApmAgentConfig {
if (!this.isDistributable) {
return {};
}

return {
// Headers & body may contain sensitive info
captureHeaders: false,
captureBody: 'off',
};
}

private getGitRev() {
if (this.isDistributable) {
return this.pkgBuild.sha;
Expand Down
3 changes: 1 addition & 2 deletions scripts/kibana_keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

require('../src/setup_node_env');
require('../src/cli_keystore');
require('../src/cli_keystore/dev');
3 changes: 1 addition & 2 deletions scripts/kibana_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

require('../src/setup_node_env');
require('../src/cli_plugin/cli');
require('../src/cli_plugin/dev');
18 changes: 16 additions & 2 deletions src/apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ module.exports = function (serviceName = name) {

apmConfig = loadConfiguration(process.argv, ROOT_DIR, isKibanaDistributable);
const conf = apmConfig.getConfig(serviceName);
require('elastic-apm-node').start(conf);
const apm = require('elastic-apm-node');

// Filter out all user PII
apm.addFilter((payload) => {
try {
if (payload.context && payload.context.user && typeof payload.context.user === 'object') {
Object.keys(payload.context.user).forEach((key) => {
payload.context.user[key] = '[REDACTED]';
});
}
} finally {
return payload;
}
});

apm.start(conf);
};

module.exports.getConfig = (serviceName) => {
Expand All @@ -50,4 +65,3 @@ module.exports.getConfig = (serviceName) => {
}
return {};
};
module.exports.isKibanaDistributable = isKibanaDistributable;
1 change: 1 addition & 0 deletions src/cli/cluster/cluster_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ClusterManager {
type: 'server',
log: this.log,
argv: serverArgv,
apmServiceName: 'kibana',
})),
];

Expand Down
2 changes: 2 additions & 0 deletions src/cli/cluster/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface WorkerOptions {
title?: string;
watch?: boolean;
baseArgv?: string[];
apmServiceName?: string;
}

export class Worker extends EventEmitter {
Expand Down Expand Up @@ -89,6 +90,7 @@ export class Worker extends EventEmitter {
NODE_OPTIONS: process.env.NODE_OPTIONS || '',
kbnWorkerType: this.type,
kbnWorkerArgv: JSON.stringify([...(opts.baseArgv || baseArgv), ...(opts.argv || [])]),
ELASTIC_APM_SERVICE_NAME: opts.apmServiceName || '',
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

require('../apm')(process.env.ELASTIC_APM_PROXY_SERVICE_NAME || 'kibana-proxy');
require('../apm')(process.env.ELASTIC_APM_SERVICE_NAME || 'kibana-proxy');
require('../setup_node_env');
require('./cli');
3 changes: 1 addition & 2 deletions src/cli/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
*/

require('../apm')();
require('../setup_node_env/no_transpilation');
require('core-js/stable');
require('../setup_node_env/dist');
require('./cli');
File renamed without changes.
21 changes: 21 additions & 0 deletions src/cli_keystore/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

require('../setup_node_env/dist');
require('./cli_keystore');
File renamed without changes.
21 changes: 21 additions & 0 deletions src/cli_plugin/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

require('../setup_node_env/dist');
require('./cli');
5 changes: 3 additions & 2 deletions src/core/public/apm_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type { InternalApplicationStart } from './application';

interface ApmConfig {
// AgentConfigOptions is not exported from @elastic/apm-rum
active?: boolean;
globalLabels?: Record<string, string>;
}

Expand All @@ -39,10 +40,10 @@ export class ApmSystem {
private readonly enabled: boolean;
/**
* `apmConfig` would be populated with relevant APM RUM agent
* configuration if server is started with `ELASTIC_APM_ACTIVE=true`
* configuration if server is started with elastic.apm.* config.
*/
constructor(private readonly apmConfig?: ApmConfig) {
this.enabled = process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && apmConfig != null;
this.enabled = apmConfig != null && !!apmConfig.active;
}

async setup() {
Expand Down
153 changes: 153 additions & 0 deletions src/core/server/core_usage_data/core_usage_data_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { PublicMethodsOf } from '@kbn/utility-types';
import { BehaviorSubject } from 'rxjs';
import { CoreUsageDataService } from './core_usage_data_service';
import { CoreUsageData, CoreUsageDataStart } from './types';

const createStartContractMock = () => {
const startContract: jest.Mocked<CoreUsageDataStart> = {
getCoreUsageData: jest.fn().mockResolvedValue(
new BehaviorSubject<CoreUsageData>({
config: {
elasticsearch: {
apiVersion: 'master',
customHeadersConfigured: false,
healthCheckDelayMs: 2500,
logQueries: false,
numberOfHostsConfigured: 1,
pingTimeoutMs: 30000,
requestHeadersWhitelistConfigured: false,
requestTimeoutMs: 30000,
shardTimeoutMs: 30000,
sniffIntervalMs: -1,
sniffOnConnectionFault: false,
sniffOnStart: false,
ssl: {
alwaysPresentCertificate: false,
certificateAuthoritiesConfigured: false,
certificateConfigured: false,
keyConfigured: false,
verificationMode: 'full',
keystoreConfigured: false,
truststoreConfigured: false,
},
},
http: {
basePathConfigured: false,
compression: {
enabled: true,
referrerWhitelistConfigured: false,
},
keepaliveTimeout: 120000,
maxPayloadInBytes: 1048576,
requestId: {
allowFromAnyIp: false,
ipAllowlistConfigured: false,
},
rewriteBasePath: false,
socketTimeout: 120000,
ssl: {
certificateAuthoritiesConfigured: false,
certificateConfigured: false,
cipherSuites: [
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-ECDSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES256-GCM-SHA384',
'ECDHE-ECDSA-AES256-GCM-SHA384',
'DHE-RSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES128-SHA256',
'DHE-RSA-AES128-SHA256',
'ECDHE-RSA-AES256-SHA384',
'DHE-RSA-AES256-SHA384',
'ECDHE-RSA-AES256-SHA256',
'DHE-RSA-AES256-SHA256',
'HIGH',
'!aNULL',
'!eNULL',
'!EXPORT',
'!DES',
'!RC4',
'!MD5',
'!PSK',
'!SRP',
'!CAMELLIA',
],
clientAuthentication: 'none',
keyConfigured: false,
keystoreConfigured: false,
redirectHttpFromPortConfigured: false,
supportedProtocols: ['TLSv1.1', 'TLSv1.2'],
truststoreConfigured: false,
},
xsrf: {
disableProtection: false,
whitelistConfigured: false,
},
},
logging: {
appendersTypesUsed: [],
loggersConfiguredCount: 0,
},
savedObjects: {
maxImportExportSizeBytes: 10000,
maxImportPayloadBytes: 10485760,
},
},
environment: {
memory: {
heapSizeLimit: 1,
heapTotalBytes: 1,
heapUsedBytes: 1,
},
},
services: {
savedObjects: {
indices: [
{
docsCount: 1,
docsDeleted: 1,
alias: 'test_index',
primaryStoreSizeBytes: 1,
storeSizeBytes: 1,
},
],
},
},
})
),
};

return startContract;
};

const createMock = () => {
const mocked: jest.Mocked<PublicMethodsOf<CoreUsageDataService>> = {
setup: jest.fn(),
start: jest.fn().mockReturnValue(createStartContractMock()),
stop: jest.fn(),
};
return mocked;
};

export const coreUsageDataServiceMock = {
create: createMock,
createStartContract: createStartContractMock,
};
Loading

0 comments on commit 8c46687

Please sign in to comment.