Skip to content

Conversation

@ymao1
Copy link
Contributor

@ymao1 ymao1 commented Apr 30, 2025

Towards #216313

Note

This PR will be merged into a feature branch

Summary

This PR adds the scheduled_report task, which generates reports on a recurring cadence.

  • maxConcurrency of this task is 1 so only one can run at a time
  • this task shares concurrency with the existing report:execute task, so only one of either task type can run at a time
  • this task requires an API key to run so it will only run when ES security and API keys are enabled and a permanent encryption key for Kibana is set
  • when the task runs, it creates a new ReportSource document in the .kibana-reporting index that stores the final base64 encoded generated output. This ReportSource matches the data model of existing reports with the addition of a scheduled_report_id field which links to the scheduled report saved object ID.

Verify

  • Use the dev console to schedule some reports.
  • Verify the the reports get generated at the expected cadence
  • Verify that the correct time range is used for each scheduled report

Note, the UI has not been updated to differentiate between scheduled and single run reports. They will look the same from in the report listing, except the scheduled report will have a timestamp appended to the report name.

In the cloud deployment for this PR, we have an example scheduled report that is running every day at 4:45 EDT: https://kibana-pr-219770.kb.us-west2.gcp.elastic-cloud.com/app/management/insightsAndAlerting/reporting

ersin-erdal and others added 30 commits April 9, 2025 18:38
…:ersin-erdal/kibana into 216308-support-rrule-for-task-scheduling
… src/core/server/integration_tests/ci_checks'
…:ersin-erdal/kibana into 216308-support-rrule-for-task-scheduling
…:ersin-erdal/kibana into 216308-support-rrule-for-task-scheduling
… src/core/server/integration_tests/ci_checks'
…:ersin-erdal/kibana into 216308-support-rrule-for-task-scheduling
@elasticmachine
Copy link
Contributor

elasticmachine commented May 20, 2025

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #37 / console app misc console behavior keyboard shortcuts open documentation should open documentation when Ctrl+/ is pressed
  • [job] [logs] FTR Configs #37 / console app misc console behavior keyboard shortcuts open documentation should open documentation when Ctrl+/ is pressed

History

@ymao1 ymao1 self-assigned this May 21, 2025
@ymao1 ymao1 marked this pull request as ready for review May 21, 2025 17:17
@ymao1 ymao1 requested a review from a team as a code owner May 21, 2025 17:17
@ymao1 ymao1 requested review from pmuellr and umbopepato May 21, 2025 17:18
@ymao1 ymao1 changed the title [Response Ops][Reporting] Scheduled Reports - Task [Response Ops][Reporting] Scheduled Reports - Task (merging into feature branch) May 21, 2025
@pmuellr
Copy link
Member

pmuellr commented May 28, 2025

Took me a bit to figure out, so saving for posterity. curl command to schedule the web logs dashboard to generate a report every hour:

curl $KB_URL/internal/reporting/schedule/printablePdfV2 \
  -H "kbn-xsrf: foo" \
  -H "x-elastic-internal-origin: kibana" \
  -H "content-type: application/json" \
  -d '
{
  "jobParams":"(browserTimezone:America/New_York,layout:(dimensions:(height:2220,width:1335),id:preserve_layout),locatorParams:!((id:DASHBOARD_APP_LOCATOR,params:(dashboardId:edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b,preserveSavedFilters:!t,timeRange:(from:now-7d/d,to:now),useHash:!f,viewMode:edit))),objectType:dashboard,title:LogsWebTraffic)",
  "schedule": { "rrule": { "freq": 3, "interval": 1, "byhour": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23] } }
}
'

@pmuellr
Copy link
Member

pmuellr commented May 29, 2025

I tried creating a scheduled report in a non-default space, via my incantation above, but with a /s/test prefix, and saw the following logged when the report finally ran:

[ERROR][plugins.reporting.runTask] Error: Saved object [scheduled_report/ebcfc3e8-13ad-405c-b486-66b4bcc5ea0e] not found
    at Function.createGenericNotFoundError (saved_objects_error_helpers.ts:259:28)
    at performGet (get.ts:73:36)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at SavedObjectsRepository.get (repository.ts:371:12)
    at RunScheduledReportTask.prepareJob (run_scheduled_report.ts:44:24)
    at Object.run (run_report.ts:443:15)

I actually referencede a dashboard that WASN'T in this space, which I realized later, so I wouldn't have expected it to actually generate a report. But it looks like it had a problem loading the scheduled report saved object.

@pmuellr
Copy link
Member

pmuellr commented May 29, 2025

Given the error I saw, mentioned in the comment above, I noticed it did NOT get retried. I think this is by design, but probably something we want to figure out, since it sometimes happens that a retry will get the search indices warmed up to get a long-running report to succeed after an initial failure.

@ymao1
Copy link
Contributor Author

ymao1 commented May 29, 2025

I tried creating a scheduled report in a non-default space, via my incantation above, but with a /s/test prefix, and saw the following logged when the report finally ran:

Good catch! Updated to be space aware in 1f46d45

@ymao1
Copy link
Contributor Author

ymao1 commented May 29, 2025

Given the error I saw, mentioned in the comment above, I noticed it did NOT get retried. I think this is by design, but probably something we want to figure out, since it sometimes happens that a retry will get the search indices warmed up to get a long-running report to succeed after an initial failure.

Yea, we typically don't perform retries for recurring tasks so there's no built in retry. I think we'd have to update task manager to allow retries for recurring tasks if we want that ability. I can open an issue to discuss

@pmuellr
Copy link
Member

pmuellr commented May 30, 2025

Yea, we typically don't perform retries for recurring tasks so there's no built in retry. I think we'd have to update task manager to allow retries for recurring tasks if we want that ability. I can open an issue to discuss

Ya, let's open an issue. Given Tim's previous note that "subsequent attempts often succeed", I think we'll have to do something. Doesn't seem like a blocker to get the basic function out. Wondering if we'd just want to do an "inline retry" of these, which would complicate the task itself, but not require any new tasks, or changes to TM ...

@ymao1
Copy link
Contributor Author

ymao1 commented May 30, 2025

Ya, let's open an issue. Given Tim's previous note that "subsequent attempts often succeed", I think we'll have to do something. Doesn't seem like a blocker to get the basic function out. Wondering if we'd just want to do an "inline retry" of these, which would complicate the task itself, but not require any new tasks, or changes to TM ...

Issue: #222079

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, was able to generate PDF reports as usual in default and a test space, as well as schedule a report in both spaces, and have them run successfully.

}

// otherwise use internal repository
return savedObjects.createInternalRepository([SCHEDULED_REPORT_SAVED_OBJECT_TYPE]);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this could be confusing in the future, since it returns either a scoped or internal client. And complicates the typing (minor concern). Would it be better to have separate methods? It seems pretty obvious to me in the code, right now ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split into separate functions in ad65b91

@elasticmachine
Copy link
Contributor

elasticmachine commented May 30, 2025

💚 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
@kbn/reporting-common 90 93 +3

Async chunks

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

id before after diff
fleet 1.7MB 1.7MB +252.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
reporting 49.7KB 49.9KB +194.0B
Unknown metric groups

API count

id before after diff
@kbn/reporting-common 100 103 +3

History

cc @ymao1

@ymao1 ymao1 merged commit 9cf25dd into elastic:scheduled-reports May 30, 2025
10 checks passed
ymao1 added a commit that referenced this pull request Jun 19, 2025
Resolves #216313

## Summary

This is a feature branch that contains the following commits. Each
individual linked PR contains a summary and verification instructions.

* Schedule API - #219771
* Scheduled report task runner -
#219770
* List and disable API - #220922
* Audit logging - #221846
* Send scheduled report emails -
#220539
* Commit to check license -
f5f9d9d
* Update to list API response format -
#224262

---------

Co-authored-by: Ersin Erdal <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Ersin Erdal <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alexi Doak <[email protected]>
ymao1 added a commit to ymao1/kibana that referenced this pull request Jun 20, 2025
Resolves elastic#216313

## Summary

This is a feature branch that contains the following commits. Each
individual linked PR contains a summary and verification instructions.

* Schedule API - elastic#219771
* Scheduled report task runner -
elastic#219770
* List and disable API - elastic#220922
* Audit logging - elastic#221846
* Send scheduled report emails -
elastic#220539
* Commit to check license -
elastic@f5f9d9d
* Update to list API response format -
elastic#224262

---------

Co-authored-by: Ersin Erdal <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Ersin Erdal <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alexi Doak <[email protected]>
(cherry picked from commit a409627)

