Skip to content

[Share] Add unused url cleanup task #220138

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

Conversation

kowalczyk-krzysztof
Copy link
Member

@kowalczyk-krzysztof kowalczyk-krzysztof commented May 5, 2025

Summary

This PR adds a background task to share plugin which periodically deletes saved objects of type url which have been older than a value controlled by share.url_expiration.duration config. This check is based on attributes.accessDate of the url saved object.

The cleanup can be run manually by calling POST /internal/unused_urls_task/run with superuser privileges. This requires share.url_expiration.enabled config to be set to true. The duration and url_limit values will be based on config.

Config options (with their default values):

share.url_expiration.enabled: false # controls whether the task is enabled
share.url_expiration.duration: '1y' # controls the expiration threshold
share.url_expiration.check_interval: '7d' # controls how often the task runs 
share.url_expiration.url_limit: 10000 # controls how many SO should be fetched per task run

Closes: #179146

Testing docs (internal)

@kowalczyk-krzysztof kowalczyk-krzysztof changed the title Add unused url cleanup task [Share] Add unused url cleanup task May 6, 2025
@kowalczyk-krzysztof kowalczyk-krzysztof added the Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) label May 6, 2025
@kowalczyk-krzysztof kowalczyk-krzysztof force-pushed the feat/share-url-expiry branch 3 times, most recently from 0a84aed to 2d8378e Compare May 6, 2025 22:45
kowalczyk-krzysztof added a commit that referenced this pull request May 27, 2025
## Summary

This PR creates a separate package with `getSpaceIdFromPath` exported to
avoid creating a circular dependency in
#220138

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kowalczyk-krzysztof added a commit that referenced this pull request May 28, 2025
…#221596)

## Summary

This PR removes spaces plugin dependency from task manager plugin and
replaces `spacesService.getActiveSpace` with `getSpaceIdFromPath` from
`@kbn/spaces-utils` package. This prevents a circular dependency from
happening in #220138

> [!NOTE]  
> I'm changing the test case to use `test-space` id instead of
`testSpace` as this was an invalid space id and it shouldn't have been
used in the mock.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@kowalczyk-krzysztof kowalczyk-krzysztof added backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes labels May 28, 2025
Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't realize the default interval was 7D! :-)

In that case, I'd say you could always leave the task enabled, and check for enablement when the task actually runs.

I'd still suggest you add a check for the enablement in the task code, in case something unexpected happens and the expectation is the task wouldn't run, but it runs anyway.

But should be fine as-is.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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
share 55 87 +32

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
taskManager 9 10 +1
Unknown metric groups

API count

id before after diff
share 121 153 +32

ESLint disabled line counts

id before after diff
share 14 12 -2

Total ESLint disabled count

id before after diff
share 16 14 -2

History

cc @kowalczyk-krzysztof

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

LGTM, just a small nit

@kowalczyk-krzysztof kowalczyk-krzysztof merged commit 5c441a4 into elastic:main Jun 18, 2025
11 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

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

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 220138

Questions ?

Please refer to the Backport tool documentation

@kowalczyk-krzysztof
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

kowalczyk-krzysztof added a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jun 18, 2025
## Summary
This PR adds a background task to `share` plugin which periodically
deletes saved objects of type `url` which have been older than a value
controlled by `share.url_expiration.duration` config - the default is 1
year.
The task can be run manually by calling `POST
/internal/unused_urls_task/run` with `superuser` privileges.

Config options (with their default values):

```yaml
share.url_expiration.enabled: false # controls whether the task is enabled
share.url_expiration.duration: '1y' # controls the expiration threshold
share.url_expiration.check_interval: '7d' # controls how often the task runs
share.url_expiration.url_limit: 10000 # controls how many urls should be fetched at once
```

Closes: elastic#179146

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 5c441a4)

# Conflicts:
#	.github/CODEOWNERS
#	src/platform/plugins/shared/share/kibana.jsonc
#	src/platform/plugins/shared/share/tsconfig.json
kowalczyk-krzysztof added a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jun 18, 2025
## Summary
This PR adds a background task to `share` plugin which periodically
deletes saved objects of type `url` which have been older than a value
controlled by `share.url_expiration.duration` config - the default is 1
year.
The task can be run manually by calling `POST
/internal/unused_urls_task/run` with `superuser` privileges.

Config options (with their default values):

```yaml
share.url_expiration.enabled: false # controls whether the task is enabled
share.url_expiration.duration: '1y' # controls the expiration threshold
share.url_expiration.check_interval: '7d' # controls how often the task runs
share.url_expiration.url_limit: 10000 # controls how many urls should be fetched at once
```

Closes: elastic#179146

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 5c441a4)

