-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing route to trigger new task
- Loading branch information
1 parent
f0bf108
commit 5c1a6da
Showing
3 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/security_solution/server/lib/telemetry/routes/index.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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import type { Logger, IRouter } from '@kbn/core/server'; | ||
import type { ITelemetryReceiver } from '../receiver'; | ||
import type { ITelemetryEventsSender } from '../sender'; | ||
import { TaskMetricsService } from '../task_metrics'; | ||
import { createTelemetryIndicesMetadataTaskConfig } from '../tasks/indices.metadata'; | ||
|
||
// TODO: just to test the POC, remove | ||
export const getTriggerIndicesMetadataTaskRoute = ( | ||
router: IRouter, | ||
logger: Logger, | ||
receiver: ITelemetryReceiver, | ||
sender: ITelemetryEventsSender | ||
) => { | ||
router.get( | ||
{ | ||
path: '/internal/trigger-indices-metadata-task', | ||
validate: false, | ||
}, | ||
async (_context, _request, response) => { | ||
const taskMetricsService = new TaskMetricsService(logger, sender); | ||
const task = createTelemetryIndicesMetadataTaskConfig(); | ||
const timeStart = performance.now(); | ||
let msgSuffix = ''; | ||
if (global.gc) { | ||
global.gc(); | ||
} else { | ||
msgSuffix = ' (Note: Garbage collection is not exposed. Start Node.js with --expose-gc.)'; | ||
} | ||
const initialMemory = process.memoryUsage().heapUsed; | ||
const result = await task.runTask('id', logger, receiver, sender, taskMetricsService, { | ||
last: 'last', | ||
current: 'current', | ||
}); | ||
const memoryUsed = process.memoryUsage().heapUsed - initialMemory; | ||
const elapsedTime = performance.now() - timeStart; | ||
|
||
return response.ok({ | ||
body: { | ||
message: `Task processed ${result} datastreams. It took ${elapsedTime} ms to run and required ${memoryUsed} bytes ${msgSuffix}`, | ||
}, | ||
}); | ||
} | ||
); | ||
}; |
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