Skip to content

Commit 366408d

Browse files
committed
[Reporting] Replace Job Completion Notifier as NP Plugin
1 parent d1b046e commit 366408d

File tree

22 files changed

+605
-249
lines changed

22 files changed

+605
-249
lines changed

x-pack/.i18nrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"xpack.monitoring": "legacy/plugins/monitoring",
3030
"xpack.remoteClusters": "legacy/plugins/remote_clusters",
3131
"xpack.reporting": "legacy/plugins/reporting",
32+
"xpack.reportingNotifier": "plugins/reporting_notifier",
3233
"xpack.rollupJobs": "legacy/plugins/rollup",
3334
"xpack.searchProfiler": "legacy/plugins/searchprofiler",
3435
"xpack.siem": "legacy/plugins/siem",

x-pack/legacy/plugins/reporting/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const reporting = (kibana) => {
4545
embeddableActions: [
4646
'plugins/reporting/panel_actions/get_csv_panel_action',
4747
],
48-
hacks: ['plugins/reporting/hacks/job_completion_notifier'],
4948
home: ['plugins/reporting/register_feature'],
5049
managementSections: ['plugins/reporting/views/management'],
5150
injectDefaultVars(server, options) {

x-pack/legacy/plugins/reporting/public/hacks/__tests__/job_completion_notifier.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

x-pack/legacy/plugins/reporting/public/hacks/job_completion_notifier.js

Lines changed: 0 additions & 207 deletions
This file was deleted.

x-pack/legacy/plugins/reporting/server/routes/jobs.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import boom from 'boom';
8+
import { RequestQuery } from 'hapi';
89
import { Request, ResponseToolkit } from 'hapi';
910
import { API_BASE_URL } from '../../common/constants';
1011
import { JobDoc, KbnServer } from '../../types';
@@ -19,6 +20,12 @@ import {
1920

2021
const MAIN_ENTRY = `${API_BASE_URL}/jobs`;
2122

23+
type ListQuery = RequestQuery & {
24+
page: string;
25+
size: string;
26+
ids?: string; // optional field forbids us from extending RequestQuery
27+
};
28+
2229
export function registerJobs(server: KbnServer) {
2330
const jobsQuery = jobsQueryFactory(server);
2431
const getRouteConfig = getRouteConfigFactoryManagementPre(server);
@@ -30,12 +37,10 @@ export function registerJobs(server: KbnServer) {
3037
method: 'GET',
3138
config: getRouteConfig(),
3239
handler: (request: Request) => {
33-
// @ts-ignore
34-
const page = parseInt(request.query.page, 10) || 0;
35-
// @ts-ignore
36-
const size = Math.min(100, parseInt(request.query.size, 10) || 10);
37-
// @ts-ignore
38-
const jobIds = request.query.ids ? request.query.ids.split(',') : null;
40+
const { page: queryPage, size: querySize, ids: queryIds } = request.query as ListQuery;
41+
const page = parseInt(queryPage, 10) || 0;
42+
const size = Math.min(100, parseInt(querySize, 10) || 10);
43+
const jobIds = queryIds ? queryIds.split(',') : null;
3944

4045
const results = jobsQuery.list(
4146
request.pre.management.jobTypes,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const reportingPollConfig = {
8+
jobCompletionNotifier: { interval: 10000, intervalErrorMultiplier: 5 },
9+
jobsRefresh: { interval: 5000, intervalErrorMultiplier: 5 },
10+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
8+
'xpack.reporting.jobCompletionNotifications';
9+
10+
export const JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG = {
11+
jobCompletionNotifier: {
12+
interval: 10000,
13+
intervalErrorMultiplier: 5
14+
} // prettier-ignore
15+
};
16+
17+
export const API_BASE_URL = '/api/reporting/jobs';
18+
export const REPORTING_MANAGEMENT_HOME = '/app/kibana#/management/kibana/reporting';
19+
20+
export const JOB_STATUS_FAILED = 'failed';
21+
export const JOB_STATUS_COMPLETED = 'completed';
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import {
8+
CoreSetup,
9+
CoreStart,
10+
HttpServiceBase,
11+
Plugin,
12+
PluginInitializerContext,
13+
NotificationsStart,
14+
} from '../../../src/core/public';
15+
16+
export type JobId = string;
17+
export type JobStatus = 'completed' | 'processing' | 'failed';
18+
19+
export type HttpFn = () => HttpServiceBase;
20+
export type NotificationsFn = () => NotificationsStart;
21+
22+
export interface SourceJob {
23+
_id: JobId;
24+
_source: {
25+
status: JobStatus;
26+
output: {
27+
max_size_reached: boolean;
28+
csv_contains_formulas: boolean;
29+
};
30+
payload: {
31+
type: string;
32+
title: string;
33+
};
34+
};
35+
}
36+
37+
export interface JobContent {
38+
content: string;
39+
}
40+
41+
export interface JobSummary {
42+
id: JobId;
43+
status: JobStatus;
44+
title: string;
45+
type: string;
46+
maxSizeReached: boolean;
47+
csvContainsFormulas: boolean;
48+
}
49+
50+
export interface JobStatusBuckets {
51+
completed: JobSummary[];
52+
failed: JobSummary[];
53+
}
54+
55+
type DownloadLink = string;
56+
export type DownloadReportFn = (jobId: JobId) => DownloadLink;
57+
58+
type ManagementLink = string;
59+
export type ManagementLinkFn = () => ManagementLink;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "reportingNotifier",
3+
"version": "kibana",
4+
"requiredPlugins": [],
5+
"server": false,
6+
"ui": true
7+
}

0 commit comments

Comments
 (0)