Skip to content

Commit

Permalink
Respond to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Oct 15, 2019
1 parent 2a28500 commit 16ebf6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/server/usage/collectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function registerLensUsageCollector(

function addEvents(prevEvents: Record<string, number>, newEvents: Record<string, number>) {
Object.keys(newEvents).forEach(key => {
prevEvents[key] = prevEvents[key] || 0 + newEvents[key];
prevEvents[key] = (prevEvents[key] || 0) + newEvents[key];
});
}

Expand Down
13 changes: 8 additions & 5 deletions x-pack/legacy/plugins/lens/server/usage/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import moment from 'moment';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { CoreSetup } from 'src/core/server';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
Expand Down Expand Up @@ -162,13 +163,14 @@ export async function getDailyEvents(
metrics.aggregations!.daily.buckets.forEach(daily => {
const byType: Record<string, number> = byDateByType[daily.key] || {};
daily.groups.buckets.regularEvents.names.buckets.forEach(bucket => {
byType[bucket.key] = bucket.sums.value || 0 + (byType[daily.key] || 0);
byType[bucket.key] = (bucket.sums.value || 0) + (byType[daily.key] || 0);
});
byDateByType[daily.key] = byType;

const suggestionsByType: Record<string, number> = suggestionsByDate[daily.key] || {};
daily.groups.buckets.suggestionEvents.names.buckets.forEach(bucket => {
suggestionsByType[bucket.key] = bucket.sums.value || 0 + (suggestionsByType[daily.key] || 0);
suggestionsByType[bucket.key] =
(bucket.sums.value || 0) + (suggestionsByType[daily.key] || 0);
});
suggestionsByDate[daily.key] = suggestionsByType;
});
Expand Down Expand Up @@ -228,8 +230,9 @@ export function telemetryTaskRunner(server: Server) {
}

function getNextMidnight() {
const nextMidnight = new Date();
nextMidnight.setHours(0, 0, 0, 0);
nextMidnight.setDate(nextMidnight.getDate() + 1);
const nextMidnight = moment()
.add(1, 'day')
.startOf('day')
.valueOf();
return nextMidnight;
}
4 changes: 3 additions & 1 deletion x-pack/test/api_integration/apis/lens/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export default ({ getService }: FtrProviderContext) => {
{ index: { _index: '.kibana' } },
getEvent('load', date1),
{ index: { _index: '.kibana' } },
getEvent('load', date1),
{ index: { _index: '.kibana' } },
getEvent('load', date2),
{ index: { _index: '.kibana' } },
getEvent('revert', date1, 'suggestion'),
Expand All @@ -164,7 +166,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(result).to.eql({
byDate: {
[date1]: {
load: 10,
load: 15,
},
[date2]: {
load: 5,
Expand Down

0 comments on commit 16ebf6c

Please sign in to comment.