Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
a74e49d
Support rrule for task scheduling
ersin-erdal Apr 9, 2025
6163f7e
remove redundant return
ersin-erdal Apr 9, 2025
20ecece
add functional tests
ersin-erdal Apr 11, 2025
c29a08e
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Apr 11, 2025
de20db1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 11, 2025
65f0960
fix linting
ersin-erdal Apr 11, 2025
2dde5f6
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal Apr 11, 2025
717cadb
fix linter
ersin-erdal Apr 11, 2025
72b108e
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Apr 11, 2025
38e69ef
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 11, 2025
c9e71ba
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Apr 11, 2025
5f6fad9
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 11, 2025
d05d9c8
Allowing shared concurrency task types
ymao1 Apr 14, 2025
4a04b90
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 14, 2025
249f14c
set second to [0]
ersin-erdal Apr 15, 2025
4c60d8e
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal Apr 15, 2025
4a14142
testing schedule is more resilient
ersin-erdal Apr 15, 2025
4ec1bca
remove "only"
ersin-erdal Apr 15, 2025
1275f1e
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 16, 2025
8aff2c9
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 16, 2025
04b70a2
Merge branch 'main' into shared-concurrency-tasks
elasticmachine Apr 23, 2025
c9547ae
Merge branch 'main' into shared-concurrency-tasks
elasticmachine Apr 25, 2025
850ec64
throw when interval is not provided for the next run calculation
ersin-erdal Apr 28, 2025
10c40e5
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal Apr 28, 2025
af75dfb
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal Apr 28, 2025
95cf333
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Apr 28, 2025
d5227aa
update read me
ersin-erdal Apr 28, 2025
2a1482e
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal Apr 28, 2025
372d4c7
Merge branch 'main' into shared-concurrency-tasks
elasticmachine Apr 28, 2025
62fe072
update read me
ersin-erdal Apr 28, 2025
0f0685e
export Frequency and Weekday from TM
ersin-erdal Apr 28, 2025
cc65fd5
Merge branch 'pr/217728' into report-dependencies
ymao1 Apr 28, 2025
11053d1
Merge branch 'shared-concurrency-tasks' into report-dependencies
ymao1 Apr 28, 2025
23d837d
Schedule report api
ymao1 Apr 28, 2025
bbabb1f
Schedule report api
ymao1 Apr 28, 2025
f5bb665
Cleanup
ymao1 Apr 28, 2025
5375fd2
Stubbing out task
ymao1 Apr 28, 2025
f039e51
add rrule examples
ersin-erdal Apr 29, 2025
e75e796
fix rrule example
ersin-erdal Apr 29, 2025
c7e0fdc
Schedule report task
ymao1 Apr 29, 2025
424d733
PR feedback
ymao1 Apr 29, 2025
0514306
Merge branch 'main' of github.com:elastic/kibana into shared-concurre…
ymao1 Apr 29, 2025
fd55806
Adding unit tests
ymao1 Apr 30, 2025
d42d1bd
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Apr 30, 2025
214fcd5
Fixing types
ymao1 Apr 30, 2025
5019e54
Merge branch 'scheduled-reports-task' of github.com:ymao1/kibana into…
ymao1 Apr 30, 2025
5ee4309
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 30, 2025
2d6dfab
Fixing types
ymao1 Apr 30, 2025
b2d9bbd
Merge branch 'pr/217728' into report-dependencies
ymao1 Apr 30, 2025
8caeb79
Merge branch 'shared-concurrency-tasks' into report-dependencies
ymao1 Apr 30, 2025
7a0d9c5
Merge branch 'scheduled-reports' of github.com:elastic/kibana into re…
ymao1 Apr 30, 2025
64cfb78
Merge branch 'report-dependencies' into scheduled-reports-api
ymao1 Apr 30, 2025
b98f26c
Fixing types
ymao1 Apr 30, 2025
3fd59a1
Cleanup
ymao1 Apr 30, 2025
0370162
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 30, 2025
ed0a7c0
Merge
ymao1 Apr 30, 2025
e47833c
Updating tests
ymao1 Apr 30, 2025
0277de9
Fixing tests
ymao1 Apr 30, 2025
b0ce938
Merge branch 'scheduled-reports-api' of github.com:ymao1/kibana into …
ymao1 Apr 30, 2025
2e48fe2
Merge branch 'scheduled-reports-api' into scheduled-reports-task
ymao1 May 1, 2025
530ac2c
Fixing tests
ymao1 May 1, 2025
cec4e50
Cleanup
ymao1 May 1, 2025
a0cff7a
Cleanup
ymao1 May 1, 2025
e770dce
Title includes runAt time
ymao1 May 2, 2025
626cf01
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal May 2, 2025
fbb3f85
remove mappings
ersin-erdal May 2, 2025
f361058
remove mappings
ersin-erdal May 2, 2025
7099229
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine May 2, 2025
a0e3fc9
Merge
ymao1 May 2, 2025
baa41cb
Merge branch 'report-dependencies' of github.com:ymao1/kibana into re…
ymao1 May 2, 2025
2947bcc
Merge branch 'pr/217728' into report-dependencies
ymao1 May 2, 2025
3afe5b2
Fix
ymao1 May 2, 2025
dc96d64
Merge and add createdBy mapping
ymao1 May 2, 2025
c1884f3
Merge branch 'scheduled-reports-api' into scheduled-reports-task
ymao1 May 2, 2025
5398116
remove schema from v4
ersin-erdal May 2, 2025
5a800d5
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal May 2, 2025
9cd5011
types types types
ymao1 May 2, 2025
8faaf40
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal May 3, 2025
aaf4309
Merge branch 'main' into shared-concurrency-tasks
elasticmachine May 5, 2025
5c55c02
Merge branch 'main' into 216308-support-rrule-for-task-scheduling
ersin-erdal May 5, 2025
fc2b386
Merge branch 'scheduled-reports' of github.com:elastic/kibana into re…
ymao1 May 5, 2025
4fed516
Merge branch 'shared-concurrency-tasks' into report-dependencies
ymao1 May 5, 2025
d1104e4
Merge branch 'pr/217728' into report-dependencies
ymao1 May 5, 2025
c9911fa
Merge branch 'report-dependencies' into scheduled-reports-api
ymao1 May 5, 2025
85cb015
Updating types
ymao1 May 5, 2025
e811ec2
Merge
ymao1 May 5, 2025
d18fcaf
Fixing types
ymao1 May 5, 2025
0253ced
add explicit error log when the next run at cannot be calculated
ersin-erdal May 5, 2025
590e659
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal May 5, 2025
3834eaf
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine May 5, 2025
c7e26f0
add missing logger
ersin-erdal May 5, 2025
8455d3c
Merge branch '216308-support-rrule-for-task-scheduling' of github.com…
ersin-erdal May 5, 2025
1e3d3e9
Handling notification
ymao1 May 5, 2025
bbea405
fix unit test
ersin-erdal May 5, 2025
4df59d0
Merge
ymao1 May 6, 2025
17bdcd0
Merge branch 'report-dependencies' into scheduled-reports-api
ymao1 May 6, 2025
4a4e0c5
Merge branch 'scheduled-reports-api' into scheduled-reports-task
ymao1 May 6, 2025
e20f1bf
Cleanup
ymao1 May 6, 2025
402ef5c
Merge
ymao1 May 6, 2025
d5799f5
Merge
ymao1 May 6, 2025
bfef31b
Merge branch 'pr/217728' into report-dependencies
ymao1 May 6, 2025
8cc0976
Merge branch 'report-dependencies' into scheduled-reports-api
ymao1 May 6, 2025
03c8304
Merge branch 'scheduled-reports-api' into scheduled-reports-task
ymao1 May 6, 2025
2bd0d5d
Adding schedule reports API
ymao1 May 7, 2025
d0da6b4
Merge
ymao1 May 7, 2025
9a7bda6
Fixing bad merge
ymao1 May 7, 2025
8cc046b
Adding changes for sending scheduled report emails
doakalexi May 8, 2025
6a7b62e
Merge
ymao1 May 8, 2025
99f186c
Merge
ymao1 May 8, 2025
601fbc6
Fixing types
ymao1 May 8, 2025
bc09318
Adding cc,bcc fields and validation for max recipients
ymao1 May 8, 2025
ea37895
Merge
ymao1 May 8, 2025
6c80c8c
Updating exchange code
doakalexi May 9, 2025
d87b6f1
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
ymao1 May 19, 2025
def242b
Merge branch 'scheduled-reports-api' into scheduled-reports-task
ymao1 May 19, 2025
d7d0806
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
doakalexi May 19, 2025
4ca09af
Merge
ymao1 May 20, 2025
f3efd5a
Fixing attempts
ymao1 May 20, 2025
4750222
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
ymao1 May 21, 2025
910b1e5
Fixing issue getting report content from es
doakalexi May 22, 2025
ce49347
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
doakalexi May 22, 2025
7b2c873
Merge branch 'scheduled-reports-task' into scheduled-reports-email-at…
doakalexi May 22, 2025
44d0674
Fixing type checks
doakalexi May 22, 2025
c9d90b0
Fixing test failures
doakalexi May 23, 2025
563741e
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
doakalexi May 30, 2025
1f8541a
Removing change from merge conflicts
doakalexi May 30, 2025
cfad8ac
Adding another test
doakalexi Jun 2, 2025
e7c3df7
Remove duplicate change
doakalexi Jun 2, 2025
778c551
Updates from pr comments
doakalexi Jun 3, 2025
e5ef677
Adding notify() tests
doakalexi Jun 4, 2025
85b8878
Fixing failing test
doakalexi Jun 4, 2025
dfeaf86
Fixing test failures
doakalexi Jun 4, 2025
579966d
Merge branch 'scheduled-reports' into scheduled-reports-email-attachm…
doakalexi Jun 6, 2025
0f05f25
Update x-pack/platform/plugins/private/reporting/server/lib/tasks/run…
doakalexi Jun 6, 2025
894e62f
More updates from pr comments
doakalexi Jun 6, 2025
52956ba
Merge branch 'scheduled-reports-email-attachments' of github.com:doak…
doakalexi Jun 6, 2025
7a8c6a3
Updating for csv
doakalexi Jun 9, 2025
0473a06
Merge branch 'scheduled-reports' of github.com:elastic/kibana into sc…
doakalexi Jun 10, 2025
e382f34
Moving around notificaton check
doakalexi Jun 11, 2025
d4f9afd
Updating for pr comments
doakalexi Jun 11, 2025
018dcce
Merge branch 'scheduled-reports' into scheduled-reports-email-attachm…
doakalexi Jun 16, 2025
f3eb0fd
Updating for pr comments
doakalexi Jun 16, 2025
3bea61e
Merge branch 'scheduled-reports-email-attachments' of github.com:doak…
doakalexi Jun 16, 2025
e3944a9
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Jun 16, 2025
179a35e
Fixing type check
doakalexi Jun 16, 2025
d9537f3
Merge branch 'scheduled-reports-email-attachments' of github.com:doak…
doakalexi Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions x-pack/platform/plugins/private/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
import type { ReportingPluginRouter } from './types';
import { EventTracker } from './usage';
import { SCHEDULED_REPORT_SAVED_OBJECT_TYPE } from './saved_objects';
import { EmailNotificationService } from './services/notifications/email_notification_service';
import { API_PRIVILEGES } from './features';

