Skip to content

Commit fec5871

Browse files
committed
Enabling UI Metric Collectors Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
1 parent d2347ca commit fec5871

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5656
- [Dynamic Configurations] Pass request headers when making application config calls ([#6164](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6164))
5757
- [Discover] Options button to configure legacy mode and remove the top navigation option ([#6170](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6170))
5858
- [Multiple Datasource] Add default functionality for customer to choose default datasource ([#6058](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/6058))
59-
59+
- Enable UI Metric Collector to collect UI Metrics and Application Usage ([#6203](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6203))
6060

6161
### 🐛 Bug Fixes
6262

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/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
}

0 commit comments

Comments
 (0)