mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Telemetry] fix bug where uiStatsMetrics is not getting report… (#54045)
* fix bug where uiStatsMetrics is not getting reported * fix tests
This commit is contained in:
parent
fa8da7c349
commit
ecab2073ae
2 changed files with 21 additions and 29 deletions
|
@ -78,6 +78,7 @@ export class ReportManager {
|
|||
}
|
||||
assignReports(newMetrics: Metric | Metric[]) {
|
||||
wrapArray(newMetrics).forEach(newMetric => this.assignReport(this.report, newMetric));
|
||||
return { report: this.report };
|
||||
}
|
||||
static createMetricKey(metric: Metric): string {
|
||||
switch (metric.type) {
|
||||
|
@ -101,7 +102,7 @@ export class ReportManager {
|
|||
case METRIC_TYPE.USER_AGENT: {
|
||||
const { appName, type, userAgent } = metric;
|
||||
if (userAgent) {
|
||||
this.report.userAgent = {
|
||||
report.userAgent = {
|
||||
[key]: {
|
||||
key,
|
||||
appName,
|
||||
|
@ -110,23 +111,22 @@ export class ReportManager {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case METRIC_TYPE.CLICK:
|
||||
case METRIC_TYPE.LOADED:
|
||||
case METRIC_TYPE.COUNT: {
|
||||
const { appName, type, eventName, count } = metric;
|
||||
if (report.uiStatsMetrics) {
|
||||
const existingStats = (report.uiStatsMetrics[key] || {}).stats;
|
||||
this.report.uiStatsMetrics = this.report.uiStatsMetrics || {};
|
||||
this.report.uiStatsMetrics[key] = {
|
||||
key,
|
||||
appName,
|
||||
eventName,
|
||||
type,
|
||||
stats: this.incrementStats(count, existingStats),
|
||||
};
|
||||
}
|
||||
report.uiStatsMetrics = report.uiStatsMetrics || {};
|
||||
const existingStats = (report.uiStatsMetrics[key] || {}).stats;
|
||||
report.uiStatsMetrics[key] = {
|
||||
key,
|
||||
appName,
|
||||
eventName,
|
||||
type,
|
||||
stats: this.incrementStats(count, existingStats),
|
||||
};
|
||||
return;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -25,15 +25,13 @@ export default function({ getService }) {
|
|||
const es = getService('legacyEs');
|
||||
|
||||
const createStatsMetric = eventName => ({
|
||||
key: ReportManager.createMetricKey({ appName: 'myApp', type: METRIC_TYPE.CLICK, eventName }),
|
||||
eventName,
|
||||
appName: 'myApp',
|
||||
type: METRIC_TYPE.CLICK,
|
||||
stats: { sum: 1, avg: 1, min: 1, max: 1 },
|
||||
count: 1,
|
||||
});
|
||||
|
||||
const createUserAgentMetric = appName => ({
|
||||
key: ReportManager.createMetricKey({ appName, type: METRIC_TYPE.USER_AGENT }),
|
||||
appName,
|
||||
type: METRIC_TYPE.USER_AGENT,
|
||||
userAgent:
|
||||
|
@ -42,12 +40,9 @@ export default function({ getService }) {
|
|||
|
||||
describe('ui_metric API', () => {
|
||||
it('increments the count field in the document defined by the {app}/{action_type} path', async () => {
|
||||
const reportManager = new ReportManager();
|
||||
const uiStatsMetric = createStatsMetric('myEvent');
|
||||
const report = {
|
||||
uiStatsMetrics: {
|
||||
[uiStatsMetric.key]: uiStatsMetric,
|
||||
},
|
||||
};
|
||||
const { report } = reportManager.assignReports([uiStatsMetric]);
|
||||
await supertest
|
||||
.post('/api/ui_metric/report')
|
||||
.set('kbn-xsrf', 'kibana')
|
||||
|
@ -61,21 +56,18 @@ export default function({ getService }) {
|
|||
});
|
||||
|
||||
it('supports multiple events', async () => {
|
||||
const reportManager = new ReportManager();
|
||||
const userAgentMetric = createUserAgentMetric('kibana');
|
||||
const uiStatsMetric1 = createStatsMetric('myEvent');
|
||||
const hrTime = process.hrtime();
|
||||
const nano = hrTime[0] * 1000000000 + hrTime[1];
|
||||
const uniqueEventName = `myEvent${nano}`;
|
||||
const uiStatsMetric2 = createStatsMetric(uniqueEventName);
|
||||
const report = {
|
||||
userAgent: {
|
||||
[userAgentMetric.key]: userAgentMetric,
|
||||
},
|
||||
uiStatsMetrics: {
|
||||
[uiStatsMetric1.key]: uiStatsMetric1,
|
||||
[uiStatsMetric2.key]: uiStatsMetric2,
|
||||
},
|
||||
};
|
||||
const { report } = reportManager.assignReports([
|
||||
userAgentMetric,
|
||||
uiStatsMetric1,
|
||||
uiStatsMetric2,
|
||||
]);
|
||||
await supertest
|
||||
.post('/api/ui_metric/report')
|
||||
.set('kbn-xsrf', 'kibana')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue