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

[Telemetry] Move to OSS #45769

Merged
merged 31 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c01fd26
update paths and licenses
Bamieh Sep 16, 2019
96f2c32
localization collector in oss
Bamieh Sep 16, 2019
e9765a9
node-crypto typings in oss
Bamieh Sep 16, 2019
d4b2be8
update telemetry i18n labels
Bamieh Sep 16, 2019
11cf28d
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Sep 16, 2019
badc1b2
update translation rc files
Bamieh Sep 16, 2019
9adbca9
merge master + rename fn
Bamieh Oct 2, 2019
3eb22a0
remove duplicate components in home for telemetry
Bamieh Oct 2, 2019
53e28d7
update tests
Bamieh Oct 2, 2019
0b1384e
finalize collection + move csp collector to oss
Bamieh Oct 2, 2019
0441d3f
update constants
Bamieh Oct 2, 2019
2b1db4c
self review
Bamieh Oct 2, 2019
d83e637
use apm instead of beats
Bamieh Oct 2, 2019
90d7d80
xpack collection
Bamieh Oct 3, 2019
782fb8c
fix collection tests
Bamieh Oct 3, 2019
e07644c
remove space specific settings
Bamieh Oct 4, 2019
a9fcec9
mock npSetup and npStart
Bamieh Oct 4, 2019
cc1eeb2
disable banner in tests
Bamieh Oct 5, 2019
5d1e679
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 5, 2019
60379a2
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 7, 2019
0676f8a
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 8, 2019
1ede425
remove commented mock
Bamieh Oct 9, 2019
fcdc9c4
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 9, 2019
2a203c6
test ec2 plugin
Bamieh Oct 14, 2019
bcb05d7
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 15, 2019
982ef43
monitoring np telemetry fixes
Bamieh Oct 15, 2019
dba4e9d
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 16, 2019
c03c567
replace telemetryOptedIn in oss instead of xpack_main
Bamieh Oct 16, 2019
c2d6f0a
fix telemetry OptIn test
Bamieh Oct 16, 2019
2432023
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 16, 2019
048f37e
Merge branch 'master' of github.com:elastic/kibana into telemetry/oss
Bamieh Oct 16, 2019
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 .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"kbnESQuery": "packages/kbn-es-query",
"inspector": "src/plugins/inspector",
"kibana-react": "src/plugins/kibana_react",
"telemetry": "src/legacy/core_plugins/telemetry",
"esUi": "src/plugins/es_ui_shared",
"uiActions": "src/plugins/ui_actions"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/settings/monitoring-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Specifies the password that {kib} uses for authentication when it retrieves data
from the monitoring cluster. If not set, {kib} uses the value of the
`elasticsearch.password` setting.

`xpack.telemetry.enabled`::
`telemetry.enabled`::
Set to `true` (default) to send cluster statistics to Elastic. Reporting your
cluster statistics helps us improve your user experience. Your data is never
shared with anyone. Set to `false` to disable statistics reporting from any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ kibana_vars=(
xpack.security.encryptionKey
xpack.security.secureCookies
xpack.security.sessionTimeout
xpack.telemetry.enabled
telemetry.enabled
)

longopts=''
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import * as systemApi from './server/lib/system_api';
import mappings from './mappings.json';
import { getUiSettingDefaults } from './ui_setting_defaults';
import { makeKQLUsageCollector } from './server/lib/kql_usage_collector';
import { registerCspCollector } from './server/lib/csp_usage_collector';
import { injectVars } from './inject_vars';
import { i18n } from '@kbn/i18n';

Expand Down Expand Up @@ -344,6 +345,7 @@ export default function (kibana) {
registerFieldFormats(server);
registerTutorials(server);
makeKQLUsageCollector(server);
registerCspCollector(server);
server.expose('systemApi', systemApi);
server.injectUiAppVars('kibana', () => injectVars(server));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
EuiCard,
EuiButton,
} from '@elastic/eui';
import { OptInMessage } from './opt_in_message';
import { OptInMessage } from '../../../../../telemetry/public/components/opt_in_message';

