Skip to content

Commit e51369a

Browse files
authored
[7.x] [Telemetry] Move to OSS (#45769) (#48370)
1 parent ac4482a commit e51369a

File tree

155 files changed

+2128
-1406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+2128
-1406
lines changed

.i18nrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"kbnESQuery": "packages/kbn-es-query",
3030
"inspector": "src/plugins/inspector",
3131
"kibana-react": "src/plugins/kibana_react",
32+
"telemetry": "src/legacy/core_plugins/telemetry",
3233
"esUi": "src/plugins/es_ui_shared",
3334
"uiActions": "src/plugins/ui_actions"
3435
},

docs/settings/monitoring-settings.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Specifies the password that {kib} uses for authentication when it retrieves data
5454
from the monitoring cluster. If not set, {kib} uses the value of the
5555
`elasticsearch.password` setting.
5656

57-
`xpack.telemetry.enabled`::
57+
`telemetry.enabled`::
5858
Set to `true` (default) to send cluster statistics to Elastic. Reporting your
5959
cluster statistics helps us improve your user experience. Your data is never
6060
shared with anyone. Set to `false` to disable statistics reporting from any

src/dev/build/tasks/os_packages/docker_generator/resources/bin/kibana-docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ kibana_vars=(
184184
xpack.security.public.protocol
185185
xpack.security.public.hostname
186186
xpack.security.public.port
187-
xpack.telemetry.enabled
187+
telemetry.enabled
188188
)
189189

190190
longopts=''

src/legacy/core_plugins/kibana/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import * as systemApi from './server/lib/system_api';
3838
import mappings from './mappings.json';
3939
import { getUiSettingDefaults } from './ui_setting_defaults';
4040
import { makeKQLUsageCollector } from './server/lib/kql_usage_collector';
41+
import { registerCspCollector } from './server/lib/csp_usage_collector';
4142
import { injectVars } from './inject_vars';
4243
import { i18n } from '@kbn/i18n';
4344

@@ -344,6 +345,7 @@ export default function (kibana) {
344345
registerFieldFormats(server);
345346
registerTutorials(server);
346347
makeKQLUsageCollector(server);
348+
registerCspCollector(server);
347349
server.expose('systemApi', systemApi);
348350
server.injectUiAppVars('kibana', () => injectVars(server));
349351
},

src/legacy/core_plugins/kibana/public/home/components/telemetry_opt_in/telemetry_opt_in_card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
EuiCard,
2525
EuiButton,
2626
} from '@elastic/eui';
27-
import { OptInMessage } from './opt_in_message';
27+
import { OptInMessage } from '../../../../../telemetry/public/components/opt_in_message';
2828

2929
export interface Props {
3030
urlBasePath: string;

src/legacy/core_plugins/kibana/public/home/kibana_services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import { uiModules } from 'ui/modules';
2121
import { npStart } from 'ui/new_platform';
2222
import { createUiStatsReporter, METRIC_TYPE } from '../../../ui_metric/public';
23-
import { TelemetryOptInProvider } from './telemetry_opt_in';
23+
import { TelemetryOptInProvider } from '../../../telemetry/public/services';
2424

2525
export let indexPatternService;
2626
export let shouldShowTelemetryOptIn;

x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/csp/csp_collector.test.ts renamed to src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.test.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License;
4-
* you may not use this file except in compliance with the Elastic License.
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
518
*/
619

720
import sinon from 'sinon';
8-
import { DEFAULT_CSP_RULES } from '../../../../../../../../src/legacy/server/csp';
9-
import {
10-
getMockCallWithInternal,
11-
getMockKbnServer,
12-
getMockTaskFetch,
13-
} from '../../../../test_utils';
21+
import { Server } from 'hapi';
22+
import { DEFAULT_CSP_RULES } from '../../../../../server/csp';
1423
import { createCspCollector } from './csp_collector';
1524

25+
interface MockConfig {
26+
get: (x: string) => any;
27+
}
28+
29+
const getMockKbnServer = (mockConfig: MockConfig) => ({
30+
config: () => mockConfig,
31+
});
32+
1633
test('fetches whether strict mode is enabled', async () => {
1734
const { collector, mockConfig } = setupCollector();
1835

@@ -72,7 +89,7 @@ function setupCollector() {
7289
mockConfig.get.withArgs('csp.strict').returns(true);
7390
mockConfig.get.withArgs('csp.warnLegacyBrowsers').returns(true);
7491

75-
const mockKbnServer = getMockKbnServer(getMockCallWithInternal(), getMockTaskFetch(), mockConfig);
92+
const mockKbnServer = getMockKbnServer(mockConfig);
7693

77-
return { mockConfig, collector: createCspCollector(mockKbnServer) };
94+
return { mockConfig, collector: createCspCollector(mockKbnServer as Server) };
7895
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Server } from 'hapi';
21+
import { createCSPRuleString, DEFAULT_CSP_RULES } from '../../../../../server/csp';
22+
23+
export function createCspCollector(server: Server) {
24+
return {
25+
type: 'csp',
26+
isReady: () => true,
27+
async fetch() {
28+
const config = server.config();
29+
30+
// It's important that we do not send the value of csp.rules here as it
31+
// can be customized with values that can be identifiable to given
32+
// installs, such as URLs
33+
const defaultRulesString = createCSPRuleString([...DEFAULT_CSP_RULES]);
34+
const actualRulesString = createCSPRuleString(config.get('csp.rules'));
35+
36+
return {
37+
strict: config.get('csp.strict'),
38+
warnLegacyBrowsers: config.get('csp.warnLegacyBrowsers'),
39+
rulesChangedFromDefault: defaultRulesString !== actualRulesString,
40+
};
41+
},
42+
};
43+
}
44+
45+
export function registerCspCollector(server: Server): void {
46+
const { collectorSet } = server.usage;
47+
const collector = collectorSet.makeUsageCollector(createCspCollector(server));
48+
collectorSet.register(collector);
49+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export { registerCspCollector } from './csp_collector';
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { i18n } from '@kbn/i18n';
21+
22+
/*
23+
* config options opt into telemetry
24+
* @type {string}
25+
*/
26+
export const CONFIG_TELEMETRY = 'telemetry:optIn';
27+
/*
28+
* config description for opting into telemetry
29+
* @type {string}
30+
*/
31+
export const getConfigTelemetryDesc = () => {
32+
return i18n.translate('telemetry.telemetryConfigDescription', {
33+
defaultMessage:
34+
'Help us improve the Elastic Stack by providing usage statistics for basic features. We will not share this data outside of Elastic.',
35+
});
36+
};
37+
38+
/**
39+
* The amount of time, in milliseconds, to wait between reports when enabled.
40+
*
41+
* Currently 24 hours.
42+
* @type {Number}
43+
*/
44+
export const REPORT_INTERVAL_MS = 86400000;
45+
46+
/*
47+
* Key for the localStorage service
48+
*/
49+
export const LOCALSTORAGE_KEY = 'telemetry.data';
50+
51+
/**
52+
* Link to the Elastic Telemetry privacy statement.
53+
*/
54+
export const PRIVACY_STATEMENT_URL = `https://www.elastic.co/legal/telemetry-privacy-statement`;
55+
56+
/**
57+
* The type name used within the Monitoring index to publish localization stats.
58+
* @type {string}
59+
*/
60+
export const KIBANA_LOCALIZATION_STATS_TYPE = 'localization';
61+
62+
/**
63+
* UI metric usage type
64+
* @type {string}
65+
*/
66+
export const UI_METRIC_USAGE_TYPE = 'ui_metric';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { KibanaConfig } from 'src/legacy/server/kbn_server';
21+
22+
export function getXpackConfigWithDeprecated(config: KibanaConfig, configPath: string) {
23+
try {
24+
const deprecatedXpackmainConfig = config.get(`xpack.xpack_main.${configPath}`);
25+
if (typeof deprecatedXpackmainConfig !== 'undefined') {
26+
return deprecatedXpackmainConfig;
27+
}
28+
} catch (err) {
29+
// swallow error
30+
}
31+
try {
32+
const deprecatedXpackConfig = config.get(`xpack.${configPath}`);
33+
if (typeof deprecatedXpackConfig !== 'undefined') {
34+
return deprecatedXpackConfig;
35+
}
36+
} catch (err) {
37+
// swallow error
38+
}
39+
40+
return config.get(configPath);
41+
}

0 commit comments

Comments
 (0)