From 9d4474fa34f35cf2290be8905340e53af81c66b1 Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Wed, 25 Nov 2020 15:11:28 -0800 Subject: [PATCH 1/4] call ES getAll reports/report definition with max_query_size --- .../public/components/main/main.tsx | 3 +- .../backend/opendistro-es-reports-plugin.ts | 30 ++++++++++--------- kibana-reports/server/routes/report.ts | 18 +++++------ .../server/routes/reportDefinition.ts | 16 +++++----- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/kibana-reports/public/components/main/main.tsx b/kibana-reports/public/components/main/main.tsx index aa9685fb..1633808c 100644 --- a/kibana-reports/public/components/main/main.tsx +++ b/kibana-reports/public/components/main/main.tsx @@ -36,6 +36,7 @@ import { permissionsMissingToast, permissionsMissingActions, } from '../utils/utils'; +import { HttpSetup } from '../../../../../src/core/public/http/types'; const reportCountStyles: CSS.Properties = { color: 'gray', @@ -165,7 +166,7 @@ export function Main(props) { const pagination = { initialPageSize: 10, - pageSizeOptions: [8, 10, 13], + pageSizeOptions: [5, 10, 20], }; useEffect(() => { diff --git a/kibana-reports/server/backend/opendistro-es-reports-plugin.ts b/kibana-reports/server/backend/opendistro-es-reports-plugin.ts index 69c684e1..f238a40d 100644 --- a/kibana-reports/server/backend/opendistro-es-reports-plugin.ts +++ b/kibana-reports/server/backend/opendistro-es-reports-plugin.ts @@ -76,13 +76,14 @@ export default function (Client: any, config: any, components: any) { esReports.getReports = clientAction({ url: { fmt: `${ES_REPORTS_API.LIST_REPORT_INSTANCES}`, - //TODO: wrong format error thrown even required = false, need to figure it out the correct setting to make it truly optional - // req: { - // fromIndex: { - // type: 'string', - // required: false, - // }, - // }, + params: { + fromIndex: { + type: 'number', + }, + maxItems: { + type: 'number', + }, + }, }, method: 'GET', }); @@ -128,13 +129,14 @@ export default function (Client: any, config: any, components: any) { esReports.getReportDefinitions = clientAction({ url: { fmt: `${ES_REPORTS_API.LIST_REPORT_DEFINITIONS}`, - //TODO: wrong format error thrown even required = false, need to figure it out the correct setting to make it truly optional - // req: { - // fromIndex: { - // type: 'string', - // required: false, - // }, - // }, + params: { + fromIndex: { + type: 'number', + }, + maxItems: { + type: 'number', + }, + }, }, method: 'GET', }); diff --git a/kibana-reports/server/routes/report.ts b/kibana-reports/server/routes/report.ts index 178d4eb4..39544e30 100644 --- a/kibana-reports/server/routes/report.ts +++ b/kibana-reports/server/routes/report.ts @@ -25,7 +25,7 @@ import { API_PREFIX } from '../../common'; import { createReport } from './lib/createReport'; import { reportSchema } from '../model'; import { errorResponse } from './utils/helpers'; -import { DELIVERY_TYPE } from './utils/constants'; +import { DEFAULT_MAX_SIZE, DELIVERY_TYPE } from './utils/constants'; import { backendToUiReport, backendToUiReportsList, @@ -206,10 +206,8 @@ export default function (router: IRouter) { path: `${API_PREFIX}/reports`, validate: { query: schema.object({ - size: schema.maybe(schema.string()), - sortField: schema.maybe(schema.string()), - sortDirection: schema.maybe(schema.string()), - fromIndex: schema.maybe(schema.string()), + fromIndex: schema.maybe(schema.number()), + maxItems: schema.maybe(schema.number()), }), }, }, @@ -218,11 +216,9 @@ export default function (router: IRouter) { request, response ): Promise> => { - const { fromIndex } = request.query as { - size: string; - sortField: string; - sortDirection: string; - fromIndex: string; + const { fromIndex, maxItems } = request.query as { + fromIndex: number; + maxItems: number; }; try { @@ -230,11 +226,11 @@ export default function (router: IRouter) { const esReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.esReportsClient.asScoped( request ); - const esResp = await esReportsClient.callAsCurrentUser( 'es_reports.getReports', { fromIndex: fromIndex, + maxItems: maxItems || DEFAULT_MAX_SIZE, } ); diff --git a/kibana-reports/server/routes/reportDefinition.ts b/kibana-reports/server/routes/reportDefinition.ts index a78e1038..285f08bf 100644 --- a/kibana-reports/server/routes/reportDefinition.ts +++ b/kibana-reports/server/routes/reportDefinition.ts @@ -29,6 +29,7 @@ import { backendToUiReportDefinitionsList, } from './utils/converters/backendToUi'; import { updateReportDefinition } from './lib/updateReportDefinition'; +import { DEFAULT_MAX_SIZE } from './utils/constants'; export default function (router: IRouter) { // Create report Definition @@ -137,10 +138,8 @@ export default function (router: IRouter) { path: `${API_PREFIX}/reportDefinitions`, validate: { query: schema.object({ - size: schema.maybe(schema.string()), - sortField: schema.maybe(schema.string()), - sortDirection: schema.maybe(schema.string()), - fromIndex: schema.maybe(schema.string()), + fromIndex: schema.maybe(schema.number()), + maxItems: schema.maybe(schema.number()), }), }, }, @@ -149,11 +148,9 @@ export default function (router: IRouter) { request, response ): Promise> => { - const { fromIndex } = request.query as { - size: string; - sortField: string; - sortDirection: string; - fromIndex: string; + const { fromIndex, maxItems } = request.query as { + fromIndex: number; + maxItems: number; }; try { @@ -166,6 +163,7 @@ export default function (router: IRouter) { 'es_reports.getReportDefinitions', { fromIndex: fromIndex, + maxItems: maxItems || DEFAULT_MAX_SIZE, } ); From ec57d3bd41ad743f5f15195361d5ddc42091f466 Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Wed, 25 Nov 2020 15:13:24 -0800 Subject: [PATCH 2/4] remove unused import --- kibana-reports/public/components/main/main.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/kibana-reports/public/components/main/main.tsx b/kibana-reports/public/components/main/main.tsx index 1633808c..0e68f251 100644 --- a/kibana-reports/public/components/main/main.tsx +++ b/kibana-reports/public/components/main/main.tsx @@ -36,7 +36,6 @@ import { permissionsMissingToast, permissionsMissingActions, } from '../utils/utils'; -import { HttpSetup } from '../../../../../src/core/public/http/types'; const reportCountStyles: CSS.Properties = { color: 'gray', From 50e5c62fa53d2dedfa7c8f7274d12095c28930c1 Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Wed, 25 Nov 2020 20:22:05 -0800 Subject: [PATCH 3/4] set enabled field to be true when swithcing from on-demand to scheduled --- .../report_definitions/report_trigger/report_trigger.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx b/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx index 4cefe5fd..7c45d142 100644 --- a/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx +++ b/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx @@ -561,8 +561,10 @@ export function ReportTrigger(props: ReportTriggerProps) { if (!edit) { reportDefinitionRequest.trigger.trigger_params.enabled = true; } + console.log(JSON.stringify(reportDefinitionRequest.trigger)); if (!('enabled' in reportDefinitionRequest.trigger.trigger_params)) { - reportDefinitionRequest.trigger.trigger_params.enabled = false; + console.log('get in to block'); + reportDefinitionRequest.trigger.trigger_params.enabled = true; } } }); From edc64e95ca7a6713ae8f10befbc3d00e606c392b Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Wed, 25 Nov 2020 20:22:43 -0800 Subject: [PATCH 4/4] clean --- .../report_definitions/report_trigger/report_trigger.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx b/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx index 7c45d142..91faf228 100644 --- a/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx +++ b/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx @@ -561,9 +561,7 @@ export function ReportTrigger(props: ReportTriggerProps) { if (!edit) { reportDefinitionRequest.trigger.trigger_params.enabled = true; } - console.log(JSON.stringify(reportDefinitionRequest.trigger)); if (!('enabled' in reportDefinitionRequest.trigger.trigger_params)) { - console.log('get in to block'); reportDefinitionRequest.trigger.trigger_params.enabled = true; } }