-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telemetry] collect number of visualization saved in the past 7, 30 a…
…nd 90 days (#67865) * Update telemetry for visualizations to also count the vis from the past 30 and 90 days * Also add metrics for the saved visualizations for the past 7 days Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
e66eaf7
commit fcab974
Showing
5 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/oss_telemetry/server/lib/get_past_days.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import { getPastDays } from './get_past_days'; | ||
|
||
describe('getPastDays', () => { | ||
test('Returns 2 days that have passed from the current date', () => { | ||
const pastDate = moment().subtract(2, 'days').startOf('day').toString(); | ||
|
||
expect(getPastDays(pastDate)).toEqual(2); | ||
}); | ||
|
||
test('Returns 30 days that have passed from the current date', () => { | ||
const pastDate = moment().subtract(30, 'days').startOf('day').toString(); | ||
|
||
expect(getPastDays(pastDate)).toEqual(30); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
export const getPastDays = (dateString: string): number => { | ||
const date = new Date(dateString); | ||
const today = new Date(); | ||
const diff = Math.abs(date.getTime() - today.getTime()); | ||
return Math.trunc(diff / (1000 * 60 * 60 * 24)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters