forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Entity Manager] Exposing stop and start transforms actions in the En…
…tityClient (elastic#192186) This PR exposes two new methods (`startTransforms` and `stopTransforms`) in the EntityClient as proposed [here](elastic/elastic-entity-model#160) This work is also required by the Entity Analytics team: elastic/security-team#10230 In addition, it splits up `stop_and_delete_transforms` into more granular actions, one for stopping and another for deleting. The uninstall function is now responsible for appropriately calling those actions in sequence.
- Loading branch information
1 parent
c8ecc31
commit 337e692
Showing
11 changed files
with
185 additions
and
164 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...ck/plugins/observability_solution/entity_manager/server/lib/entities/delete_transforms.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,58 @@ | ||
/* | ||
* 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 { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
import { EntityDefinition } from '@kbn/entities-schema'; | ||
|
||
import { | ||
generateHistoryTransformId, | ||
generateHistoryBackfillTransformId, | ||
generateLatestTransformId, | ||
} from './helpers/generate_component_id'; | ||
import { retryTransientEsErrors } from './helpers/retry'; | ||
import { isBackfillEnabled } from './helpers/is_backfill_enabled'; | ||
|
||
export async function deleteTransforms( | ||
esClient: ElasticsearchClient, | ||
definition: EntityDefinition, | ||
logger: Logger | ||
) { | ||
try { | ||
const historyTransformId = generateHistoryTransformId(definition); | ||
const latestTransformId = generateLatestTransformId(definition); | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.deleteTransform( | ||
{ transform_id: historyTransformId, force: true }, | ||
{ ignore: [404] } | ||
), | ||
{ logger } | ||
); | ||
if (isBackfillEnabled(definition)) { | ||
const historyBackfillTransformId = generateHistoryBackfillTransformId(definition); | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.deleteTransform( | ||
{ transform_id: historyBackfillTransformId, force: true }, | ||
{ ignore: [404] } | ||
), | ||
{ logger } | ||
); | ||
} | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.deleteTransform( | ||
{ transform_id: latestTransformId, force: true }, | ||
{ ignore: [404] } | ||
), | ||
{ logger } | ||
); | ||
} catch (e) { | ||
logger.error(`Cannot delete history transform [${definition.id}]: ${e}`); | ||
throw e; | ||
} | ||
} |
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
102 changes: 0 additions & 102 deletions
102
...ns/observability_solution/entity_manager/server/lib/entities/stop_and_delete_transform.ts
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/observability_solution/entity_manager/server/lib/entities/stop_transforms.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,65 @@ | ||
/* | ||
* 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 { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
import { EntityDefinition } from '@kbn/entities-schema'; | ||
|
||
import { | ||
generateHistoryTransformId, | ||
generateHistoryBackfillTransformId, | ||
generateLatestTransformId, | ||
} from './helpers/generate_component_id'; | ||
import { retryTransientEsErrors } from './helpers/retry'; | ||
|
||
import { isBackfillEnabled } from './helpers/is_backfill_enabled'; | ||
|
||
export async function stopTransforms( | ||
esClient: ElasticsearchClient, | ||
definition: EntityDefinition, | ||
logger: Logger | ||
) { | ||
try { | ||
const historyTransformId = generateHistoryTransformId(definition); | ||
const latestTransformId = generateLatestTransformId(definition); | ||
|
||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.stopTransform( | ||
{ transform_id: historyTransformId, wait_for_completion: true, force: true }, | ||
{ ignore: [409, 404] } | ||
), | ||
{ logger } | ||
); | ||
|
||
if (isBackfillEnabled(definition)) { | ||
const historyBackfillTransformId = generateHistoryBackfillTransformId(definition); | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.stopTransform( | ||
{ | ||
transform_id: historyBackfillTransformId, | ||
wait_for_completion: true, | ||
force: true, | ||
}, | ||
{ ignore: [409, 404] } | ||
), | ||
{ logger } | ||
); | ||
} | ||
await retryTransientEsErrors( | ||
() => | ||
esClient.transform.stopTransform( | ||
{ transform_id: latestTransformId, wait_for_completion: true, force: true }, | ||
{ ignore: [409, 404] } | ||
), | ||
{ logger } | ||
); | ||
} catch (e) { | ||
logger.error(`Cannot stop entity transforms [${definition.id}]: ${e}`); | ||
throw e; | ||
} | ||
} |
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
Oops, something went wrong.