Skip to content

Commit 5258d83

Browse files
authored
Enabling UI Metric Collector (#6203)
Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
1 parent 7aa7a74 commit 5258d83

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
108108
- [Workspace] Add workspaces filter to saved objects page. ([#6458](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6458))
109109
- [Multiple Datasource] Support multi data source in Region map ([#6654](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6654))
110110
- Add `rightNavigationButton` component in chrome service for applications to register and add dev tool to top right navigation. ([#6553](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6553))
111+
- Enable UI Metric Collector to collect UI Metrics and Application Usage ([#6203](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6203))
111112

112113
### 🐛 Bug Fixes
113114

config/opensearch_dashboards.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,7 @@
313313

314314
# Set the value to true to enable workspace feature
315315
# workspace.enabled: false
316+
317+
# Set the value to true to enable Ui Metric Collectors in Usage Collector
318+
# This publishes the Application Usage and UI Metrics into the saved object, which can be accessed by /api/stats?extended=true&legacy=true&exclude_usage=false
319+
# usageCollection.uiMetric.enabled: false

packages/osd-analytics/src/reporter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { Report, ReportManager } from './report';
3636
import { ApplicationUsage } from './metrics';
3737

3838
export interface ReporterConfig {
39-
// http: ReportHTTP;
39+
http: ReportHTTP;
4040
storage?: Storage;
4141
checkInterval?: number;
4242
debug?: boolean;
@@ -49,7 +49,7 @@ export class Reporter {
4949
checkInterval: number;
5050
private interval?: NodeJS.Timer;
5151
private lastAppId?: string;
52-
// private http: ReportHTTP;
52+
private http: ReportHTTP;
5353
private reportManager: ReportManager;
5454
private storageManager: ReportStorageManager;
5555
private readonly applicationUsage: ApplicationUsage;
@@ -59,8 +59,8 @@ export class Reporter {
5959
private started = false;
6060

6161
constructor(config: ReporterConfig) {
62-
const { storage, debug, checkInterval = 90000, storageKey = 'analytics' } = config;
63-
// this.http = http;
62+
const { http, storage, debug, checkInterval = 90000, storageKey = 'analytics' } = config;
63+
this.http = http;
6464
this.checkInterval = checkInterval;
6565
this.applicationUsage = new ApplicationUsage();
6666
this.storageManager = new ReportStorageManager(storageKey, storage);
@@ -144,14 +144,14 @@ export class Reporter {
144144
public reportApplicationUsage(appId?: string) {
145145
this.log(`Reporting application changed to ${appId}`);
146146
this.lastAppId = appId || this.lastAppId;
147-
// const appChangedReport = this.applicationUsage.appChanged(appId);
148-
// if (appChangedReport) this.saveToReport([appChangedReport]);
147+
const appChangedReport = this.applicationUsage.appChanged(appId);
148+
if (appChangedReport) this.saveToReport([appChangedReport]);
149149
}
150150

151151
public sendReports = async () => {
152152
if (!this.reportManager.isReportEmpty()) {
153153
try {
154-
// await this.http(this.reportManager.report);
154+
await this.http(this.reportManager.report);
155155
this.flushReport();
156156
} catch (err) {
157157
this.log(`Error Sending Metrics Report ${err}`);

src/plugins/usage_collection/public/services/create_reporter.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ interface AnalyicsReporterConfig {
3838
}
3939

4040
export function createReporter(config: AnalyicsReporterConfig): Reporter {
41-
const { localStorage, debug } = config;
41+
const { localStorage, debug, fetch } = config;
4242

4343
return new Reporter({
4444
debug,
4545
storage: localStorage,
46-
// async http(report) {
47-
// const response = await fetch.post('/api/ui_metric/report', {
48-
// body: JSON.stringify({ report }),
49-
// });
46+
async http(report) {
47+
const response = await fetch.post('/api/ui_metric/report', {
48+
body: JSON.stringify({ report }),
49+
});
5050

51-
// if (response.status !== 'ok') {
52-
// throw Error('Unable to store report.');
53-
// }
54-
// return response;
55-
// },
51+
if (response.status !== 'ok') {
52+
throw Error('Unable to store report.');
53+
}
54+
return response;
55+
},
5656
});
5757
}

src/plugins/usage_collection/server/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { DEFAULT_MAXIMUM_WAIT_TIME_FOR_ALL_COLLECTORS_IN_S } from '../common/con
3434

3535
export const configSchema = schema.object({
3636
uiMetric: schema.object({
37-
enabled: schema.boolean({ defaultValue: true }),
37+
enabled: schema.boolean({ defaultValue: false }),
3838
debug: schema.boolean({ defaultValue: schema.contextRef('dev') }),
3939
}),
4040
maximumWaitTimeForAllCollectorsInS: schema.number({

src/plugins/usage_collection/server/routes/report_metrics.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
* under the License.
2929
*/
3030

31-
// import { schema } from '@osd/config-schema';
31+
import { schema } from '@osd/config-schema';
3232
import { IRouter, ISavedObjectsRepository } from 'opensearch-dashboards/server';
33-
// import { storeReport, reportSchema } from '../report';
33+
import { storeReport, reportSchema } from '../report';
3434

3535
export function registerUiMetricRoute(
3636
router: IRouter,
3737
getSavedObjects: () => ISavedObjectsRepository | undefined
3838
) {
39-
/*
4039
router.post(
4140
{
4241
path: '/api/ui_metric/report',
@@ -59,5 +58,5 @@ export function registerUiMetricRoute(
5958
return res.ok({ body: { status: 'fail' } });
6059
}
6160
}
62-
);*/
61+
);
6362
}

src/plugins/vis_type_vega/server/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { DataSourcePluginSetup } from 'src/plugins/data_source/server';
3333
import { HomeServerPluginSetup } from '../../home/server';
3434
import { UsageCollectionSetup } from '../../usage_collection/server';
3535

36-
export type ConfigObservable = Observable<{ kibana: { index: string } }>;
36+
export type ConfigObservable = Observable<{ opensearchDashboards: { index: string } }>;
3737

3838
export interface VegaSavedObjectAttributes {
3939
title: string;

src/plugins/vis_type_vega/server/usage_collector/get_usage_collector.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const getMockCallCluster = (hits?: unknown[]) =>
8787
jest.fn().mockReturnValue(Promise.resolve({ hits: { hits } }) as unknown) as LegacyAPICaller;
8888

8989
describe('Vega visualization usage collector', () => {
90-
const configMock = of({ kibana: { index: '' } });
90+
const configMock = of({ opensearchDashboards: { index: '' } });
9191
const usageCollector = getUsageCollector(configMock, {
9292
home: ({
9393
sampleData: {

src/plugins/vis_type_vega/server/usage_collector/get_usage_collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function getUsageCollector(
151151
type: VEGA_USAGE_TYPE,
152152
isReady: () => true,
153153
fetch: async (callCluster: LegacyAPICaller) => {
154-
const { index } = (await config.pipe(first()).toPromise()).kibana;
154+
const { index } = (await config.pipe(first()).toPromise()).opensearchDashboards;
155155

156156
return await getStats(callCluster, index, dependencies);
157157
},

0 commit comments

Comments
 (0)