# Conflicts:
#	src/platform/packages/private/kbn-reporting/common/routes.ts
#	x-pack/platform/plugins/private/canvas/server/feature.test.ts
#	x-pack/platform/plugins/private/reporting/server/core.ts
#	x-pack/platform/plugins/private/reporting/server/features.ts
#	x-pack/platform/plugins/shared/features/server/__snapshots__/oss_features.test.ts.snap
#	x-pack/platform/test/api_integration/apis/features/features/features.ts
#	x-pack/test_serverless/api_integration/test_suites/chat/platform_security/authorization.ts
#	x-pack/test_serverless/api_integration/test_suites/observability/platform_security/authorization.ts
#	x-pack/test_serverless/api_integration/test_suites/search/platform_security/authorization.ts
#	x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts
ymao1 added a commit that referenced this pull request Jun 23, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Response Ops][Reporting] Scheduled Reports
(#221028)](#221028)

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

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

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-19T13:20:18Z","message":"[Response
Ops][Reporting] Scheduled Reports (#221028)\n\nResolves
https://github.com/elastic/kibana/issues/216313\n\n## Summary\n\nThis is
a feature branch that contains the following commits. Each\nindividual
linked PR contains a summary and verification instructions.\n\n*
Schedule API - https://github.com/elastic/kibana/pull/219771\n*
Scheduled report task runner
-\nhttps://github.com//pull/219770\n* List and disable API
- https://github.com/elastic/kibana/pull/220922\n* Audit logging -
https://github.com/elastic/kibana/pull/221846\n* Send scheduled report
emails -\nhttps://github.com//pull/220539\n* Commit to
check license
-\nhttps://github.com//pull/221028/commits/f5f9d9daedcd18447b6a02335a53631a44413788\n*
Update to list API response format
-\nhttps://github.com//pull/224262\n\n---------\n\nCo-authored-by:
Ersin Erdal <[email protected]>\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by: Ersin
Erdal <[email protected]>\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Alexi Doak
<[email protected]>","sha":"a409627765dfaf3d588c35a0d510b8d1857cd266","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:ResponseOps","release_note:feature","ci:cloud-deploy","ci:cloud-persist-deployment","Feature:Reporting:Framework","backport:version","v9.1.0","v8.19.0"],"title":"[Response
Ops][Reporting] Scheduled
Reports","number":221028,"url":"https://github.com/elastic/kibana/pull/221028","mergeCommit":{"message":"[Response
Ops][Reporting] Scheduled Reports (#221028)\n\nResolves
https://github.com/elastic/kibana/issues/216313\n\n## Summary\n\nThis is
a feature branch that contains the following commits. Each\nindividual
linked PR contains a summary and verification instructions.\n\n*
Schedule API - https://github.com/elastic/kibana/pull/219771\n*
Scheduled report task runner
-\nhttps://github.com//pull/219770\n* List and disable API
- https://github.com/elastic/kibana/pull/220922\n* Audit logging -
https://github.com/elastic/kibana/pull/221846\n* Send scheduled report
emails -\nhttps://github.com//pull/220539\n* Commit to
check license
-\nhttps://github.com//pull/221028/commits/f5f9d9daedcd18447b6a02335a53631a44413788\n*
Update to list API response format
-\nhttps://github.com//pull/224262\n\n---------\n\nCo-authored-by:
Ersin Erdal <[email protected]>\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by: Ersin
Erdal <[email protected]>\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Alexi Doak
<[email protected]>","sha":"a409627765dfaf3d588c35a0d510b8d1857cd266"}},"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/221028","number":221028,"mergeCommit":{"message":"[Response
Ops][Reporting] Scheduled Reports (#221028)\n\nResolves
https://github.com/elastic/kibana/issues/216313\n\n## Summary\n\nThis is
a feature branch that contains the following commits. Each\nindividual
linked PR contains a summary and verification instructions.\n\n*
Schedule API - https://github.com/elastic/kibana/pull/219771\n*
Scheduled report task runner
-\nhttps://github.com//pull/219770\n* List and disable API
- https://github.com/elastic/kibana/pull/220922\n* Audit logging -
https://github.com/elastic/kibana/pull/221846\n* Send scheduled report
emails -\nhttps://github.com//pull/220539\n* Commit to
check license
-\nhttps://github.com//pull/221028/commits/f5f9d9daedcd18447b6a02335a53631a44413788\n*
Update to list API response format
-\nhttps://github.com//pull/224262\n\n---------\n\nCo-authored-by:
Ersin Erdal <[email protected]>\nCo-authored-by: kibanamachine
<[email protected]>\nCo-authored-by: Ersin
Erdal <[email protected]>\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Alexi Doak
<[email protected]>","sha":"a409627765dfaf3d588c35a0d510b8d1857cd266"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:cloud-deploy Create or update a Cloud deployment ci:cloud-persist-deployment Persist cloud deployment indefinitely

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants