Skip to content

Commit 5551966

Browse files
Maja Grubickibanamachine
andauthored
[Advanced Settings] Introducing telemetry (#82860)
* [Advaned Settings] Introducing telemetry * Publishing doc changes * Move metric tracking to onSave method * Adding deprecated warning * Updating docs Co-authored-by: Kibana Machine <[email protected]>
1 parent c3e5794 commit 5551966

File tree

17 files changed

+109
-6
lines changed

17 files changed

+109
-6
lines changed

docs/development/core/public/kibana-plugin-core-public.uisettingsparams.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface UiSettingsParams<T = unknown>
1919
| [category](./kibana-plugin-core-public.uisettingsparams.category.md) | <code>string[]</code> | used to group the configured setting in the UI |
2020
| [deprecation](./kibana-plugin-core-public.uisettingsparams.deprecation.md) | <code>DeprecationSettings</code> | optional deprecation information. Used to generate a deprecation warning. |
2121
| [description](./kibana-plugin-core-public.uisettingsparams.description.md) | <code>string</code> | description provided to a user in UI |
22+
| [metric](./kibana-plugin-core-public.uisettingsparams.metric.md) | <code>{</code><br/><code> type: UiStatsMetricType;</code><br/><code> name: string;</code><br/><code> }</code> | Metric to track once this property changes |
2223
| [name](./kibana-plugin-core-public.uisettingsparams.name.md) | <code>string</code> | title in the UI |
2324
| [optionLabels](./kibana-plugin-core-public.uisettingsparams.optionlabels.md) | <code>Record&lt;string, string&gt;</code> | text labels for 'select' type UI element |
2425
| [options](./kibana-plugin-core-public.uisettingsparams.options.md) | <code>string[]</code> | array of permitted values for this setting |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [UiSettingsParams](./kibana-plugin-core-public.uisettingsparams.md) &gt; [metric](./kibana-plugin-core-public.uisettingsparams.metric.md)
4+
5+
## UiSettingsParams.metric property
6+
7+
> Warning: This API is now obsolete.
8+
>
9+
> Temporary measure until https://github.com/elastic/kibana/issues/83084 is in place
10+
>
11+
12+
Metric to track once this property changes
13+
14+
<b>Signature:</b>
15+
16+
```typescript
17+
metric?: {
18+
type: UiStatsMetricType;
19+
name: string;
20+
};
21+
```

docs/development/core/server/kibana-plugin-core-server.uisettingsparams.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface UiSettingsParams<T = unknown>
1919
| [category](./kibana-plugin-core-server.uisettingsparams.category.md) | <code>string[]</code> | used to group the configured setting in the UI |
2020
| [deprecation](./kibana-plugin-core-server.uisettingsparams.deprecation.md) | <code>DeprecationSettings</code> | optional deprecation information. Used to generate a deprecation warning. |
2121
| [description](./kibana-plugin-core-server.uisettingsparams.description.md) | <code>string</code> | description provided to a user in UI |
22+
| [metric](./kibana-plugin-core-server.uisettingsparams.metric.md) | <code>{</code><br/><code> type: UiStatsMetricType;</code><br/><code> name: string;</code><br/><code> }</code> | Metric to track once this property changes |
2223
| [name](./kibana-plugin-core-server.uisettingsparams.name.md) | <code>string</code> | title in the UI |
2324
| [optionLabels](./kibana-plugin-core-server.uisettingsparams.optionlabels.md) | <code>Record&lt;string, string&gt;</code> | text labels for 'select' type UI element |
2425
| [options](./kibana-plugin-core-server.uisettingsparams.options.md) | <code>string[]</code> | array of permitted values for this setting |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [UiSettingsParams](./kibana-plugin-core-server.uisettingsparams.md) &gt; [metric](./kibana-plugin-core-server.uisettingsparams.metric.md)
4+
5+
## UiSettingsParams.metric property
6+
7+
> Warning: This API is now obsolete.
8+
>
9+
> Temporary measure until https://github.com/elastic/kibana/issues/83084 is in place
10+
>
11+
12+
Metric to track once this property changes
13+
14+
<b>Signature:</b>
15+
16+
```typescript
17+
metric?: {
18+
type: UiStatsMetricType;
19+
name: string;
20+
};
21+
```

src/core/public/public.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
3838
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
3939
import { Type } from '@kbn/config-schema';
4040
import { TypeOf } from '@kbn/config-schema';
41+
import { UiStatsMetricType } from '@kbn/analytics';
4142
import { UnregisterCallback } from 'history';
4243
import { UserProvidedValues as UserProvidedValues_2 } from 'src/core/server/types';
4344

@@ -1362,6 +1363,11 @@ export interface UiSettingsParams<T = unknown> {
13621363
// Warning: (ae-forgotten-export) The symbol "DeprecationSettings" needs to be exported by the entry point index.d.ts
13631364
deprecation?: DeprecationSettings;
13641365
description?: string;
1366+
// @deprecated
1367+
metric?: {
1368+
type: UiStatsMetricType;
1369+
name: string;
1370+
};
13651371
name?: string;
13661372
optionLabels?: Record<string, string>;
13671373
options?: string[];

src/core/server/server.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
160160
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
161161
import { Type } from '@kbn/config-schema';
162162
import { TypeOf } from '@kbn/config-schema';
163+
import { UiStatsMetricType } from '@kbn/analytics';
163164
import { UpdateDocumentByQueryParams } from 'elasticsearch';
164165
import { UpdateDocumentParams } from 'elasticsearch';
165166
import { URL } from 'url';
@@ -2746,6 +2747,11 @@ export interface UiSettingsParams<T = unknown> {
27462747
category?: string[];
27472748
deprecation?: DeprecationSettings;
27482749
description?: string;
2750+
// @deprecated
2751+
metric?: {
2752+
type: UiStatsMetricType;
2753+
name: string;
2754+
};
27492755
name?: string;
27502756
optionLabels?: Record<string, string>;
27512757
options?: string[];

src/core/types/ui_settings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919
import { Type } from '@kbn/config-schema';
20+
import { UiStatsMetricType } from '@kbn/analytics';
2021

2122
/**
2223
* UI element type to represent the settings.
@@ -80,6 +81,15 @@ export interface UiSettingsParams<T = unknown> {
8081
* Used to validate value on write and read.
8182
*/
8283
schema: Type<T>;
84+
/**
85+
* Metric to track once this property changes
86+
* @deprecated
87+
* Temporary measure until https://github.com/elastic/kibana/issues/83084 is in place
88+
*/
89+
metric?: {
90+
type: UiStatsMetricType;
91+
name: string;
92+
};
8393
}
8494

8595
/**

src/plugins/advanced_settings/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"server": true,
55
"ui": true,
66
"requiredPlugins": ["management"],
7-
"optionalPlugins": ["home"],
7+
"optionalPlugins": ["home", "usageCollection"],
88
"requiredBundles": ["kibanaReact", "home"]
99
}

src/plugins/advanced_settings/public/management_app/advanced_settings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Subscription } from 'rxjs';
2222
import { Comparators, EuiFlexGroup, EuiFlexItem, EuiSpacer, Query } from '@elastic/eui';
2323

2424
import { useParams } from 'react-router-dom';
25+
import { UiStatsMetricType } from '@kbn/analytics';
2526
import { CallOuts } from './components/call_outs';
2627
import { Search } from './components/search';
2728
import { Form } from './components/form';
@@ -39,6 +40,7 @@ interface AdvancedSettingsProps {
3940
dockLinks: DocLinksStart['links'];
4041
toasts: ToastsStart;
4142
componentRegistry: ComponentRegistry['start'];
43+
trackUiMetric?: (metricType: UiStatsMetricType, eventName: string | string[]) => void;
4244
}
4345

4446
interface AdvancedSettingsComponentProps extends AdvancedSettingsProps {
@@ -241,6 +243,7 @@ export class AdvancedSettingsComponent extends Component<
241243
enableSaving={this.props.enableSaving}
242244
dockLinks={this.props.dockLinks}
243245
toasts={this.props.toasts}
246+
trackUiMetric={this.props.trackUiMetric}
244247
/>
245248
<PageFooter
246249
toasts={this.props.toasts}
@@ -263,6 +266,7 @@ export const AdvancedSettings = (props: AdvancedSettingsProps) => {
263266
dockLinks={props.dockLinks}
264267
toasts={props.toasts}
265268
componentRegistry={props.componentRegistry}
269+
trackUiMetric={props.trackUiMetric}
266270
/>
267271
);
268272
};

src/plugins/advanced_settings/public/management_app/components/form/form.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
import { FormattedMessage } from '@kbn/i18n/react';
3737
import { isEmpty } from 'lodash';
3838
import { i18n } from '@kbn/i18n';
39+
import { UiStatsMetricType } from '@kbn/analytics';
3940
import { toMountPoint } from '../../../../../kibana_react/public';
4041
import { DocLinksStart, ToastsStart } from '../../../../../../core/public';
4142

@@ -56,6 +57,7 @@ interface FormProps {
5657
enableSaving: boolean;
5758
dockLinks: DocLinksStart['links'];
5859
toasts: ToastsStart;
60+
trackUiMetric?: (metricType: UiStatsMetricType, eventName: string | string[]) => void;
5961
}
6062

6163
interface FormState {
@@ -149,7 +151,7 @@ export class Form extends PureComponent<FormProps> {
149151
if (!setting) {
150152
return;
151153
}
152-
const { defVal, type, requiresPageReload } = setting;
154+
const { defVal, type, requiresPageReload, metric } = setting;
153155
let valueToSave = value;
154156
let equalsToDefault = false;
155157
switch (type) {
@@ -163,6 +165,11 @@ export class Form extends PureComponent<FormProps> {
163165
const isArray = Array.isArray(JSON.parse((defVal as string) || '{}'));
164166
valueToSave = valueToSave.trim();
165167
valueToSave = valueToSave || (isArray ? '[]' : '{}');
168+
case 'boolean':
169+
if (metric && this.props.trackUiMetric) {
170+
const metricName = valueToSave ? `${metric.name}_on` : `${metric.name}_off`;
171+
this.props.trackUiMetric(metric.type, metricName);
172+
}
166173
default:
167174
equalsToDefault = valueToSave === defVal;
168175
}

0 commit comments

Comments
 (0)