From c7d2eb55ff324296f6817a3dfd718c88537f7f17 Mon Sep 17 00:00:00 2001 From: Rachel Shen Date: Thu, 14 Sep 2023 10:13:36 -0600 Subject: [PATCH] [Fix Reporting Serverless] ILM disabling in reporting client (#166005) ## Summary Closes https://github.com/elastic/kibana/issues/165999 This PR adds to the config `disableStatefulSettings`. The error originates in the `x-pack/plugins/reporting/server/lib/deprecations/check_ilm_migration_status.ts` that is then called by the reporting api client ``` jsx ... this.disableStatefulSettings ? null : this.http.put(INTERNAL_ROUTES.MIGRATE.MIGRATE_ILM_POLICY); ``` I thought an appropriate fix would be adding this setting to the config vs a topical fix in the check_ilm_migration_status to include any other stateful settings that are not permitted in the serverless offering. The store is also inhibiting the csv generation from working. Testing csv downloads works now in Discover. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --- .../__test__/report_listing.test.helpers.tsx | 1 + .../public/management/report_listing.tsx | 2 +- x-pack/plugins/reporting/public/plugin.ts | 1 + .../config/__snapshots__/schema.test.ts.snap | 6 ++++ .../server/config/create_config.test.ts | 6 ++++ .../plugins/reporting/server/config/index.ts | 2 +- .../reporting/server/config/schema.test.ts | 8 +++++ .../plugins/reporting/server/config/schema.ts | 8 +++++ .../reporting/server/lib/store/store.test.ts | 2 ++ .../reporting/server/lib/store/store.ts | 30 +++++++++++-------- .../create_mock_reportingplugin.ts | 1 + 11 files changed, 53 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/reporting/public/management/__test__/report_listing.test.helpers.tsx b/x-pack/plugins/reporting/public/management/__test__/report_listing.test.helpers.tsx index fc1b0f25d9c01..2d24736d7e13b 100644 --- a/x-pack/plugins/reporting/public/management/__test__/report_listing.test.helpers.tsx +++ b/x-pack/plugins/reporting/public/management/__test__/report_listing.test.helpers.tsx @@ -70,6 +70,7 @@ export const mockConfig = { roles: { enabled: false, }, + statefulSettings: { enabled: true }, }; const validCheck = { diff --git a/x-pack/plugins/reporting/public/management/report_listing.tsx b/x-pack/plugins/reporting/public/management/report_listing.tsx index 74753437f54ce..49607c6f38710 100644 --- a/x-pack/plugins/reporting/public/management/report_listing.tsx +++ b/x-pack/plugins/reporting/public/management/report_listing.tsx @@ -109,7 +109,7 @@ class ReportListingUi extends Component { } /> - + {config.statefulSettings.enabled ? : null}
{this.renderTable()}
diff --git a/x-pack/plugins/reporting/public/plugin.ts b/x-pack/plugins/reporting/public/plugin.ts index 912f519d60002..46e425b54239d 100644 --- a/x-pack/plugins/reporting/public/plugin.ts +++ b/x-pack/plugins/reporting/public/plugin.ts @@ -47,6 +47,7 @@ export interface ClientConfigType { poll: { jobsRefresh: { interval: number; intervalErrorMultiplier: number } }; roles: { enabled: boolean }; export_types: { pdf: { enabled: boolean }; png: { enabled: boolean }; csv: { enabled: boolean } }; + statefulSettings: { enabled: boolean }; } function getStored(): JobId[] { diff --git a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap b/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap index 48f834d238795..1c9a695f4a78e 100644 --- a/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap +++ b/x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap @@ -55,6 +55,9 @@ Object { ], "enabled": true, }, + "statefulSettings": Object { + "enabled": true, + }, } `; @@ -112,5 +115,8 @@ Object { ], "enabled": true, }, + "statefulSettings": Object { + "enabled": true, + }, } `; diff --git a/x-pack/plugins/reporting/server/config/create_config.test.ts b/x-pack/plugins/reporting/server/config/create_config.test.ts index 0a10b859bb18f..dbb16d050297f 100644 --- a/x-pack/plugins/reporting/server/config/create_config.test.ts +++ b/x-pack/plugins/reporting/server/config/create_config.test.ts @@ -51,6 +51,9 @@ describe('Reporting server createConfig', () => { port: 5677, protocol: 'httpsa', }, + statefulSettings: { + enabled: true, + }, }); const result = createConfig(mockCoreSetup, mockConfig, mockLogger); @@ -92,6 +95,9 @@ describe('Reporting server createConfig', () => { "roles": Object { "enabled": false, }, + "statefulSettings": Object { + "enabled": true, + }, } `); expect(mockLogger.warn).not.toHaveBeenCalled(); diff --git a/x-pack/plugins/reporting/server/config/index.ts b/x-pack/plugins/reporting/server/config/index.ts index 5786498035721..3bb4b79dd6fc8 100644 --- a/x-pack/plugins/reporting/server/config/index.ts +++ b/x-pack/plugins/reporting/server/config/index.ts @@ -11,7 +11,7 @@ import { get } from 'lodash'; import { ConfigSchema, ReportingConfigType } from './schema'; export const config: PluginConfigDescriptor = { - exposeToBrowser: { poll: true, roles: true, export_types: true }, + exposeToBrowser: { poll: true, roles: true, export_types: true, statefulSettings: true }, schema: ConfigSchema, deprecations: ({ unused }) => [ unused('capture.browser.chromium.maxScreenshotDimension', { level: 'warning' }), // unused since 7.8 diff --git a/x-pack/plugins/reporting/server/config/schema.test.ts b/x-pack/plugins/reporting/server/config/schema.test.ts index 14ed1886e9136..f30be71db09ea 100644 --- a/x-pack/plugins/reporting/server/config/schema.test.ts +++ b/x-pack/plugins/reporting/server/config/schema.test.ts @@ -85,6 +85,14 @@ describe('Reporting Config Schema', () => { `); }); + it('disables ilm settings in serverless', () => { + expect(ConfigSchema.validate({}, { serverless: true }).statefulSettings).toMatchInlineSnapshot(` + Object { + "enabled": false, + } + `); + }); + it('disables screenshot type exports in serverless', () => { expect(ConfigSchema.validate({}, { serverless: true }).export_types).toMatchInlineSnapshot(` Object { diff --git a/x-pack/plugins/reporting/server/config/schema.ts b/x-pack/plugins/reporting/server/config/schema.ts index 966f4f20ff313..ff0cda89a693b 100644 --- a/x-pack/plugins/reporting/server/config/schema.ts +++ b/x-pack/plugins/reporting/server/config/schema.ts @@ -128,6 +128,13 @@ const ExportTypeSchema = schema.object({ }), }); +const SettingsSchema = schema.object({ + enabled: offeringBasedSchema({ + serverless: schema.boolean({ defaultValue: false }), + traditional: schema.boolean({ defaultValue: true }), + }), +}); + export const ConfigSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), kibanaServer: KibanaServerSchema, @@ -138,6 +145,7 @@ export const ConfigSchema = schema.object({ roles: RolesSchema, poll: PollSchema, export_types: ExportTypeSchema, + statefulSettings: SettingsSchema, }); export type ReportingConfigType = TypeOf; diff --git a/x-pack/plugins/reporting/server/lib/store/store.test.ts b/x-pack/plugins/reporting/server/lib/store/store.test.ts index f1400ab357ee9..64556ef1a2c22 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.test.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.test.ts @@ -19,6 +19,7 @@ describe('ReportingStore', () => { const reportingConfig = { index: '.reporting-test', queue: { indexInterval: 'week' }, + statefulSettings: { enabled: true }, }; mockCore = await createMockReportingCore(createMockConfigSchema(reportingConfig)); mockEsClient = (await mockCore.getEsClient()).asInternalUser as typeof mockEsClient; @@ -60,6 +61,7 @@ describe('ReportingStore', () => { const reportingConfig = { index: '.reporting-test', queue: { indexInterval: 'centurially' }, + statefulSettings: { enabled: true }, }; mockCore = await createMockReportingCore(createMockConfigSchema(reportingConfig)); diff --git a/x-pack/plugins/reporting/server/lib/store/store.ts b/x-pack/plugins/reporting/server/lib/store/store.ts index 96a3ffacee51c..1a0dcbf16a893 100644 --- a/x-pack/plugins/reporting/server/lib/store/store.ts +++ b/x-pack/plugins/reporting/server/lib/store/store.ts @@ -87,12 +87,13 @@ export class ReportingStore { private readonly indexInterval: string; // config setting of index prefix: how often to poll for pending work private client?: ElasticsearchClient; private ilmPolicyManager?: IlmPolicyManager; + config: ReportingCore['config']; constructor(private reportingCore: ReportingCore, private logger: Logger) { - const config = reportingCore.getConfig(); + this.config = reportingCore.getConfig(); this.indexPrefix = REPORTING_SYSTEM_INDEX; - this.indexInterval = config.queue.indexInterval; + this.indexInterval = this.config.queue.indexInterval; this.logger = logger.get('store'); } @@ -105,12 +106,8 @@ export class ReportingStore { } private async getIlmPolicyManager() { - if (!this.ilmPolicyManager) { - const client = await this.getClient(); - this.ilmPolicyManager = IlmPolicyManager.create({ client }); - } - - return this.ilmPolicyManager; + const client = await this.getClient(); + return (this.ilmPolicyManager = IlmPolicyManager.create({ client })); } private async createIndex(indexName: string) { @@ -121,10 +118,8 @@ export class ReportingStore { return exists; } - try { - await client.indices.create({ - index: indexName, - body: { + const indexSettings = this.config.statefulSettings.enabled + ? { settings: { number_of_shards: 1, auto_expand_replicas: '0-1', @@ -132,6 +127,14 @@ export class ReportingStore { name: ILM_POLICY_NAME, }, }, + } + : {}; + + try { + await client.indices.create({ + index: indexName, + body: { + ...indexSettings, mappings: { properties: mapping, }, @@ -185,6 +188,9 @@ export class ReportingStore { * configured for storage of reports. */ public async start() { + if (!this.config.statefulSettings.enabled) { + return; + } const ilmPolicyManager = await this.getIlmPolicyManager(); try { if (await ilmPolicyManager.doesIlmPolicyExist()) { diff --git a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts index 38a7bb8399abb..d96a66bc9b9fd 100644 --- a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts +++ b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts @@ -117,6 +117,7 @@ export const createMockConfigSchema = ( csv: { enabled: true }, ...overrides.export_types, }, + statefulSettings: { enabled: true }, } as ReportingConfigType; };