Skip to content

Commit

Permalink
EDD-46: Add logging of metrics to EDD (#32)
Browse files Browse the repository at this point in the history
* EDD-46 Added logging for Pause, Resume, Restart, and Completed downloads

* EDD-46 Added EDL retrieval and totalFiles, downloadedFiles metrics

* EDD-46 Updating logging endpoint

* EDD-46 single line

* EDD-46 Bumping version

* EDD-46 Bumping version

* EDD-46 Updating metricsLogger test

* EDD-46 PR feedback changes

* EDD-46 Updating metricsLogger

* EDD-46 adding download and file info to pause/resume/restart/cancel

* EDD-46 ts-check

* EDD-46 Setting endpoint to UAT

* EDD-46 Overhauled previous metrics. Added new metrics to reflect desired tracked events

* EDD-46 Updating setPreferences test

* EDD-46 Updating setPreferences test

* EDD-46 Added some new db tests

* EDD-46 Adding more db tests

* EDD-46 PR feedback

* EDD-46 Removing axios package

* EDD-46 metric and test updates

* EDD-46 Adding test assertions

* EDD-46 Updating tests

* EDD-46 Moved database call to reports section

* EDD-46 Removing deprecated db calls

* EDD-46 Addressing PR feedback

* EDD-46 Test assertion change

* EDD-46 Metric location updates and db call adjustments

* EDD-46 added downloadIdForMetrics and download pause count

* EDD-46 import change

* EDD-46 PR Feedback

* EDD-46 Addressing PR comments

* EDD-46 Addressing PR feedback

* EDD-46 Addressing PR feedback

* EDD-46 Addressing PR feedback

* EDD-46 Adding test assertion

* EDD-46 Test adjustments

* EDD-46 Addressing PR feedback

* EDD-46 Updating windowStateKeeper

* EDD-46 Added expect

---------

Co-authored-by: drewpesall <[email protected]>
  • Loading branch information
dpesall and drewpesall authored Dec 5, 2023
1 parent 50bfa05 commit 694690a
Show file tree
Hide file tree
Showing 29 changed files with 907 additions and 45 deletions.
43 changes: 24 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "earthdata-download",
"version": "0.1.0",
"version": "0.1.1",
"description": "Earthdata Download is a cross-platform download manager designed to improve how users download Earth Science data. It accepts lists of files from applications like Earthdata Search (https://search.earthdata.nasa.gov/) and enables clients to offer users a streamlined experience when downloading files from their browser.",
"repository": "nasa/earthdata-download",
"homepage": "https://github.com/nasa/earthdata-download#readme",
Expand Down
4 changes: 4 additions & 0 deletions src/main/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"note": "This endpoint is for EDSC-UAT CloudWatch",
"logging": "https://dycghwhsgr9el.cloudfront.net/edd_logger"
}
32 changes: 32 additions & 0 deletions src/main/eventHandlers/__tests__/cancelDownloadItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import MockDate from 'mockdate'
import cancelDownloadItem from '../cancelDownloadItem'

import downloadStates from '../../../app/constants/downloadStates'
import metricsLogger from '../../utils/metricsLogger.ts'

beforeEach(() => {
MockDate.set('2023-05-01')
})

jest.mock('../../utils/metricsLogger.ts', () => ({
__esModule: true,
default: jest.fn(() => {})
}))

describe('cancelDownloadItem', () => {
describe('when downloadId and name are provided', () => {
test('updates the file state', async () => {
Expand All @@ -34,6 +40,14 @@ describe('cancelDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadItemCancel',
data: {
downloadId: 'mock-download-id'
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith('mock-download-id', 'mock-filename.png')

Expand Down Expand Up @@ -76,6 +90,15 @@ describe('cancelDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadCancel',
data: {
downloadIds: ['mock-download-id'],
cancelCount: 1
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith('mock-download-id', undefined)

Expand Down Expand Up @@ -125,6 +148,15 @@ describe('cancelDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadCancel',
data: {
downloadIds: [123, 456],
cancelCount: 2
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith(undefined, undefined)

Expand Down
37 changes: 34 additions & 3 deletions src/main/eventHandlers/__tests__/pauseDownloadItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import pauseDownloadItem from '../pauseDownloadItem'
import downloadStates from '../../../app/constants/downloadStates'
import metricsLogger from '../../utils/metricsLogger.ts'

jest.mock('../../utils/metricsLogger.ts', () => ({
__esModule: true,
default: jest.fn(() => {})
}))

describe('pauseDownloadItem', () => {
describe('when downloadId and name are provided', () => {
Expand All @@ -19,7 +25,9 @@ describe('pauseDownloadItem', () => {
updateFilesWhere: jest.fn(),
createPauseByDownloadIdAndFilename: jest.fn(),
createPauseByDownloadId: jest.fn(),
createPauseForAllActiveDownloads: jest.fn()
createPauseForAllActiveDownloads: jest.fn().mockResolvedValue({
pausedIds: ['mock-download-id-1', 'mock-download-id-2']
})
}

await pauseDownloadItem({
Expand All @@ -28,6 +36,8 @@ describe('pauseDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(0)

expect(currentDownloadItems.pauseItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.pauseItem).toHaveBeenCalledWith('mock-download-id', 'mock-filename.png')

Expand Down Expand Up @@ -63,7 +73,9 @@ describe('pauseDownloadItem', () => {
updateFilesWhere: jest.fn(),
createPauseByDownloadIdAndFilename: jest.fn(),
createPauseByDownloadId: jest.fn(),
createPauseForAllActiveDownloads: jest.fn()
createPauseForAllActiveDownloads: jest.fn().mockResolvedValue({
pausedIds: ['mock-download-id-1', 'mock-download-id-2']
})
}

await pauseDownloadItem({
Expand All @@ -72,6 +84,15 @@ describe('pauseDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadPause',
data: {
downloadCount: 1,
downloadIds: ['mock-download-id']
}
})

expect(currentDownloadItems.pauseItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.pauseItem).toHaveBeenCalledWith('mock-download-id', undefined)

Expand Down Expand Up @@ -101,7 +122,9 @@ describe('pauseDownloadItem', () => {
updateFilesWhere: jest.fn(),
createPauseByDownloadIdAndFilename: jest.fn(),
createPauseByDownloadId: jest.fn(),
createPauseForAllActiveDownloads: jest.fn()
createPauseForAllActiveDownloads: jest.fn().mockResolvedValue({
pausedIds: ['mock-download-id-1', 'mock-download-id-2']
})
}

await pauseDownloadItem({
Expand All @@ -110,6 +133,14 @@ describe('pauseDownloadItem', () => {
info
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadPause',
data: {
downloadIds: ['mock-download-id-1', 'mock-download-id-2']
}
})

expect(currentDownloadItems.pauseItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.pauseItem).toHaveBeenCalledWith(undefined, undefined)

Expand Down
60 changes: 57 additions & 3 deletions src/main/eventHandlers/__tests__/restartDownload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import downloadStates from '../../../app/constants/downloadStates'
import restartDownload from '../restartDownload'

import startNextDownload from '../../utils/startNextDownload'
import metricsLogger from '../../utils/metricsLogger'

jest.mock('../../utils/startNextDownload', () => ({
__esModule: true,
default: jest.fn(() => {})
}))

jest.mock('../../utils/metricsLogger.ts', () => ({
__esModule: true,
default: jest.fn(() => {})
}))

beforeEach(() => {
MockDate.set('2023-05-01')

Expand All @@ -32,7 +38,11 @@ describe('restartDownload', () => {
updateDownloadById: jest.fn(),
updateFilesWhere: jest.fn(),
deletePausesByDownloadIdAndFilename: jest.fn(),
deleteAllPausesByDownloadId: jest.fn()
deleteAllPausesByDownloadId: jest.fn(),
getDownloadReport: jest.fn().mockResolvedValue({
finishedFiles: 8,
totalFiles: 10
})
}
const downloadIdContext = {}
const webContents = {}
Expand All @@ -49,6 +59,16 @@ describe('restartDownload', () => {
webContents
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadRestart',
data: {
downloadId: 'mock-download-id',
filesCompleted: 8,
filesInProgress: 2
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith('mock-download-id', undefined)

Expand All @@ -57,6 +77,8 @@ describe('restartDownload', () => {

expect(database.deletePausesByDownloadIdAndFilename).toHaveBeenCalledTimes(0)

expect(database.getDownloadReport).toHaveBeenCalledTimes(1)

expect(database.deleteAllPausesByDownloadId).toHaveBeenCalledTimes(1)
expect(database.deleteAllPausesByDownloadId).toHaveBeenCalledWith('mock-download-id')

Expand Down Expand Up @@ -111,7 +133,11 @@ describe('restartDownload', () => {
updateDownloadById: jest.fn(),
updateFilesWhere: jest.fn(),
deletePausesByDownloadIdAndFilename: jest.fn(),
deleteAllPausesByDownloadId: jest.fn()
deleteAllPausesByDownloadId: jest.fn(),
getDownloadReport: jest.fn().mockResolvedValue({
finishedFiles: 8,
totalFiles: 10
})
}
const downloadIdContext = {}
const webContents = {}
Expand All @@ -129,6 +155,16 @@ describe('restartDownload', () => {
webContents
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadRestart',
data: {
downloadId: 'mock-download-id',
filesCompleted: 8,
filesInProgress: 2
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith('mock-download-id', 'mock-filename')

Expand All @@ -142,6 +178,8 @@ describe('restartDownload', () => {

expect(database.deleteAllPausesByDownloadId).toHaveBeenCalledTimes(0)

expect(database.getDownloadReport).toHaveBeenCalledTimes(1)

expect(database.updateFilesWhere).toHaveBeenCalledTimes(2)
expect(database.updateFilesWhere).toHaveBeenCalledWith({
restartId: 'mock-restart-id'
Expand Down Expand Up @@ -188,7 +226,11 @@ describe('restartDownload', () => {
updateDownloadById: jest.fn(),
updateFilesWhere: jest.fn(),
deletePausesByDownloadIdAndFilename: jest.fn(),
deleteAllPausesByDownloadId: jest.fn()
deleteAllPausesByDownloadId: jest.fn(),
getDownloadReport: jest.fn().mockResolvedValue({
finishedFiles: 8,
totalFiles: 10
})
}
const downloadIdContext = {}
const webContents = {}
Expand All @@ -206,12 +248,24 @@ describe('restartDownload', () => {
webContents
})

expect(metricsLogger).toHaveBeenCalledTimes(1)
expect(metricsLogger).toHaveBeenCalledWith({
eventType: 'DownloadRestart',
data: {
downloadId: 'mock-download-id',
filesCompleted: 8,
filesInProgress: 2
}
})

expect(currentDownloadItems.cancelItem).toHaveBeenCalledTimes(1)
expect(currentDownloadItems.cancelItem).toHaveBeenCalledWith('mock-download-id', 'mock-filename')

expect(database.getDownloadById).toHaveBeenCalledTimes(1)
expect(database.getDownloadById).toHaveBeenCalledWith('mock-download-id')

expect(database.getDownloadReport).toHaveBeenCalledTimes(1)

expect(database.createPauseWith).toHaveBeenCalledTimes(1)
expect(database.createPauseWith).toHaveBeenCalledWith({
downloadId: 'mock-download-id',
Expand Down
Loading

0 comments on commit 694690a

Please sign in to comment.