-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Cases] Incremental id telemetry and config improvements #226935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
janmonschke
merged 3 commits into
elastic:main
from
janmonschke:cases/incremental-id-telemetry-config
Jul 9, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
x-pack/platform/plugins/shared/cases/common/constants/incremental_id.ts
This file contains hidden or 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,9 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export const DEFAULT_TASK_INTERVAL_MINUTES = 10; | ||
| export const DEFAULT_TASK_START_DELAY_MINUTES = 10; |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ import { | |
| type TaskManagerSetupContract, | ||
| type TaskManagerStartContract, | ||
| } from '@kbn/task-manager-plugin/server'; | ||
| import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; | ||
| import type { IUsageCounter } from '@kbn/usage-collection-plugin/server/usage_counters/usage_counter'; | ||
| import { CASE_SAVED_OBJECT, CASE_ID_INCREMENTER_SAVED_OBJECT } from '../../../common/constants'; | ||
| import { CasesIncrementalIdService } from '../../services/incremental_id'; | ||
| import type { ConfigType } from '../../config'; | ||
|
|
@@ -24,16 +26,21 @@ export class IncrementalIdTaskManager { | |
| private logger: Logger; | ||
| private internalSavedObjectsClient?: SavedObjectsClient; | ||
| private taskManager?: TaskManagerStartContract; | ||
|
|
||
| private successErrorUsageCounter?: IUsageCounter; | ||
| constructor( | ||
| taskManager: TaskManagerSetupContract, | ||
| config: ConfigType['incrementalId'], | ||
| logger: Logger | ||
| logger: Logger, | ||
| usageCollection?: UsageCollectionSetup | ||
| ) { | ||
| this.config = config; | ||
| this.logger = logger.get('incremental_id_task'); | ||
| this.logger.info('Registering Case Incremental ID Task Manager'); | ||
|
|
||
| if (usageCollection) { | ||
| this.successErrorUsageCounter = usageCollection?.createUsageCounter('CasesIncrementalId'); | ||
| } | ||
|
|
||
| taskManager.registerTaskDefinitions({ | ||
| [CASES_INCREMENTAL_ID_SYNC_TASK_TYPE]: { | ||
| title: 'Cases Numerical ID assignment', | ||
|
|
@@ -64,20 +71,32 @@ export class IncrementalIdTaskManager { | |
| this.logger.debug( | ||
| `${casesWithoutIncrementalId.length} cases without incremental ids` | ||
| ); | ||
| // Increment the case ids | ||
| const processedAmount = await casesIncrementService.incrementCaseIds( | ||
| casesWithoutIncrementalId | ||
| ); | ||
| this.logger.debug( | ||
| `Applied incremental ids to ${processedAmount} out of ${casesWithoutIncrementalId.length} cases` | ||
| ); | ||
|
|
||
| const endTime = performance.now(); | ||
| this.logger.debug( | ||
| `Task terminated ${CASES_INCREMENTAL_ID_SYNC_TASK_ID}. Task run took ${ | ||
| endTime - startTime | ||
| }ms [ started: ${initializedTime}, ended: ${new Date().toISOString()} ]` | ||
| ); | ||
| try { | ||
| // Increment the case ids | ||
| const processedAmount = await casesIncrementService.incrementCaseIds( | ||
| casesWithoutIncrementalId | ||
| ); | ||
| this.logger.debug( | ||
| `Applied incremental ids to ${processedAmount} out of ${casesWithoutIncrementalId.length} cases` | ||
| ); | ||
|
|
||
| const endTime = performance.now(); | ||
| this.logger.debug( | ||
| `Task terminated ${CASES_INCREMENTAL_ID_SYNC_TASK_ID}. Task run took ${ | ||
| endTime - startTime | ||
| }ms [ started: ${initializedTime}, ended: ${new Date().toISOString()} ]` | ||
| ); | ||
| this.successErrorUsageCounter?.incrementCounter({ | ||
| counterName: 'incrementIdTaskSuccess', | ||
| incrementBy: 1, | ||
| }); | ||
| } catch (_) { | ||
| this.successErrorUsageCounter?.incrementCounter({ | ||
| counterName: 'incrementIdTaskError', | ||
| incrementBy: 1, | ||
| }); | ||
|
Comment on lines
+90
to
+98
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual change |
||
| } | ||
| }, | ||
| cancel: async () => { | ||
| casesIncrementService.stopService(); | ||
|
|
@@ -125,7 +144,7 @@ export class IncrementalIdTaskManager { | |
| id: CASES_INCREMENTAL_ID_SYNC_TASK_ID, | ||
| taskType: CASES_INCREMENTAL_ID_SYNC_TASK_TYPE, | ||
| // start delayed to give the system some time to start up properly | ||
| runAt: new Date(new Date().getTime() + this.config.taskIntervalMinutes * 60 * 1000), | ||
| runAt: new Date(new Date().getTime() + this.config.taskStartDelayMinutes * 60 * 1000), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was forgotten in a previous PR |
||
| schedule: { | ||
| interval: `${this.config.taskIntervalMinutes}m`, | ||
| }, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapped this in a
try/catch, therefore the whitespace changed.