export interface Props {
urlBasePath: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { uiModules } from 'ui/modules';
import { npStart } from 'ui/new_platform';
import { createUiStatsReporter, METRIC_TYPE } from '../../../ui_metric/public';
import { TelemetryOptInProvider } from './telemetry_opt_in';
import { TelemetryOptInProvider } from '../../../telemetry/public/services';

export let indexPatternService;
export let shouldShowTelemetryOptIn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
/*
* 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.
* 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 sinon from 'sinon';
import { DEFAULT_CSP_RULES } from '../../../../../../../../src/legacy/server/csp';
import {
getMockCallWithInternal,
getMockKbnServer,
getMockTaskFetch,
} from '../../../../test_utils';
import { Server } from 'hapi';
import { DEFAULT_CSP_RULES } from '../../../../../server/csp';
import { createCspCollector } from './csp_collector';

interface MockConfig {
get: (x: string) => any;
}

const getMockKbnServer = (mockConfig: MockConfig) => ({
config: () => mockConfig,
});

test('fetches whether strict mode is enabled', async () => {
const { collector, mockConfig } = setupCollector();

Expand Down Expand Up @@ -72,7 +89,7 @@ function setupCollector() {
mockConfig.get.withArgs('csp.strict').returns(true);
mockConfig.get.withArgs('csp.warnLegacyBrowsers').returns(true);

const mockKbnServer = getMockKbnServer(getMockCallWithInternal(), getMockTaskFetch(), mockConfig);
const mockKbnServer = getMockKbnServer(mockConfig);

return { mockConfig, collector: createCspCollector(mockKbnServer) };
return { mockConfig, collector: createCspCollector(mockKbnServer as Server) };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { Server } from 'hapi';
import { createCSPRuleString, DEFAULT_CSP_RULES } from '../../../../../server/csp';

export function createCspCollector(server: Server) {
return {
type: 'csp',
isReady: () => true,
async fetch() {
const config = server.config();

// It's important that we do not send the value of csp.rules here as it
// can be customized with values that can be identifiable to given
// installs, such as URLs
const defaultRulesString = createCSPRuleString([...DEFAULT_CSP_RULES]);
const actualRulesString = createCSPRuleString(config.get('csp.rules'));

return {
strict: config.get('csp.strict'),
warnLegacyBrowsers: config.get('csp.warnLegacyBrowsers'),
rulesChangedFromDefault: defaultRulesString !== actualRulesString,
};
},
};
}

export function registerCspCollector(server: Server): void {
const { collectorSet } = server.usage;
const collector = collectorSet.makeUsageCollector(createCspCollector(server));
collectorSet.register(collector);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { registerCspCollector } from './csp_collector';
66 changes: 66 additions & 0 deletions src/legacy/core_plugins/telemetry/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 { i18n } from '@kbn/i18n';

/*
* config options opt into telemetry
* @type {string}
*/
export const CONFIG_TELEMETRY = 'telemetry:optIn';
/*
* config description for opting into telemetry
* @type {string}
*/
export const getConfigTelemetryDesc = () => {
return i18n.translate('telemetry.telemetryConfigDescription', {
defaultMessage:
'Help us improve the Elastic Stack by providing usage statistics for basic features. We will not share this data outside of Elastic.',
});
};

/**
* The amount of time, in milliseconds, to wait between reports when enabled.
*
* Currently 24 hours.
* @type {Number}
*/
export const REPORT_INTERVAL_MS = 86400000;

/*
* Key for the localStorage service
*/
export const LOCALSTORAGE_KEY = 'telemetry.data';

/**
* Link to the Elastic Telemetry privacy statement.
*/
export const PRIVACY_STATEMENT_URL = `https://www.elastic.co/legal/telemetry-privacy-statement`;

/**
* The type name used within the Monitoring index to publish localization stats.
* @type {string}
*/
export const KIBANA_LOCALIZATION_STATS_TYPE = 'localization';

/**
* UI metric usage type
* @type {string}
*/
export const UI_METRIC_USAGE_TYPE = 'ui_metric';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { KibanaConfig } from 'src/legacy/server/kbn_server';

export function getXpackConfigWithDeprecated(config: KibanaConfig, configPath: string) {
Bamieh marked this conversation as resolved.
Show resolved Hide resolved
try {
const deprecatedXpackmainConfig = config.get(`xpack.xpack_main.${configPath}`);
if (typeof deprecatedXpackmainConfig !== 'undefined') {
return deprecatedXpackmainConfig;
}
} catch (err) {
// swallow error
}
try {
const deprecatedXpackConfig = config.get(`xpack.${configPath}`);
if (typeof deprecatedXpackConfig !== 'undefined') {
return deprecatedXpackConfig;
}
} catch (err) {
// swallow error
}

return config.get(configPath);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
/*
* 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.
* 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 { resolve } from 'path';
import JoiNamespace from 'joi';
import { Server } from 'hapi';
import { CoreSetup, PluginInitializerContext } from 'src/core/server';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import mappings from './mappings.json';
import { CONFIG_TELEMETRY, getConfigTelemetryDesc, REPORT_INTERVAL_MS } from './common/constants';
import { CONFIG_TELEMETRY, getConfigTelemetryDesc } from './common/constants';
import { getXpackConfigWithDeprecated } from './common/get_xpack_config_with_deprecated';
import { telemetryPlugin } from './server';

Expand All @@ -22,10 +36,10 @@ import {

const ENDPOINT_VERSION = 'v2';

export const telemetry = (kibana: any) => {
const telemetry = (kibana: any) => {
return new kibana.Plugin({
id: 'telemetry',
configPrefix: 'xpack.telemetry',
configPrefix: 'telemetry',
publicDir: resolve(__dirname, 'public'),
require: ['elasticsearch'],
config(Joi: typeof JoiNamespace) {
Expand All @@ -49,7 +63,7 @@ export const telemetry = (kibana: any) => {
managementSections: ['plugins/telemetry/views/management'],
uiSettingDefaults: {
[CONFIG_TELEMETRY]: {
name: i18n.translate('xpack.telemetry.telemetryConfigTitle', {
name: i18n.translate('telemetry.telemetryConfigTitle', {
defaultMessage: 'Telemetry opt-in',
}),
description: getConfigTelemetryDesc(),
Expand All @@ -65,8 +79,9 @@ export const telemetry = (kibana: any) => {
injectDefaultVars(server: Server) {
const config = server.config();
return {
telemetryEnabled: getXpackConfigWithDeprecated(config, 'telemetry.enabled'),
telemetryUrl: getXpackConfigWithDeprecated(config, 'telemetry.url'),
telemetryBanner: config.get('xpack.telemetry.banner'),
telemetryBanner: getXpackConfigWithDeprecated(config, 'telemetry.banner'),
telemetryOptedIn: null,
};
},
Expand All @@ -75,8 +90,10 @@ export const telemetry = (kibana: any) => {
},
init(server: Server) {
const initializerContext = {} as PluginInitializerContext;

const coreSetup = ({
http: { server },
log: server.log,
} as any) as CoreSetup;

telemetryPlugin(initializerContext).setup(coreSetup);
Expand All @@ -85,9 +102,9 @@ export const telemetry = (kibana: any) => {
server.usage.collectorSet.register(createLocalizationUsageCollector(server));
server.usage.collectorSet.register(createTelemetryUsageCollector(server));
server.usage.collectorSet.register(createUiMetricUsageCollector(server));

// expose
server.expose('telemetryCollectionInterval', REPORT_INTERVAL_MS);
},
});
};

// eslint-disable-next-line import/no-default-export
export default telemetry;
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/telemetry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "telemetry",
"version": "kibana"
}
Loading