export interface ReportingInternalSetup {
Expand Down Expand Up @@ -181,12 +182,16 @@ export class ReportingCore {
et.start({ ...startDeps });
});

const { taskManager } = startDeps;
const { taskManager, notifications } = startDeps;
const emailNotificationService = new EmailNotificationService({
notifications,
});

const { runSingleReportTask, runScheduledReportTask } = this;
// enable this instance to generate reports
await Promise.all([
runSingleReportTask.init(taskManager),
runScheduledReportTask.init(taskManager),
runScheduledReportTask.init(taskManager, emailNotificationService),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,48 @@ describe('ReportingStore', () => {
`);
});

it('setReportWarning sets the status of a saved report to warning', async () => {
const store = new ReportingStore(mockCore, mockLogger);
const report = new SavedReport({
_id: 'id-of-processing',
_index: '.reporting-test-index-12345',
_seq_no: 42,
_primary_term: 10002,
jobtype: 'test-report',
created_by: 'created_by_test_string',
max_attempts: 50,
payload: {
title: 'test report',
headers: 'rp_test_headers',
objectType: 'testOt',
browserTimezone: 'ABC',
version: '7.14.0',
},
timeout: 30000,
});

await store.setReportWarning(report, {
output: { warnings: ['warning1'] },
warning: 'warning2',
} as any);

const [[updateCall]] = mockEsClient.update.mock.calls;

const response = (updateCall as estypes.UpdateRequest)?.doc as Report;
expect(response.migration_version).toBe(`7.14.0`);
expect(response.status).toBe(`completed_with_warnings`);
expect(response.output).toMatchInlineSnapshot(`
Object {
"warnings": Array [
"warning1",
"warning2",
],
}
`);
expect(updateCall.if_seq_no).toBe(42);
expect(updateCall.if_primary_term).toBe(10002);
});

describe('start', () => {
class TestReportingStore extends ReportingStore {
constructor(...args: ConstructorParameters<typeof ReportingStore>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export type ReportCompletedFields = Required<{
output: Omit<ReportOutput, 'content'> | null;
}>;

export interface ReportWarningFields {
output: Omit<ReportOutput, 'content'>;
warning: string;
}

/*
* When searching for long-pending reports, we get a subset of fields
*/
Expand Down Expand Up @@ -337,4 +342,31 @@ export class ReportingStore {

return body;
}

public async setReportWarning(
report: SavedReport,
warningInfo: ReportWarningFields
): Promise<UpdateResponse<ReportDocument>> {
const { output, warning } = warningInfo;
const warnings: string[] = output.warnings ?? [];
warnings.push(warning);
const doc = sourceDoc({
output: {
...output,
warnings,
},
status: JOB_STATUS.WARNINGS,
} as ReportSource);

let body: UpdateResponse<ReportDocument>;
try {
const client = await this.getClient();
body = await client.update<unknown, unknown, ReportDocument>(esDocForUpdate(report, doc));
} catch (err) {
this.logError(`Error in updating status to warning! Report: ${jobDebugMessage(report)}`, err, report); // prettier-ignore
throw err;
}

return body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { timeout } from 'rxjs';
import { Writable } from 'stream';
import type { FakeRawRequest, Headers } from '@kbn/core-http-server';
import { UpdateResponse } from '@elastic/elasticsearch/lib/api/types';
import type { KibanaRequest, Logger } from '@kbn/core/server';
import type { KibanaRequest, Logger, SavedObject } from '@kbn/core/server';
import {
CancellationToken,
KibanaShuttingDownError,
Expand Down Expand Up @@ -44,9 +44,11 @@ import { ReportTaskParams, ReportingTask, ReportingTaskStatus, TIME_BETWEEN_ATTE
import type { ReportingCore } from '../..';
import { EventTracker } from '../../usage';
import { Report, SavedReport } from '../store';
import type { ReportFailedFields } from '../store/store';
import type { ReportFailedFields, ReportWarningFields } from '../store/store';
import { errorLogger } from './error_logger';
import { finishedWithNoPendingCallbacks, getContentStream } from '../content_stream';
import { EmailNotificationService } from '../../services/notifications/email_notification_service';
import { ScheduledReportType } from '../../types';

type CompletedReportOutput = Omit<ReportOutput, 'content'>;

Expand Down Expand Up @@ -91,6 +93,7 @@ export interface PrepareJobResults {
jobId: string;
report?: SavedReport;
task?: ReportTaskParams;
reportSO?: SavedObject<ScheduledReportType>;
}

type ReportTaskParamsType = Record<string, any>;
Expand All @@ -106,6 +109,7 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>
protected kibanaName?: string;
protected exportTypesRegistry: ExportTypesRegistry;
protected eventTracker?: EventTracker;
protected emailNotificationService?: EmailNotificationService;

constructor(protected readonly opts: ConstructorOpts) {
this.logger = opts.logger.get('runTask');
Expand All @@ -127,13 +131,27 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>

protected abstract getMaxAttempts(): number | undefined;

protected abstract notify(
report: SavedReport,
taskInstance: ConcreteTaskInstance,
output: TaskRunResult,
byteSize: number,
reportSO?: SavedObject<ScheduledReportType>,
spaceId?: string
): Promise<void>;

// Public methods
public async init(taskManager: TaskManagerStartContract) {
public async init(
taskManager: TaskManagerStartContract,
emailNotificationService?: EmailNotificationService
) {
this.taskManagerStart = taskManager;

const { uuid, name } = this.opts.reporting.getServerInfo();
this.kibanaId = uuid;
this.kibanaName = name;

this.emailNotificationService = emailNotificationService;
}

public getStatus() {
Expand Down Expand Up @@ -171,6 +189,11 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>
return exportType.jobContentEncoding;
}

protected getJobContentExtension(jobType: string) {
const exportType = this.exportTypesRegistry.getByJobType(jobType);
return exportType.jobContentExtension;
}

protected async failJob(
report: SavedReport,
error?: ReportingError
Expand Down Expand Up @@ -227,6 +250,24 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>
return await store.setReportError(report, doc);
}

protected async saveExecutionWarning(
report: SavedReport,
output: CompletedReportOutput,
message: string
): Promise<UpdateResponse<ReportDocument>> {
const logger = this.logger.get(report._id);
logger.warn(message);

// update the report in the store
const store = await this.opts.reporting.getStore();
const doc: ReportWarningFields = {
output,
warning: message,
};

return await store.setReportWarning(report, doc);
}

protected formatOutput(output: CompletedReportOutput | ReportingError): ReportOutput {
const docOutput = {} as ReportOutput;
const unknownMime = null;
Expand Down Expand Up @@ -440,6 +481,7 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>
jobId: jId,
report: preparedReport,
task,
reportSO,
} = await this.prepareJob(taskInstance);
jobId = jId;
report = preparedReport;
Expand Down Expand Up @@ -517,18 +559,28 @@ export abstract class RunReportTask<TaskParams extends ReportTaskParamsType>
report._seq_no = stream.getSeqNo()!;
report._primary_term = stream.getPrimaryTerm()!;

const byteSize = stream.bytesWritten;
eventLog.logExecutionComplete({
...(output.metrics ?? {}),
byteSize: stream.bytesWritten,
byteSize,
});

if (output) {
logger.debug(`Job output size: ${stream.bytesWritten} bytes.`);
logger.debug(`Job output size: ${byteSize} bytes.`);
// Update the job status to "completed"
report = await this.completeJob(report, {
...output,
size: stream.bytesWritten,
size: byteSize,
});

await this.notify(
report,
taskInstance,
output,
byteSize,
reportSO,
task.payload.spaceId
);
}

// untrack the report for concurrency awareness
Expand Down
Loading