Skip to content

Commit

Permalink
Enabling UI Metric Collectors Signed-off-by: Suchit Sahoo <suchsah@am…
Browse files Browse the repository at this point in the history
…azon.com>
  • Loading branch information
LDrago27 committed Mar 14, 2024
1 parent 03483e4 commit 867e5c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
14 changes: 7 additions & 7 deletions packages/osd-analytics/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { Report, ReportManager } from './report';
import { ApplicationUsage } from './metrics';

export interface ReporterConfig {
// http: ReportHTTP;
http: ReportHTTP;
storage?: Storage;
checkInterval?: number;
debug?: boolean;
Expand All @@ -49,7 +49,7 @@ export class Reporter {
checkInterval: number;
private interval?: NodeJS.Timer;
private lastAppId?: string;
// private http: ReportHTTP;
private http: ReportHTTP;
private reportManager: ReportManager;
private storageManager: ReportStorageManager;
private readonly applicationUsage: ApplicationUsage;
Expand All @@ -59,8 +59,8 @@ export class Reporter {
private started = false;

constructor(config: ReporterConfig) {
const { storage, debug, checkInterval = 90000, storageKey = 'analytics' } = config;
// this.http = http;
const { http, storage, debug, checkInterval = 90000, storageKey = 'analytics' } = config;
this.http = http;
this.checkInterval = checkInterval;
this.applicationUsage = new ApplicationUsage();
this.storageManager = new ReportStorageManager(storageKey, storage);
Expand Down Expand Up @@ -144,14 +144,14 @@ export class Reporter {
public reportApplicationUsage(appId?: string) {
this.log(`Reporting application changed to ${appId}`);
this.lastAppId = appId || this.lastAppId;
// const appChangedReport = this.applicationUsage.appChanged(appId);
// if (appChangedReport) this.saveToReport([appChangedReport]);
const appChangedReport = this.applicationUsage.appChanged(appId);
if (appChangedReport) this.saveToReport([appChangedReport]);
}

public sendReports = async () => {
if (!this.reportManager.isReportEmpty()) {
try {
// await this.http(this.reportManager.report);
await this.http(this.reportManager.report);
this.flushReport();
} catch (err) {
this.log(`Error Sending Metrics Report ${err}`);
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/usage_collection/public/services/create_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ interface AnalyicsReporterConfig {
}

export function createReporter(config: AnalyicsReporterConfig): Reporter {
const { localStorage, debug } = config;
const { localStorage, debug, fetch } = config;

return new Reporter({
debug,
storage: localStorage,
// async http(report) {
// const response = await fetch.post('/api/ui_metric/report', {
// body: JSON.stringify({ report }),
// });
async http(report) {
const response = await fetch.post('/api/ui_metric/report', {
body: JSON.stringify({ report }),
});

// if (response.status !== 'ok') {
// throw Error('Unable to store report.');
// }
// return response;
// },
if (response.status !== 'ok') {
throw Error('Unable to store report.');
}
return response;
},
});
}
7 changes: 3 additions & 4 deletions src/plugins/usage_collection/server/routes/report_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
* under the License.
*/

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

export function registerUiMetricRoute(
router: IRouter,
getSavedObjects: () => ISavedObjectsRepository | undefined
) {
/*
router.post(
{
path: '/api/ui_metric/report',
Expand All @@ -59,5 +58,5 @@ export function registerUiMetricRoute(
return res.ok({ body: { status: 'fail' } });
}
}
);*/
);
}

0 comments on commit 867e5c4

Please sign in to comment.