From 0cae4f3f401e59d0cfcdbdbad008869163b7324e Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Tue, 15 Jul 2025 13:41:53 -0400 Subject: [PATCH 1/4] [Response Ops][Reporting] Fixing next run calculation in list scheduled report API (#227704) ## Summary Fixes a small bug in the next run calculation when using the list scheduled report API. This takes the `rrule.dtstart` into account if it is defined and in the future. If it is in the past, defaults to using `Date.now()` as before. --------- Co-authored-by: Elastic Machine (cherry picked from commit a893aa7744848877c0922c5a2ba4b53f73ba4e5a) --- .../common/scheduled/scheduled_query.test.ts | 76 +++++++++++++++++++ .../common/scheduled/scheduled_query.ts | 23 +++++- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.test.ts b/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.test.ts index a999c43311e7a..f6fd06509cb0b 100644 --- a/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.test.ts +++ b/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.test.ts @@ -25,6 +25,7 @@ import { transformResponse, scheduledQueryFactory, CreatedAtSearchResponse, + transformSingleResponse, } from './scheduled_query'; import { ReportingCore } from '../../..'; import { ScheduledReportType } from '../../../types'; @@ -1216,6 +1217,81 @@ describe('transformResponse', () => { }); }); + it('should correctly transform a response with rrule.dtstart is in the future', () => { + jest.useFakeTimers(); + jest.setSystemTime(new Date('2025-05-06T21:10:17.137Z')); + + // current time is 2025-05-06T21:10:17.137Z which is a Tuesday + // schedule is set to run every Friday at 17:00 UTC + // start time is set to 2025-05-11T12:00:00.000Z (which is a Sunday) + // next run should be the next Friday after 2025-05-11T12:00:00.000Z which is 2025-05-16T17:00:00.000Z + // not the actual next friday which would be 2025-05-09T17:00:00.000Z + const dtstart = '2025-05-11T12:00:00.000Z'; + expect( + transformSingleResponse(mockLogger, { + type: 'scheduled_report', + id: 'aa8b6fb3-cf61-4903-bce3-eec9ddc823ca', + namespaces: ['a-space'], + attributes: { + createdAt: '2025-05-06T21:10:17.137Z', + createdBy: 'elastic', + enabled: true, + jobType: 'printable_pdf_v2', + meta: { + isDeprecated: false, + layout: 'preserve_layout', + objectType: 'dashboard', + }, + migrationVersion: '9.1.0', + title: '[Logs] Web Traffic', + payload, + schedule: { + rrule: { + dtstart, + freq: 3, + interval: 1, + byhour: [17], + byminute: [0], + byweekday: ['FR'], + tzid: 'UTC', + }, + }, + }, + references: [], + managed: false, + updated_at: '2025-05-06T21:10:17.137Z', + created_at: '2025-05-06T21:10:17.137Z', + version: 'WzEsMV0=', + coreMigrationVersion: '8.8.0', + typeMigrationVersion: '10.1.0', + score: 0, + }) + ).toEqual({ + id: 'aa8b6fb3-cf61-4903-bce3-eec9ddc823ca', + created_at: '2025-05-06T21:10:17.137Z', + created_by: 'elastic', + enabled: true, + jobtype: 'printable_pdf_v2', + next_run: '2025-05-16T17:00:00.000Z', + payload: jsonPayload, + schedule: { + rrule: { + dtstart, + freq: 3, + interval: 1, + byhour: [17], + byminute: [0], + byweekday: ['FR'], + tzid: 'UTC', + }, + }, + space_id: 'a-space', + title: '[Logs] Web Traffic', + }); + + jest.useRealTimers(); + }); + it('handles malformed payload', () => { const malformedSo = { ...savedObjects[0], diff --git a/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.ts b/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.ts index f60aab8776ff1..05028a1794818 100644 --- a/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.ts +++ b/x-pack/platform/plugins/private/reporting/server/routes/common/scheduled/scheduled_query.ts @@ -73,10 +73,25 @@ export function transformSingleResponse( ); const schedule = so.attributes.schedule; - const _rrule = new RRule({ - ...schedule.rrule, - dtstart: new Date(), - }); + + // get start date + let dtstart = new Date(); + const rruleStart = schedule.rrule.dtstart; + if (rruleStart) { + try { + // if start date is provided and in the future, use it, otherwise use current time + const startDateValue = new Date(rruleStart).valueOf(); + const now = Date.now(); + if (startDateValue > now) { + dtstart = new Date(startDateValue + 60000); // add 1 minute to ensure it's in the future + } + } catch (e) { + logger.debug( + `Failed to parse rrule.dtstart for scheduled report next run calculation - default to now ${id}: ${e.message}` + ); + } + } + const _rrule = new RRule({ ...schedule.rrule, dtstart }); let payload: ReportApiJSON['payload'] | undefined; try { From d749d787be1f88deb2a97f9b74f3f300dc3374b5 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:00:05 +0000 Subject: [PATCH 2/4] [CI] Auto-commit changed files from 'node scripts/generate codeowners' --- .github/CODEOWNERS | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1ba25cba197ef..f4160b3878471 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -429,7 +429,7 @@ src/platform/packages/shared/kbn-babel-register @elastic/kibana-operations src/platform/packages/shared/kbn-cache-cli @elastic/kibana-operations src/platform/packages/shared/kbn-calculate-auto @elastic/obs-ux-management-team src/platform/packages/shared/kbn-calculate-width-from-char-count @elastic/kibana-visualizations -src/platform/packages/shared/kbn-cases-components @elastic/kibana-cases +src/platform/packages/shared/kbn-cases-components @elastic/response-ops src/platform/packages/shared/kbn-cbor @elastic/kibana-operations src/platform/packages/shared/kbn-cell-actions @elastic/security-threat-hunting-investigations src/platform/packages/shared/kbn-chart-icons @elastic/kibana-visualizations @@ -932,7 +932,7 @@ x-pack/platform/plugins/shared/aiops @elastic/ml-ui x-pack/platform/plugins/shared/alerting @elastic/response-ops x-pack/platform/plugins/shared/apm_sources_access @elastic/obs-ux-infra_services-team x-pack/platform/plugins/shared/automatic_import @elastic/security-scalability -x-pack/platform/plugins/shared/cases @elastic/kibana-cases +x-pack/platform/plugins/shared/cases @elastic/response-ops @elastic/kibana-cases x-pack/platform/plugins/shared/cloud @elastic/kibana-core x-pack/platform/plugins/shared/content_connectors @elastic/search-kibana x-pack/platform/plugins/shared/dashboard_enhanced @elastic/kibana-presentation @@ -984,16 +984,16 @@ x-pack/platform/test/alerting_api_integration/common/plugins/alerts_restricted @ x-pack/platform/test/alerting_api_integration/common/plugins/task_manager_fixture @elastic/response-ops x-pack/platform/test/alerting_api_integration/packages/helpers @elastic/response-ops x-pack/platform/test/api_integration/apis/entity_manager/fixture_plugin @elastic/obs-entities -x-pack/platform/test/cases_api_integration/common/plugins/cases @elastic/kibana-cases -x-pack/platform/test/cases_api_integration/common/plugins/observability @elastic/kibana-cases -x-pack/platform/test/cases_api_integration/common/plugins/security_solution @elastic/kibana-cases +x-pack/platform/test/cases_api_integration/common/plugins/cases @elastic/response-ops +x-pack/platform/test/cases_api_integration/common/plugins/observability @elastic/response-ops +x-pack/platform/test/cases_api_integration/common/plugins/security_solution @elastic/response-ops x-pack/platform/test/cloud_integration/plugins/saml_provider @elastic/kibana-core x-pack/platform/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin @elastic/kibana-security x-pack/platform/test/functional_cors/plugins/kibana_cors_test @elastic/kibana-security x-pack/platform/test/functional_embedded/plugins/iframe_embedded @elastic/kibana-core x-pack/platform/test/functional_execution_context/plugins/alerts @elastic/kibana-core x-pack/platform/test/functional_with_es_ssl/plugins/alerts @elastic/response-ops -x-pack/platform/test/functional_with_es_ssl/plugins/cases @elastic/kibana-cases +x-pack/platform/test/functional_with_es_ssl/plugins/cases @elastic/response-ops x-pack/platform/test/licensing_plugin/plugins/test_feature_usage @elastic/kibana-security x-pack/platform/test/plugin_api_integration/plugins/elasticsearch_client @elastic/kibana-core x-pack/platform/test/plugin_api_integration/plugins/event_log @elastic/response-ops @@ -2954,4 +2954,11 @@ x-pack/plugins/observability_solution/synthetics/server/saved_objects/synthetics # See https://github.com/elastic/kibana/pull/199404 # Prevent backport assignments -* @kibanamachine \ No newline at end of file +* @kibanamachine +#### +## These rules are always last so they take ultimate priority over everything else +#### + +# See https://github.com/elastic/kibana/pull/199404 +# Prevent backport assignments +* @kibanamachine From 098cc920b72a16d0011cd037d4683f6114882aeb Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:11:11 +0000 Subject: [PATCH 3/4] [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs' --- .github/CODEOWNERS | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f4160b3878471..73c5ba6611fd0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2955,10 +2955,3 @@ x-pack/plugins/observability_solution/synthetics/server/saved_objects/synthetics # See https://github.com/elastic/kibana/pull/199404 # Prevent backport assignments * @kibanamachine -#### -## These rules are always last so they take ultimate priority over everything else -#### - -# See https://github.com/elastic/kibana/pull/199404 -# Prevent backport assignments -* @kibanamachine From 54b32f6caf7bb7a96466ed1f6919444824cb3d01 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 15 Jul 2025 23:52:29 +0100 Subject: [PATCH 4/4] chore(NA): update CODEOWNERS --- .github/CODEOWNERS | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 73c5ba6611fd0..61eaf5647f4a3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -429,7 +429,7 @@ src/platform/packages/shared/kbn-babel-register @elastic/kibana-operations src/platform/packages/shared/kbn-cache-cli @elastic/kibana-operations src/platform/packages/shared/kbn-calculate-auto @elastic/obs-ux-management-team src/platform/packages/shared/kbn-calculate-width-from-char-count @elastic/kibana-visualizations -src/platform/packages/shared/kbn-cases-components @elastic/response-ops +src/platform/packages/shared/kbn-cases-components @elastic/kibana-cases src/platform/packages/shared/kbn-cbor @elastic/kibana-operations src/platform/packages/shared/kbn-cell-actions @elastic/security-threat-hunting-investigations src/platform/packages/shared/kbn-chart-icons @elastic/kibana-visualizations @@ -932,7 +932,7 @@ x-pack/platform/plugins/shared/aiops @elastic/ml-ui x-pack/platform/plugins/shared/alerting @elastic/response-ops x-pack/platform/plugins/shared/apm_sources_access @elastic/obs-ux-infra_services-team x-pack/platform/plugins/shared/automatic_import @elastic/security-scalability -x-pack/platform/plugins/shared/cases @elastic/response-ops @elastic/kibana-cases +x-pack/platform/plugins/shared/cases @elastic/kibana-cases x-pack/platform/plugins/shared/cloud @elastic/kibana-core x-pack/platform/plugins/shared/content_connectors @elastic/search-kibana x-pack/platform/plugins/shared/dashboard_enhanced @elastic/kibana-presentation @@ -984,16 +984,16 @@ x-pack/platform/test/alerting_api_integration/common/plugins/alerts_restricted @ x-pack/platform/test/alerting_api_integration/common/plugins/task_manager_fixture @elastic/response-ops x-pack/platform/test/alerting_api_integration/packages/helpers @elastic/response-ops x-pack/platform/test/api_integration/apis/entity_manager/fixture_plugin @elastic/obs-entities -x-pack/platform/test/cases_api_integration/common/plugins/cases @elastic/response-ops -x-pack/platform/test/cases_api_integration/common/plugins/observability @elastic/response-ops -x-pack/platform/test/cases_api_integration/common/plugins/security_solution @elastic/response-ops +x-pack/platform/test/cases_api_integration/common/plugins/cases @elastic/kibana-cases +x-pack/platform/test/cases_api_integration/common/plugins/observability @elastic/kibana-cases +x-pack/platform/test/cases_api_integration/common/plugins/security_solution @elastic/kibana-cases x-pack/platform/test/cloud_integration/plugins/saml_provider @elastic/kibana-core x-pack/platform/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin @elastic/kibana-security x-pack/platform/test/functional_cors/plugins/kibana_cors_test @elastic/kibana-security x-pack/platform/test/functional_embedded/plugins/iframe_embedded @elastic/kibana-core x-pack/platform/test/functional_execution_context/plugins/alerts @elastic/kibana-core x-pack/platform/test/functional_with_es_ssl/plugins/alerts @elastic/response-ops -x-pack/platform/test/functional_with_es_ssl/plugins/cases @elastic/response-ops +x-pack/platform/test/functional_with_es_ssl/plugins/cases @elastic/kibana-cases x-pack/platform/test/licensing_plugin/plugins/test_feature_usage @elastic/kibana-security x-pack/platform/test/plugin_api_integration/plugins/elasticsearch_client @elastic/kibana-core x-pack/platform/test/plugin_api_integration/plugins/event_log @elastic/response-ops