Skip to content

Commit

Permalink
[Rename] telemetry plugin (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Mar 19, 2021
1 parent ee7032c commit e29af53
Show file tree
Hide file tree
Showing 48 changed files with 280 additions and 280 deletions.
20 changes: 10 additions & 10 deletions src/plugins/telemetry/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Kibana Telemetry Service
# OpenSearch Dashboards Telemetry Service

Telemetry allows Kibana features to have usage tracked in the wild. The general term "telemetry" refers to multiple things:
Telemetry allows OpenSearch Dashboards features to have usage tracked in the wild. The general term "telemetry" refers to multiple things:

1. Integrating with the telemetry service to express how to collect usage data (Collecting).
2. Sending a payload of usage data up to Elastic's telemetry cluster.
3. Viewing usage data in the Kibana instance of the telemetry cluster (Viewing).
2. Sending a payload of usage data up to OpenSearch's telemetry cluster.
3. Viewing usage data in the OpenSearchDashboards instance of the telemetry cluster (Viewing).

This plugin is responsible for sending usage data to the telemetry cluster. For collecting usage data, use the [`usageCollection` plugin](../usage_collection/README.md)

Expand All @@ -18,27 +18,27 @@ The `setup` function exposes the following interface:
An async function that resolves into the telemetry Url used to send telemetry. The url is wrapped with node's [URL constructor](https://nodejs.org/api/url.html). Here is an example on how to grab the url origin:
```
const telemetryUrl = await getTelemetryUrl();
> telemetryUrl.origin; // 'https://telemetry.elastic.co'
> telemetryUrl.origin; // 'https://telemetry.opensearch.co'
```
Note that the telemetry URL is a kibana.yml configuration hence it is recommended to call the `getTelemetryUrl` everytime before using the actual url.
Note that the telemetry URL is a opensearch_dashboards.yml configuration hence it is recommended to call the `getTelemetryUrl` everytime before using the actual url.

### Start

The `start` function exposes the following interface:

- `async getIsOptedIn(): Promise<boolean>`:
An async function that resolves into `true` if the user has opted into send Elastic usage data.
Resolves to `false` if the user explicitly opted out of sending usage data to Elastic or did not choose
An async function that resolves into `true` if the user has opted into send OpenSearch usage data.
Resolves to `false` if the user explicitly opted out of sending usage data to OpenSearch or did not choose
to opt-in or out yet after a minor or major upgrade (only when previously opted out).

### Usage

To use the exposed plugin start and setup contracts:

1. Make sure `telemetry` is in your `optionalPlugins` in the `kibana.json` file:
1. Make sure `telemetry` is in your `optionalPlugins` in the `opensearch_dashboards.json` file:

```json5
// <plugin>/kibana.json
// <plugin>/opensearch_dashboards.json
{
"id": "...",
"optionalPlugins": ["telemetry"]
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/telemetry/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';

/**
* config options opt into telemetry
Expand All @@ -31,7 +31,7 @@ export const getConfigTelemetryDesc = () => {
// Can't find where it's used but copying it over from the legacy code just in case...
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.',
'Help us improve the OpenSearch Stack by providing usage statistics for basic features. We will not share this data outside of Elastic.',
});
};

Expand All @@ -49,10 +49,10 @@ export const LOCALSTORAGE_KEY = 'telemetry.data';
/**
* Link to Advanced Settings.
*/
export const PATH_TO_ADVANCED_SETTINGS = 'management/kibana/settings';
export const PATH_TO_ADVANCED_SETTINGS = 'management/opensearch-dashboards/settings';

/**
* Link to the Elastic Telemetry privacy statement.
* Link to the OpenSearch Telemetry privacy statement.
*/
export const PRIVACY_STATEMENT_URL = ``;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { getNotifyUserAboutOptInDefault } from './get_telemetry_notify_user_about_optin_default';

describe('getNotifyUserAboutOptInDefault: get a flag that describes if the user must be notified about optin default', () => {
it('should return true when kibana has fresh defaults', () => {
it('should return true when OpenSearch Dashboards has fresh defaults', () => {
expect(
getNotifyUserAboutOptInDefault({
allowChangingOptInStatus: true,
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('getNotifyUserAboutOptInDefault: get a flag that describes if the user
).toBe(false);
});

it('should return false if kibana is opted out via config', () => {
it('should return false if OpenSearch Dashboards is opted out via config', () => {
expect(
getNotifyUserAboutOptInDefault({
allowChangingOptInStatus: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ describe('getTelemetryOptIn', () => {
type VersionCheckTable = Array<Partial<CallGetTelemetryOptInParams>>;

const EnabledFalseVersionChecks: VersionCheckTable = [
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '8.0.1', result: false },
{ lastVersionChecked: '8.0.1', currentKibanaVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '8.1.0', result: null },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '9.0.0', result: null },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '7.0.0', result: false },
{ lastVersionChecked: '8.1.0', currentKibanaVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0-X', currentKibanaVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: '8.0.0-X', result: false },
{ lastVersionChecked: null, currentKibanaVersion: '8.0.0', result: null },
{ lastVersionChecked: undefined, currentKibanaVersion: '8.0.0', result: null },
{ lastVersionChecked: 5, currentKibanaVersion: '8.0.0', result: null },
{ lastVersionChecked: '8.0.0', currentKibanaVersion: 'beta', result: null },
{ lastVersionChecked: 'beta', currentKibanaVersion: '8.0.0', result: null },
{ lastVersionChecked: 'beta', currentKibanaVersion: 'beta', result: false },
{ lastVersionChecked: 'BETA', currentKibanaVersion: 'beta', result: null },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '8.0.1', result: false },
{ lastVersionChecked: '8.0.1', currentOpenSearchDashboardsVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '8.1.0', result: null },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '9.0.0', result: null },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '7.0.0', result: false },
{ lastVersionChecked: '8.1.0', currentOpenSearchDashboardsVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0-X', currentOpenSearchDashboardsVersion: '8.0.0', result: false },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: '8.0.0-X', result: false },
{ lastVersionChecked: null, currentOpenSearchDashboardsVersion: '8.0.0', result: null },
{ lastVersionChecked: undefined, currentOpenSearchDashboardsVersion: '8.0.0', result: null },
{ lastVersionChecked: 5, currentOpenSearchDashboardsVersion: '8.0.0', result: null },
{ lastVersionChecked: '8.0.0', currentOpenSearchDashboardsVersion: 'beta', result: null },
{ lastVersionChecked: 'beta', currentOpenSearchDashboardsVersion: '8.0.0', result: null },
{ lastVersionChecked: 'beta', currentOpenSearchDashboardsVersion: 'beta', result: false },
{ lastVersionChecked: 'BETA', currentOpenSearchDashboardsVersion: 'beta', result: null },
].map((el) => ({ ...el, enabled: false }));

// build a table of tests with version checks, with results for enabled true/null/undefined
Expand Down Expand Up @@ -124,7 +124,7 @@ interface CallGetTelemetryOptInParams {
savedObjectNotFound: boolean;
savedObjectForbidden: boolean;
lastVersionChecked?: any; // should be a string, but test with non-strings
currentKibanaVersion: string;
currentOpenSearchDashboardsVersion: string;
result?: boolean | null;
enabled: boolean | null | undefined;
configTelemetryOptIn: boolean | null;
Expand All @@ -136,7 +136,7 @@ const DefaultParams = {
savedObjectForbidden: false,
enabled: true,
lastVersionChecked: '8.0.0',
currentKibanaVersion: '8.0.0',
currentOpenSearchDashboardsVersion: '8.0.0',
configTelemetryOptIn: null,
allowChangingOptInStatus: true,
};
Expand All @@ -148,10 +148,10 @@ function getCallGetTelemetryOptInParams(
}

function callGetTelemetryOptIn(params: CallGetTelemetryOptInParams) {
const { currentKibanaVersion, configTelemetryOptIn, allowChangingOptInStatus } = params;
const { currentOpenSearchDashboardsVersion, configTelemetryOptIn, allowChangingOptInStatus } = params;
const telemetrySavedObject = getMockTelemetrySavedObject(params);
return getTelemetryOptIn({
currentKibanaVersion,
currentOpenSearchDashboardsVersion,
telemetrySavedObject,
allowChangingOptInStatus,
configTelemetryOptIn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TelemetrySavedObject } from './types';

interface GetTelemetryOptInConfig {
telemetrySavedObject: TelemetrySavedObject;
currentKibanaVersion: string;
currentOpenSearchDashboardsVersion: string;
allowChangingOptInStatus: boolean;
configTelemetryOptIn: boolean | null;
}
Expand All @@ -31,7 +31,7 @@ type GetTelemetryOptIn = (config: GetTelemetryOptInConfig) => null | boolean;

export const getTelemetryOptIn: GetTelemetryOptIn = ({
telemetrySavedObject,
currentKibanaVersion,
currentOpenSearchDashboardsVersion,
allowChangingOptInStatus,
configTelemetryOptIn,
}) => {
Expand All @@ -53,19 +53,19 @@ export const getTelemetryOptIn: GetTelemetryOptIn = ({
if (savedOptIn === true) return savedOptIn;

// Additional check if they've already opted out (enabled: false):
// - if the Kibana version has changed by at least a minor version,
// - if the OpenSearch Dashboards version has changed by at least a minor version,
// return null to re-prompt.

const lastKibanaVersion = telemetrySavedObject.lastVersionChecked;
const lastOpenSearchDashboardsVersion = telemetrySavedObject.lastVersionChecked;

// if the last kibana version isn't set, or is somehow not a string, return null
if (typeof lastKibanaVersion !== 'string') return null;
// if the last OpenSearch Dashboards version isn't set, or is somehow not a string, return null
if (typeof lastOpenSearchDashboardsVersion !== 'string') return null;

// if version hasn't changed, just return enabled value
if (lastKibanaVersion === currentKibanaVersion) return savedOptIn;
if (lastOpenSearchDashboardsVersion === currentOpenSearchDashboardsVersion) return savedOptIn;

const lastSemver = parseSemver(lastKibanaVersion);
const currentSemver = parseSemver(currentKibanaVersion);
const lastSemver = parseSemver(lastOpenSearchDashboardsVersion);
const currentSemver = parseSemver(currentOpenSearchDashboardsVersion);

// if either version is invalid, return null
if (lastSemver == null || currentSemver == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getTelemetrySendUsageFrom } from './get_telemetry_send_usage_from';
import { TelemetrySavedObject } from './types';

describe('getTelemetrySendUsageFrom', () => {
it('returns kibana.yml config when saved object not found', () => {
it('returns opensearch_dashboards.yml config when saved object not found', () => {
const params: CallGetTelemetryUsageFetcherParams = {
savedObjectNotFound: true,
configSendUsageFrom: 'browser',
Expand All @@ -32,7 +32,7 @@ describe('getTelemetrySendUsageFrom', () => {
expect(result).toBe('browser');
});

it('returns kibana.yml config when saved object forbidden', () => {
it('returns opensearch_dashboards.yml config when saved object forbidden', () => {
const params: CallGetTelemetryUsageFetcherParams = {
savedObjectForbidden: true,
configSendUsageFrom: 'browser',
Expand All @@ -43,7 +43,7 @@ describe('getTelemetrySendUsageFrom', () => {
expect(result).toBe('browser');
});

it('returns kibana.yml config when saved object sendUsageFrom is undefined', () => {
it('returns opensearch_dashboards.yml config when saved object sendUsageFrom is undefined', () => {
const params: CallGetTelemetryUsageFetcherParams = {
savedSendUsagefrom: undefined,
configSendUsageFrom: 'server',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "telemetry",
"version": "kibana",
"version": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": [
Expand All @@ -9,7 +9,7 @@
],
"extraPublicDirs": ["common/constants"],
"requiredBundles": [
"kibanaUtils",
"kibanaReact"
"opensearchDashboardsUtils",
"opensearchDashboardsReact"
]
}
4 changes: 2 additions & 2 deletions src/plugins/telemetry/public/components/opt_in_banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import * as React from 'react';
import { EuiButton, EuiCallOut, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';
import { OptInMessage } from './opt_in_message';

interface Props {
Expand All @@ -32,7 +32,7 @@ export class OptInBanner extends React.PureComponent<Props> {
const title = (
<FormattedMessage
id="telemetry.welcomeBanner.title"
defaultMessage="Help us improve the Elastic Stack"
defaultMessage="Help us improve the OpenSearch Stack"
/>
);
return (
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/telemetry/public/components/opt_in_message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import * as React from 'react';
import { EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';
import { PRIVACY_STATEMENT_URL } from '../../common/constants';

export class OptInMessage extends React.PureComponent {
Expand All @@ -28,7 +28,7 @@ export class OptInMessage extends React.PureComponent {
<React.Fragment>
<FormattedMessage
id="telemetry.telemetryBannerDescription"
defaultMessage="Want to help us improve the Elastic Stack? Data usage collection is currently disabled. Enabling data usage collection helps us manage and improve our products and services. See our {privacyStatementLink} for more details."
defaultMessage="Want to help us improve the OpenSearch Stack? Data usage collection is currently disabled. Enabling data usage collection helps us manage and improve our products and services. See our {privacyStatementLink} for more details."
values={{
privacyStatementLink: (
<EuiLink href={PRIVACY_STATEMENT_URL} target="_blank" rel="noopener">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import * as React from 'react';
import { EuiButton, EuiLink, EuiCallOut, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import { i18n } from '@osd/i18n';
import { PATH_TO_ADVANCED_SETTINGS, PRIVACY_STATEMENT_URL } from '../../common/constants';

interface Props {
Expand All @@ -33,7 +33,7 @@ export class OptedInNoticeBanner extends React.PureComponent<Props> {
render() {
const { onSeenBanner } = this.props;
const bannerTitle = i18n.translate('telemetry.telemetryOptedInNoticeTitle', {
defaultMessage: 'Help us improve the Elastic Stack',
defaultMessage: 'Help us improve the OpenSearch Stack',
});

return (
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/telemetry/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { PluginInitializerContext } from 'opensearch-dashboards/public';
import { TelemetryPlugin, TelemetryPluginConfig } from './plugin';
export { TelemetryPluginStart, TelemetryPluginSetup } from './plugin';

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/telemetry/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { overlayServiceMock } from '../../../core/public/overlays/overlay_service.mock';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { httpServiceMock } from '../../../core/public/http/http_service.mock';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { notificationServiceMock } from '../../../core/public/notifications/notifications_service.mock';
import { TelemetryService } from './services/telemetry_service';
import { TelemetryNotifications } from './services/telemetry_notifications/telemetry_notifications';
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/telemetry/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export interface TelemetryPluginConfig {
}

export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPluginStart> {
private readonly currentKibanaVersion: string;
private readonly currentOpenSearchDashboardsVersion: string;
private readonly config: TelemetryPluginConfig;
private telemetrySender?: TelemetrySender;
private telemetryNotifications?: TelemetryNotifications;
private telemetryService?: TelemetryService;
private canUserChangeSettings: boolean = true;

constructor(initializerContext: PluginInitializerContext<TelemetryPluginConfig>) {
this.currentKibanaVersion = initializerContext.env.packageInfo.version;
this.currentOpenSearchDashboardsVersion = initializerContext.env.packageInfo.version;
this.config = initializerContext.config.get();
}

Expand Down Expand Up @@ -182,7 +182,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
const configTelemetryOptIn = this.config.optIn as boolean;
const configTelemetryAllowChangingOptInStatus = this.config.allowChangingOptInStatus;

const currentKibanaVersion = this.currentKibanaVersion;
const currentOpenSearchDashboardsVersion = this.currentOpenSearchDashboardsVersion;

const allowChangingOptInStatus = getTelemetryAllowChangingOptInStatus({
configTelemetryAllowChangingOptInStatus,
Expand All @@ -193,7 +193,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
configTelemetryOptIn,
allowChangingOptInStatus,
telemetrySavedObject,
currentKibanaVersion,
currentOpenSearchDashboardsVersion,
});

const sendUsageFrom = getTelemetrySendUsageFrom({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { renderOptInBanner } from './render_opt_in_banner';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { overlayServiceMock } from '../../../../../core/public/overlays/overlay_service.mock';

describe.skip('renderOptInBanner', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

import React from 'react';
import { CoreStart } from 'kibana/public';
import { CoreStart } from 'opensearch-dashboards/public';
import { OptInBanner } from '../../components/opt_in_banner';
import { toMountPoint } from '../../../../kibana_react/public';
import { toMountPoint } from '../../../../opensearch_dashboards_react/public';

interface RenderBannerConfig {
overlays: CoreStart['overlays'];
Expand Down
Loading

0 comments on commit e29af53

Please sign in to comment.