# Conflicts:
#	.github/CODEOWNERS
#	src/platform/plugins/shared/share/kibana.jsonc
#	src/platform/plugins/shared/share/tsconfig.json
kowalczyk-krzysztof added a commit that referenced this pull request Jun 18, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Share] Add unused url cleanup task
(#220138)](#220138)

<!--- Backport version: 10.0.1 -->

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

<!--BACKPORT [{"author":{"name":"Krzysztof
Kowalczyk","email":"krzysztof.kowalczyk@elastic.co"},"sourceCommit":{"committedDate":"2025-06-18T14:29:29Z","message":"[Share]
Add unused url cleanup task (#220138)\n\n## Summary\nThis PR adds a
background task to `share` plugin which periodically\ndeletes saved
objects of type `url` which have been older than a value\ncontrolled by
`share.url_expiration.duration` config - the default is 1\nyear.\nThe
task can be run manually by calling
`POST\n/internal/unused_urls_task/run` with `superuser`
privileges.\n\nConfig options (with their default
values):\n\n```yaml\nshare.url_expiration.enabled: false # controls
whether the task is enabled\nshare.url_expiration.duration: '1y' #
controls the expiration threshold\nshare.url_expiration.check_interval:
'7d' # controls how often the task runs
\nshare.url_expiration.url_limit: 10000 # controls how many urls should
be fetched at once\n```\n\nCloses:
#179146\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"5c441a49cbd12a72a9f32373352dd524c154516d","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:SharedUX","backport:version","v9.1.0","v8.19.0"],"title":"[Share]
Add unused url cleanup
task","number":220138,"url":"https://github.com/elastic/kibana/pull/220138","mergeCommit":{"message":"[Share]
Add unused url cleanup task (#220138)\n\n## Summary\nThis PR adds a
background task to `share` plugin which periodically\ndeletes saved
objects of type `url` which have been older than a value\ncontrolled by
`share.url_expiration.duration` config - the default is 1\nyear.\nThe
task can be run manually by calling
`POST\n/internal/unused_urls_task/run` with `superuser`
privileges.\n\nConfig options (with their default
values):\n\n```yaml\nshare.url_expiration.enabled: false # controls
whether the task is enabled\nshare.url_expiration.duration: '1y' #
controls the expiration threshold\nshare.url_expiration.check_interval:
'7d' # controls how often the task runs
\nshare.url_expiration.url_limit: 10000 # controls how many urls should
be fetched at once\n```\n\nCloses:
#179146\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"5c441a49cbd12a72a9f32373352dd524c154516d"}},"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/220138","number":220138,"mergeCommit":{"message":"[Share]
Add unused url cleanup task (#220138)\n\n## Summary\nThis PR adds a
background task to `share` plugin which periodically\ndeletes saved
objects of type `url` which have been older than a value\ncontrolled by
`share.url_expiration.duration` config - the default is 1\nyear.\nThe
task can be run manually by calling
`POST\n/internal/unused_urls_task/run` with `superuser`
privileges.\n\nConfig options (with their default
values):\n\n```yaml\nshare.url_expiration.enabled: false # controls
whether the task is enabled\nshare.url_expiration.duration: '1y' #
controls the expiration threshold\nshare.url_expiration.check_interval:
'7d' # controls how often the task runs
\nshare.url_expiration.url_limit: 10000 # controls how many urls should
be fetched at once\n```\n\nCloses:
#179146\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"5c441a49cbd12a72a9f32373352dd524c154516d"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kowalczyk-krzysztof added a commit that referenced this pull request Aug 1, 2025
## Summary

This PR adds documentation for unused URLs cleanup task.  

Implementation PR: #220138
Cloud settings allowlist PR:
elastic/cloud#144070
kowalczyk-krzysztof added a commit to kowalczyk-krzysztof/kibana that referenced this pull request Aug 1, 2025
## Summary

This PR adds documentation for unused URLs cleanup task.

Implementation PR: elastic#220138
Cloud settings allowlist PR:
elastic/cloud#144070

(cherry picked from commit 747660d)

# Conflicts:
#	docs/reference/toc.yml
florent-leborgne added a commit that referenced this pull request Aug 1, 2025
## Summary

This PR adds documentation for unused URLs cleanup task.  

Implementation PR: #220138
Cloud settings allowlist PR:
elastic/cloud#144070

---------

Co-authored-by: Florent Le Borgne <florent.leborgne@elastic.co>
szaffarano pushed a commit to szaffarano/kibana that referenced this pull request Aug 5, 2025
## Summary

This PR adds documentation for unused URLs cleanup task.  

Implementation PR: elastic#220138
Cloud settings allowlist PR:
elastic/cloud#144070
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
## Summary

This PR adds documentation for unused URLs cleanup task.  

Implementation PR: elastic#220138
Cloud settings allowlist PR:
elastic/cloud#144070
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:enhancement Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete unused URL saved objects to avoid upgrade downtime
8 participants