Skip to content

[Automatic Migration] Introduce Last execution info for a migration#221635

Merged
logeekal merged 25 commits intoelastic:mainfrom
logeekal:fix/stop_migration_status
Jun 3, 2025
Merged

[Automatic Migration] Introduce Last execution info for a migration#221635
logeekal merged 25 commits intoelastic:mainfrom
logeekal:fix/stop_migration_status

Conversation

@logeekal
Copy link
Contributor

@logeekal logeekal commented May 27, 2025

Resolves

Summary

Please find the summary of all the changes below.

Last Execution Info

This Enhancement introduces last_execution object to the migration document. There is some information that we need to add for the last run migration ( eg. error occured or connector_id used ). This PR add that info. Below is how a sample migration document looks like with last_execution info and shape of last_execution object.

export const RuleMigrationLastExecution = z.object({
  /**
   * The moment the last execution started.
   */
  started_at: z.string().optional(),
  /**
   * The moment the last execution ended.
   */
  ended_at: z.string().optional(),
  /**
   * The connector ID used for the last execution, if applicable.
   */
  connector_id: z.string().optional(),
  /**
   * The error message if the last execution failed.
   */
  error: z.string().optional(),
  /**
   * Indicates if the last execution was aborted by the user.
   */
  is_aborted: z.boolean().optional(),
});
{
  "created_by": "u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0",
  "created_at": "2025-05-28T06:10:37.638Z",
  "last_execution": {
    "connector_id": "azureOpenAiGPT4o",
    "started_at": "2025-05-28T06:10:48.030Z",
    "is_aborted": false,
    "error": "Failed to populate ELSER indices. Make sure the ELSER model is deployed and running at Machine Learning > Trained Models. Error: Exception when running inference id [.elser-2-elasticsearch] on field [elser_embedding]",
    "ended_at": "2025-05-28T06:11:31.464Z"
}

Why Last Execution info was needed?

  • An automatic migration can run into an error and terminate. Today, we store that error in server state and do not persist. This can be a problem when server is restarted and user will not be able to see that error.

    • So, we need a way to persist the error for last execution.
  • Additionally, we do not have any details on when the last execution was started and finished.

  • We also need to store the connector_id so that we can re-use it when user is restarting a migration.

In addition to resolving above issues, this Ticket makes some minor UI Changes to the Migration Ready Panel in different states of a Migration

When Migration is Ready to be started.

This remains exactly the same as before:

image

When Migration was Aborted

Before After
image image

When there was an error

Before After
image image

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

if (lastExecution?.is_aborted) {
return SiemMigrationTaskStatus.ABORTED;
}
if (dataStats.pending === dataStats.total) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if pending === total but the task was aborted, we would want to inform user that the task was aborted but can still be started.

@logeekal logeekal changed the title Fix/stop migration status [Automatic Migration] Introduce Last execution info for a migration May 28, 2025
@logeekal logeekal marked this pull request as ready for review May 28, 2025 06:13
@logeekal logeekal requested review from a team as code owners May 28, 2025 06:13
@logeekal logeekal added Team:Threat Hunting Security Solution Threat Hunting Team backport:version Backport to applied version labels v9.1.0 v8.19.0 labels May 28, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@logeekal logeekal added the release_note:skip Skip the PR/issue when compiling release notes label May 28, 2025
@logeekal logeekal requested a review from a team as a code owner May 28, 2025 06:47
@logeekal logeekal requested a review from semd May 28, 2025 12:28
@logeekal
Copy link
Contributor Author

@semd , as we discussed, here are some cosmetic naming changes + final workflow for Saving aborted/failed/ended state in migration index

6930b3b

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks Jatin

@logeekal logeekal enabled auto-merge (squash) June 2, 2025 13:01
@logeekal logeekal merged commit 6458650 into elastic:main Jun 3, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15410758137

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #73 / Rule execution logic API - Trial License/Complete Tier @ess @serverless synthetic source synthetic source limitations should convert dot-notation to nested objects
  • [job] [logs] FTR Configs #55 / Security Solution - Telemetry Security Telemetry - Indices metadata task telemetry @ess indices metadata should include ilm_policy in data stream events when defined

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 9.2MB 9.2MB +1.3KB

History

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.19:
- [Security Solution] Integrations card in automatic migrations (#221493)

Manual backport

To create the backport manually run:

node scripts/backport --pr 221635

Questions ?

Please refer to the Backport tool documentation

zacharyparikh pushed a commit to zacharyparikh/kibana that referenced this pull request Jun 4, 2025
…lastic#221635)

## Resolves 

- elastic/security-team#12681
- elastic/security-team#12682

## Summary

Please find the summary of all the changes below.

### Last Execution Info

This Enhancement introduces `last_execution` object to the `migration`
document. There is some information that we need to add for the last run
migration ( eg. `error` occured or `connector_id` used ). This PR add
that info. Below is how a sample `migration` document looks like with
`last_execution` info and shape of `last_execution` object.

```ts
export const RuleMigrationLastExecution = z.object({
  /**
   * The moment the last execution started.
   */
  started_at: z.string().optional(),
  /**
   * The moment the last execution ended.
   */
  ended_at: z.string().optional(),
  /**
   * The connector ID used for the last execution, if applicable.
   */
  connector_id: z.string().optional(),
  /**
   * The error message if the last execution failed.
   */
  error: z.string().optional(),
  /**
   * Indicates if the last execution was aborted by the user.
   */
  is_aborted: z.boolean().optional(),
});
```
```json
{
  "created_by": "u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0",
  "created_at": "2025-05-28T06:10:37.638Z",
  "last_execution": {
    "connector_id": "azureOpenAiGPT4o",
    "started_at": "2025-05-28T06:10:48.030Z",
    "is_aborted": false,
    "error": "Failed to populate ELSER indices. Make sure the ELSER model is deployed and running at Machine Learning > Trained Models. Error: Exception when running inference id [.elser-2-elasticsearch] on field [elser_embedding]",
    "ended_at": "2025-05-28T06:11:31.464Z"
}

```

### Why `Last Execution` info was needed?



- An automatic migration can run into an error and terminate. Today, we
store that error in server state and do not persist. This can be a
problem when server is restarted and user will not be able to see that
error.
  - So, we need a way to persist the error for last execution.
- Additionally, we do not have any details on when the last execution
was started and finished.

- We also need to store the connector_id so that we can re-use it when
user is restarting a migration.


In addition to resolving above issues, this Ticket makes some minor UI
Changes to the Migration Ready Panel in different states of a Migration


### When Migration is Ready to be started.

This remains exactly the same as before:


![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)

### When Migration was Aborted

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|

### When there was an error

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|



### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 5, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221635 locally
cc: @logeekal

4 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221635 locally
cc: @logeekal

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221635 locally
cc: @logeekal

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221635 locally
cc: @logeekal

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221635 locally
cc: @logeekal

@logeekal logeekal added backport:version Backport to applied version labels and removed backport missing Added to PRs automatically when the are determined to be missing a backport. backport:version Backport to applied version labels labels Jun 11, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15581696693

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 11, 2025
…lastic#221635)

## Resolves

- elastic/security-team#12681
- elastic/security-team#12682

## Summary

Please find the summary of all the changes below.

### Last Execution Info

This Enhancement introduces `last_execution` object to the `migration`
document. There is some information that we need to add for the last run
migration ( eg. `error` occured or `connector_id` used ). This PR add
that info. Below is how a sample `migration` document looks like with
`last_execution` info and shape of `last_execution` object.

```ts
export const RuleMigrationLastExecution = z.object({
  /**
   * The moment the last execution started.
   */
  started_at: z.string().optional(),
  /**
   * The moment the last execution ended.
   */
  ended_at: z.string().optional(),
  /**
   * The connector ID used for the last execution, if applicable.
   */
  connector_id: z.string().optional(),
  /**
   * The error message if the last execution failed.
   */
  error: z.string().optional(),
  /**
   * Indicates if the last execution was aborted by the user.
   */
  is_aborted: z.boolean().optional(),
});
```
```json
{
  "created_by": "u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0",
  "created_at": "2025-05-28T06:10:37.638Z",
  "last_execution": {
    "connector_id": "azureOpenAiGPT4o",
    "started_at": "2025-05-28T06:10:48.030Z",
    "is_aborted": false,
    "error": "Failed to populate ELSER indices. Make sure the ELSER model is deployed and running at Machine Learning > Trained Models. Error: Exception when running inference id [.elser-2-elasticsearch] on field [elser_embedding]",
    "ended_at": "2025-05-28T06:11:31.464Z"
}

```

### Why `Last Execution` info was needed?

- An automatic migration can run into an error and terminate. Today, we
store that error in server state and do not persist. This can be a
problem when server is restarted and user will not be able to see that
error.
  - So, we need a way to persist the error for last execution.
- Additionally, we do not have any details on when the last execution
was started and finished.

- We also need to store the connector_id so that we can re-use it when
user is restarting a migration.

In addition to resolving above issues, this Ticket makes some minor UI
Changes to the Migration Ready Panel in different states of a Migration

### When Migration is Ready to be started.

This remains exactly the same as before:

![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)

### When Migration was Aborted

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|

### When there was an error

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 6458650)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jun 11, 2025
…ation (#221635) (#223379)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Automatic Migration] Introduce Last execution info for a migration
(#221635)](#221635)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Jatin
Kathuria","email":"jatin.kathuria@elastic.co"},"sourceCommit":{"committedDate":"2025-06-03T07:05:43Z","message":"[Automatic
Migration] Introduce Last execution info for a migration (#221635)\n\n##
Resolves \n\n- https://github.com/elastic/security-team/issues/12681\n-
https://github.com/elastic/security-team/issues/12682\n\n##
Summary\n\nPlease find the summary of all the changes below.\n\n### Last
Execution Info\n\nThis Enhancement introduces `last_execution` object to
the `migration`\ndocument. There is some information that we need to add
for the last run\nmigration ( eg. `error` occured or `connector_id` used
). This PR add\nthat info. Below is how a sample `migration` document
looks like with\n`last_execution` info and shape of `last_execution`
object.\n\n```ts\nexport const RuleMigrationLastExecution = z.object({\n
/**\n * The moment the last execution started.\n */\n started_at:
z.string().optional(),\n /**\n * The moment the last execution ended.\n
*/\n ended_at: z.string().optional(),\n /**\n * The connector ID used
for the last execution, if applicable.\n */\n connector_id:
z.string().optional(),\n /**\n * The error message if the last execution
failed.\n */\n error: z.string().optional(),\n /**\n * Indicates if the
last execution was aborted by the user.\n */\n is_aborted:
z.boolean().optional(),\n});\n```\n```json\n{\n \"created_by\":
\"u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0\",\n \"created_at\":
\"2025-05-28T06:10:37.638Z\",\n \"last_execution\": {\n
\"connector_id\": \"azureOpenAiGPT4o\",\n \"started_at\":
\"2025-05-28T06:10:48.030Z\",\n \"is_aborted\": false,\n \"error\":
\"Failed to populate ELSER indices. Make sure the ELSER model is
deployed and running at Machine Learning > Trained Models. Error:
Exception when running inference id [.elser-2-elasticsearch] on field
[elser_embedding]\",\n \"ended_at\":
\"2025-05-28T06:11:31.464Z\"\n}\n\n```\n\n### Why `Last Execution` info
was needed?\n\n\n\n- An automatic migration can run into an error and
terminate. Today, we\nstore that error in server state and do not
persist. This can be a\nproblem when server is restarted and user will
not be able to see that\nerror.\n - So, we need a way to persist the
error for last execution.\n- Additionally, we do not have any details on
when the last execution\nwas started and finished.\n\n- We also need to
store the connector_id so that we can re-use it when\nuser is restarting
a migration.\n\n\nIn addition to resolving above issues, this Ticket
makes some minor UI\nChanges to the Migration Ready Panel in different
states of a Migration\n\n\n### When Migration is Ready to be
started.\n\nThis remains exactly the same as
before:\n\n\n![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)\n\n###
When Migration was
Aborted\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|\n\n###
When there was an
error\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|\n\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [ ] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"645865097609a1e77ec0ec405494c46a08eaa8b2","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat
Hunting","backport:version","v9.1.0","v8.19.0"],"title":"[Automatic
Migration] Introduce Last execution info for a
migration","number":221635,"url":"https://github.com/elastic/kibana/pull/221635","mergeCommit":{"message":"[Automatic
Migration] Introduce Last execution info for a migration (#221635)\n\n##
Resolves \n\n- https://github.com/elastic/security-team/issues/12681\n-
https://github.com/elastic/security-team/issues/12682\n\n##
Summary\n\nPlease find the summary of all the changes below.\n\n### Last
Execution Info\n\nThis Enhancement introduces `last_execution` object to
the `migration`\ndocument. There is some information that we need to add
for the last run\nmigration ( eg. `error` occured or `connector_id` used
). This PR add\nthat info. Below is how a sample `migration` document
looks like with\n`last_execution` info and shape of `last_execution`
object.\n\n```ts\nexport const RuleMigrationLastExecution = z.object({\n
/**\n * The moment the last execution started.\n */\n started_at:
z.string().optional(),\n /**\n * The moment the last execution ended.\n
*/\n ended_at: z.string().optional(),\n /**\n * The connector ID used
for the last execution, if applicable.\n */\n connector_id:
z.string().optional(),\n /**\n * The error message if the last execution
failed.\n */\n error: z.string().optional(),\n /**\n * Indicates if the
last execution was aborted by the user.\n */\n is_aborted:
z.boolean().optional(),\n});\n```\n```json\n{\n \"created_by\":
\"u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0\",\n \"created_at\":
\"2025-05-28T06:10:37.638Z\",\n \"last_execution\": {\n
\"connector_id\": \"azureOpenAiGPT4o\",\n \"started_at\":
\"2025-05-28T06:10:48.030Z\",\n \"is_aborted\": false,\n \"error\":
\"Failed to populate ELSER indices. Make sure the ELSER model is
deployed and running at Machine Learning > Trained Models. Error:
Exception when running inference id [.elser-2-elasticsearch] on field
[elser_embedding]\",\n \"ended_at\":
\"2025-05-28T06:11:31.464Z\"\n}\n\n```\n\n### Why `Last Execution` info
was needed?\n\n\n\n- An automatic migration can run into an error and
terminate. Today, we\nstore that error in server state and do not
persist. This can be a\nproblem when server is restarted and user will
not be able to see that\nerror.\n - So, we need a way to persist the
error for last execution.\n- Additionally, we do not have any details on
when the last execution\nwas started and finished.\n\n- We also need to
store the connector_id so that we can re-use it when\nuser is restarting
a migration.\n\n\nIn addition to resolving above issues, this Ticket
makes some minor UI\nChanges to the Migration Ready Panel in different
states of a Migration\n\n\n### When Migration is Ready to be
started.\n\nThis remains exactly the same as
before:\n\n\n![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)\n\n###
When Migration was
Aborted\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|\n\n###
When there was an
error\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|\n\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [ ] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"645865097609a1e77ec0ec405494c46a08eaa8b2"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221635","number":221635,"mergeCommit":{"message":"[Automatic
Migration] Introduce Last execution info for a migration (#221635)\n\n##
Resolves \n\n- https://github.com/elastic/security-team/issues/12681\n-
https://github.com/elastic/security-team/issues/12682\n\n##
Summary\n\nPlease find the summary of all the changes below.\n\n### Last
Execution Info\n\nThis Enhancement introduces `last_execution` object to
the `migration`\ndocument. There is some information that we need to add
for the last run\nmigration ( eg. `error` occured or `connector_id` used
). This PR add\nthat info. Below is how a sample `migration` document
looks like with\n`last_execution` info and shape of `last_execution`
object.\n\n```ts\nexport const RuleMigrationLastExecution = z.object({\n
/**\n * The moment the last execution started.\n */\n started_at:
z.string().optional(),\n /**\n * The moment the last execution ended.\n
*/\n ended_at: z.string().optional(),\n /**\n * The connector ID used
for the last execution, if applicable.\n */\n connector_id:
z.string().optional(),\n /**\n * The error message if the last execution
failed.\n */\n error: z.string().optional(),\n /**\n * Indicates if the
last execution was aborted by the user.\n */\n is_aborted:
z.boolean().optional(),\n});\n```\n```json\n{\n \"created_by\":
\"u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0\",\n \"created_at\":
\"2025-05-28T06:10:37.638Z\",\n \"last_execution\": {\n
\"connector_id\": \"azureOpenAiGPT4o\",\n \"started_at\":
\"2025-05-28T06:10:48.030Z\",\n \"is_aborted\": false,\n \"error\":
\"Failed to populate ELSER indices. Make sure the ELSER model is
deployed and running at Machine Learning > Trained Models. Error:
Exception when running inference id [.elser-2-elasticsearch] on field
[elser_embedding]\",\n \"ended_at\":
\"2025-05-28T06:11:31.464Z\"\n}\n\n```\n\n### Why `Last Execution` info
was needed?\n\n\n\n- An automatic migration can run into an error and
terminate. Today, we\nstore that error in server state and do not
persist. This can be a\nproblem when server is restarted and user will
not be able to see that\nerror.\n - So, we need a way to persist the
error for last execution.\n- Additionally, we do not have any details on
when the last execution\nwas started and finished.\n\n- We also need to
store the connector_id so that we can re-use it when\nuser is restarting
a migration.\n\n\nIn addition to resolving above issues, this Ticket
makes some minor UI\nChanges to the Migration Ready Panel in different
states of a Migration\n\n\n### When Migration is Ready to be
started.\n\nThis remains exactly the same as
before:\n\n\n![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)\n\n###
When Migration was
Aborted\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|\n\n###
When there was an
error\n\n|Before|After|\n|---|---|\n\n|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|\n\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [ ] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"645865097609a1e77ec0ec405494c46a08eaa8b2"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jatin Kathuria <jatin.kathuria@elastic.co>
nickpeihl pushed a commit to nickpeihl/kibana that referenced this pull request Jun 12, 2025
…lastic#221635)

## Resolves 

- elastic/security-team#12681
- elastic/security-team#12682

## Summary

Please find the summary of all the changes below.

### Last Execution Info

This Enhancement introduces `last_execution` object to the `migration`
document. There is some information that we need to add for the last run
migration ( eg. `error` occured or `connector_id` used ). This PR add
that info. Below is how a sample `migration` document looks like with
`last_execution` info and shape of `last_execution` object.

```ts
export const RuleMigrationLastExecution = z.object({
  /**
   * The moment the last execution started.
   */
  started_at: z.string().optional(),
  /**
   * The moment the last execution ended.
   */
  ended_at: z.string().optional(),
  /**
   * The connector ID used for the last execution, if applicable.
   */
  connector_id: z.string().optional(),
  /**
   * The error message if the last execution failed.
   */
  error: z.string().optional(),
  /**
   * Indicates if the last execution was aborted by the user.
   */
  is_aborted: z.boolean().optional(),
});
```
```json
{
  "created_by": "u_v6jVi3qZ21kAEUwmbl-sfujRnwydrltycxyByl3jtIM_0",
  "created_at": "2025-05-28T06:10:37.638Z",
  "last_execution": {
    "connector_id": "azureOpenAiGPT4o",
    "started_at": "2025-05-28T06:10:48.030Z",
    "is_aborted": false,
    "error": "Failed to populate ELSER indices. Make sure the ELSER model is deployed and running at Machine Learning > Trained Models. Error: Exception when running inference id [.elser-2-elasticsearch] on field [elser_embedding]",
    "ended_at": "2025-05-28T06:11:31.464Z"
}

```

### Why `Last Execution` info was needed?



- An automatic migration can run into an error and terminate. Today, we
store that error in server state and do not persist. This can be a
problem when server is restarted and user will not be able to see that
error.
  - So, we need a way to persist the error for last execution.
- Additionally, we do not have any details on when the last execution
was started and finished.

- We also need to store the connector_id so that we can re-use it when
user is restarting a migration.


In addition to resolving above issues, this Ticket makes some minor UI
Changes to the Migration Ready Panel in different states of a Migration


### When Migration is Ready to be started.

This remains exactly the same as before:


![image](https://github.com/user-attachments/assets/290a4cb2-ac13-44af-a266-22c0d57719db)

### When Migration was Aborted

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/fee267c1-addc-4de5-87ae-86b6b4d332aa)|![image](https://github.com/user-attachments/assets/6580f10e-9276-422b-8576-f90e862c8bb9)|

### When there was an error

|Before|After|
|---|---|

|![image](https://github.com/user-attachments/assets/97ab4e86-1e5d-42db-a6b6-86fc4a0cd837)|![image](https://github.com/user-attachments/assets/ff89bf71-a86e-4409-929d-69dd631b448e)|



### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants