Skip to content

Conversation

@sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Apr 25, 2025

Expose LockManager as package to make it easier to consume from other plugins

cc @nchaulet

@sorenlouv sorenlouv requested review from a team and kibanamachine as code owners April 25, 2025 10:21
@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:Obs AI Assistant Observability AI Assistant labels Apr 25, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@github-actions
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@sorenlouv sorenlouv added backport:version Backport to applied version labels v9.1.0 v8.19.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 25, 2025
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner April 25, 2025 13:48
Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

kibana.jsonc LGTM

kibanamachine and others added 4 commits April 26, 2025 22:35
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/streams --include-path /api/fleet --include-path /api/dashboards --include-path /api/saved_objects/_import --include-path /api/saved_objects/_export --include-path /api/alerting/maintenance_window --update'
@sorenlouv
Copy link
Member Author

sorenlouv commented Apr 27, 2025

That's actually what I started out with. Happy to move it back

@sorenlouv I think a package makes sense, but I don't want to create more work for you if a plugin is preferred by others. Maybe @afharo has an opinion from Core's perspective?

A package makes sense. I think that I misread the initial PR description. I thought that it was intentionally moved to a plugin for future reasons. If it's "just about" exporting a "helper" function. A package is the way.

That being said, please, keep SKA in mind. Place the package in the correct platform or solutions directory. AFAIK, placing it in the x-pack/packages dir is currently reserved for devOnly packages that don't make it to the production bundle (cc @gsoldevila @lukeelmers to keep me honest).

Moved it out of x-pack to top-level packages. I also prefixed with kbn- because that's how all other packages are named. Now getting this jest error:

Error: ● Validation Error:

  Preset @kbn/test/jest_node not found.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

Can be reproduced locally with node scripts/jest.js --config packages/kbn-lock-manager/jest.config.js.

Any clue? nvm. fixed.

}
}

export async function setupLockManagerIndex(esClient: ElasticsearchClient, logger: Logger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if this function never throws, how does the lock manager know it can attempt to acquire the lock?

Copy link
Member Author

@sorenlouv sorenlouv Apr 29, 2025

Choose a reason for hiding this comment

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

I changed ensureTemplatesAndIndexCreated so it now throws if the template or index can't be created

@sorenlouv sorenlouv enabled auto-merge (squash) April 29, 2025 14:48
@elasticmachine
Copy link
Contributor

elasticmachine commented Apr 29, 2025

💚 Build Succeeded

  • Buildkite Build
  • Commit: b7f22b3
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-219220-b7f22b3c61ff

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/lock-manager - 11 +11
Unknown metric groups

API count

id before after diff
@kbn/lock-manager - 12 +12

ESLint disabled line counts

id before after diff
@kbn/lock-manager - 1 +1
observabilityAIAssistant 7 6 -1
total -0

Total ESLint disabled count

id before after diff
@kbn/lock-manager - 1 +1
observabilityAIAssistant 9 8 -1
total -0

History

@sorenlouv sorenlouv merged commit 8b8d569 into elastic:main Apr 29, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

@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:
- [upgrade assistant] Create upgrade-assistant package, stub out storybook usage (#218705)
- [Scout] add painless lab

Manual backport

To create the backport manually run:

node scripts/backport --pr 219220

Questions ?

Please refer to the Backport tool documentation

@sorenlouv sorenlouv deleted the extract-lock-manager-to-plugin branch April 29, 2025 17:32
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Apr 30, 2025
Expose LockManager as package to make it easier to consume from other
plugins

cc @nchaulet

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Viduni Wickramarachchi <[email protected]>
@sorenlouv
Copy link
Member Author

💚 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

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Apr 30, 2025
Expose LockManager as package to make it easier to consume from other
plugins

cc @nchaulet

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Viduni Wickramarachchi <[email protected]>
(cherry picked from commit 8b8d569)
sorenlouv added a commit that referenced this pull request May 1, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Obs AI Assistant] Skip lock tests in MKI temporarily
(#216753)](#216753)
- [[Obs AI Assistant] Replace Task Manager usage with Lock Manager
(#216916)](#216916)
- [[LockManager] Ensure index template are created
(#218901)](#218901)
- [[LockManager] Expose as package
(#219220)](#219220)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-02T09:28:35Z","message":"[Obs
AI Assistant] Skip lock tests in MKI temporarily (#216753)\n\nTests
added in #216397 are failing\non
MKI. Skipping temporarily in the affected environment\n\n###
Error\n\n```\n └- ✖ fail: Serverless Observability - Deployment-agnostic
API integration tests observability AI Assistant LockManager Basic lock
operations acquires the lock when not held\n │ ResponseError:
security_exception\n │ \tRoot causes:\n │ \t\tsecurity_exception: action
[indices:admin/create] is unauthorized for user [testing-internal] with
effective roles [superuser] on restricted indices
[.kibana_locks-000001], this action is granted by the index privileges
[create_index,manage,all]\n```\n\n### Root cause\n```ts\nconst es =
getService('es');\nes.deleteByQuery({ index: '.kibana_locks-000001',
query: { match_all: {}
}});\n```","sha":"8bcce2e89b6be758d144b9b802eb9d2a09dd62cf","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","v9.1.0","v8.19.0"],"title":"[Obs
AI Assistant] Skip lock tests in MKI
temporarily","number":216753,"url":"https://github.com/elastic/kibana/pull/216753","mergeCommit":{"message":"[Obs
AI Assistant] Skip lock tests in MKI temporarily (#216753)\n\nTests
added in #216397 are failing\non
MKI. Skipping temporarily in the affected environment\n\n###
Error\n\n```\n └- ✖ fail: Serverless Observability - Deployment-agnostic
API integration tests observability AI Assistant LockManager Basic lock
operations acquires the lock when not held\n │ ResponseError:
security_exception\n │ \tRoot causes:\n │ \t\tsecurity_exception: action
[indices:admin/create] is unauthorized for user [testing-internal] with
effective roles [superuser] on restricted indices
[.kibana_locks-000001], this action is granted by the index privileges
[create_index,manage,all]\n```\n\n### Root cause\n```ts\nconst es =
getService('es');\nes.deleteByQuery({ index: '.kibana_locks-000001',
query: { match_all: {}
}});\n```","sha":"8bcce2e89b6be758d144b9b802eb9d2a09dd62cf"}},"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/216753","number":216753,"mergeCommit":{"message":"[Obs
AI Assistant] Skip lock tests in MKI temporarily (#216753)\n\nTests
added in #216397 are failing\non
MKI. Skipping temporarily in the affected environment\n\n###
Error\n\n```\n └- ✖ fail: Serverless Observability - Deployment-agnostic
API integration tests observability AI Assistant LockManager Basic lock
operations acquires the lock when not held\n │ ResponseError:
security_exception\n │ \tRoot causes:\n │ \t\tsecurity_exception: action
[indices:admin/create] is unauthorized for user [testing-internal] with
effective roles [superuser] on restricted indices
[.kibana_locks-000001], this action is granted by the index privileges
[create_index,manage,all]\n```\n\n### Root cause\n```ts\nconst es =
getService('es');\nes.deleteByQuery({ index: '.kibana_locks-000001',
query: { match_all: {}
}});\n```","sha":"8bcce2e89b6be758d144b9b802eb9d2a09dd62cf"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]},{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-08T08:13:00Z","message":"[Obs
AI Assistant] Replace Task Manager usage with Lock Manager
(#216916)\n\nThis PR replaces usage of the Kibana Task Manager with the
[LockManager\nutility](#216397)
that ensures\nstrict mutual exclusion when running operations such as
re-indexing or\ndata migrations.\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi <[email protected]>\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"624410524f1a07dc72d92759464a3f4a85466c7a","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","Team:Obs
AI Assistant","v9.1.0"],"title":"[Obs AI Assistant] Replace Task Manager
usage with Lock
Manager","number":216916,"url":"https://github.com/elastic/kibana/pull/216916","mergeCommit":{"message":"[Obs
AI Assistant] Replace Task Manager usage with Lock Manager
(#216916)\n\nThis PR replaces usage of the Kibana Task Manager with the
[LockManager\nutility](#216397)
that ensures\nstrict mutual exclusion when running operations such as
re-indexing or\ndata migrations.\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi <[email protected]>\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"624410524f1a07dc72d92759464a3f4a85466c7a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216916","number":216916,"mergeCommit":{"message":"[Obs
AI Assistant] Replace Task Manager usage with Lock Manager
(#216916)\n\nThis PR replaces usage of the Kibana Task Manager with the
[LockManager\nutility](#216397)
that ensures\nstrict mutual exclusion when running operations such as
re-indexing or\ndata migrations.\n\n---------\n\nCo-authored-by: Viduni
Wickramarachchi <[email protected]>\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"624410524f1a07dc72d92759464a3f4a85466c7a"}}]},{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-23T23:34:28Z","message":"[LockManager]
Ensure index template are created (#218901)\n\nCloses:
https://github.com/elastic/kibana/issues/218944\n\nThe index template
for the Lock Manager was not created, causing index\nmappings and
settings to be incorrect.\nRoot cause: the function responsible for
creating the index template\n(`ensureTemplatesAndIndexCreated`) was
never invoked - only during\nautomated testing 🤦\n\n## Manual testing
steps\n\nThe mappings for the lock manager index
(`.kibana_locks-000001`) should\nmatch this:\n```ts\n {\n mappings: {\n
dynamic: false,\n properties: {\n token: { type: 'keyword' },\n
metadata: { enabled: false },\n createdAt: { type: 'date' },\n
expiresAt: { type: 'date' },\n },\n },\n}\n```\n\n### Test 1\n\nIn this
test we make sure that the LockManager library can recover and\nfix the
mappings if the existing index has invalid mappings\n\n#### Delete
existing assets if they already exist\n```\nDELETE
.kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n#### Create lock
index. This is invalid because it does not have the\ncorrect
mappings\n```\nPUT .kibana_locks-000001\n```\n\n(Restart Kibana)\n\n####
Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\n### Test 2\n\nIn this test we make
sure that out of the box, the LockManager library\ncreates an index with
the correct mappings\n\n```\nDELETE .kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n(Restart
Kibana)\n\n#### Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\nRelated:
https://github.com/elastic/kibana/pull/216916\nhttps://github.com/elastic/kibana/pull/216397\n\n---------\n\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"f684ea4071dfb5e6acc4cb057b46acbf915943d7","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:skip","Team:Obs
AI
Assistant","ci:project-deploy-observability","v9.1.0"],"title":"[LockManager]
Ensure index template are
created","number":218901,"url":"https://github.com/elastic/kibana/pull/218901","mergeCommit":{"message":"[LockManager]
Ensure index template are created (#218901)\n\nCloses:
https://github.com/elastic/kibana/issues/218944\n\nThe index template
for the Lock Manager was not created, causing index\nmappings and
settings to be incorrect.\nRoot cause: the function responsible for
creating the index template\n(`ensureTemplatesAndIndexCreated`) was
never invoked - only during\nautomated testing 🤦\n\n## Manual testing
steps\n\nThe mappings for the lock manager index
(`.kibana_locks-000001`) should\nmatch this:\n```ts\n {\n mappings: {\n
dynamic: false,\n properties: {\n token: { type: 'keyword' },\n
metadata: { enabled: false },\n createdAt: { type: 'date' },\n
expiresAt: { type: 'date' },\n },\n },\n}\n```\n\n### Test 1\n\nIn this
test we make sure that the LockManager library can recover and\nfix the
mappings if the existing index has invalid mappings\n\n#### Delete
existing assets if they already exist\n```\nDELETE
.kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n#### Create lock
index. This is invalid because it does not have the\ncorrect
mappings\n```\nPUT .kibana_locks-000001\n```\n\n(Restart Kibana)\n\n####
Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\n### Test 2\n\nIn this test we make
sure that out of the box, the LockManager library\ncreates an index with
the correct mappings\n\n```\nDELETE .kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n(Restart
Kibana)\n\n#### Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\nRelated:
https://github.com/elastic/kibana/pull/216916\nhttps://github.com/elastic/kibana/pull/216397\n\n---------\n\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"f684ea4071dfb5e6acc4cb057b46acbf915943d7"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218901","number":218901,"mergeCommit":{"message":"[LockManager]
Ensure index template are created (#218901)\n\nCloses:
https://github.com/elastic/kibana/issues/218944\n\nThe index template
for the Lock Manager was not created, causing index\nmappings and
settings to be incorrect.\nRoot cause: the function responsible for
creating the index template\n(`ensureTemplatesAndIndexCreated`) was
never invoked - only during\nautomated testing 🤦\n\n## Manual testing
steps\n\nThe mappings for the lock manager index
(`.kibana_locks-000001`) should\nmatch this:\n```ts\n {\n mappings: {\n
dynamic: false,\n properties: {\n token: { type: 'keyword' },\n
metadata: { enabled: false },\n createdAt: { type: 'date' },\n
expiresAt: { type: 'date' },\n },\n },\n}\n```\n\n### Test 1\n\nIn this
test we make sure that the LockManager library can recover and\nfix the
mappings if the existing index has invalid mappings\n\n#### Delete
existing assets if they already exist\n```\nDELETE
.kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n#### Create lock
index. This is invalid because it does not have the\ncorrect
mappings\n```\nPUT .kibana_locks-000001\n```\n\n(Restart Kibana)\n\n####
Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\n### Test 2\n\nIn this test we make
sure that out of the box, the LockManager library\ncreates an index with
the correct mappings\n\n```\nDELETE .kibana_locks-000001\nDELETE
_index_template/.kibana_locks-index-template\nDELETE
_component_template/.kibana_locks-component\n```\n\n(Restart
Kibana)\n\n#### Check mappings are correct\n```\nGET
.kibana_locks-000001/_mapping\n```\n\nRelated:
https://github.com/elastic/kibana/pull/216916\nhttps://github.com/elastic/kibana/pull/216397\n\n---------\n\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"f684ea4071dfb5e6acc4cb057b46acbf915943d7"}}]},{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-29T16:42:45Z","message":"[LockManager]
Expose as package (#219220)\n\nExpose LockManager as package to make it
easier to consume from other\nplugins\n\ncc
@nchaulet\n\n---------\n\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"8b8d569986f216185755aa7ac98a2a3bbeb84f76","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0"],"title":"[LockManager]
Expose as
package","number":219220,"url":"https://github.com/elastic/kibana/pull/219220","mergeCommit":{"message":"[LockManager]
Expose as package (#219220)\n\nExpose LockManager as package to make it
easier to consume from other\nplugins\n\ncc
@nchaulet\n\n---------\n\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"8b8d569986f216185755aa7ac98a2a3bbeb84f76"}},"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/219220","number":219220,"mergeCommit":{"message":"[LockManager]
Expose as package (#219220)\n\nExpose LockManager as package to make it
easier to consume from other\nplugins\n\ncc
@nchaulet\n\n---------\n\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by:
Viduni Wickramarachchi
<[email protected]>","sha":"8b8d569986f216185755aa7ac98a2a3bbeb84f76"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
Expose LockManager as package to make it easier to consume from other
plugins

cc @nchaulet

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Viduni Wickramarachchi <[email protected]>
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 ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:Obs AI Assistant Observability AI Assistant v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants