Skip to content

Commit

Permalink
Merge branch 'main' into eui-v87.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Aug 21, 2023
2 parents d3b45ad + c1d2834 commit 33663cd
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2475,15 +2475,15 @@ Any modifications made to this file will be overwritten.
<div class='model-description'></div>
<div class="field-items">
<div class="param">name </div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> The display name for the connector. </div>
<div class="param">secrets </div><div class="param-desc"><span class="param-type"><a href="#">secrets_properties_slack_api</a></span> </div>
<div class="param">secrets </div><div class="param-desc"><span class="param-type"><a href="#secrets_properties_slack_api">secrets_properties_slack_api</a></span> </div>
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="update_connector_request_slack_webhook"><code>update_connector_request_slack_webhook</code> - Update Slack connector request</a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">name </div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> The display name for the connector. </div>
<div class="param">secrets </div><div class="param-desc"><span class="param-type"><a href="#">secrets_properties_slack_webhook</a></span> </div>
<div class="param">secrets </div><div class="param-desc"><span class="param-type"><a href="#secrets_properties_slack_webhook">secrets_properties_slack_webhook</a></span> </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/actions/docs/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -3720,8 +3720,6 @@
"description": "The display name for the connector."
},
"secrets": {
"type": "object",
"description": "The secrets object containing the necessary fields for authentication.",
"$ref": "#/components/schemas/secrets_properties_slack_api"
}
}
Expand All @@ -3739,8 +3737,6 @@
"description": "The display name for the connector."
},
"secrets": {
"type": "object",
"description": "The secrets object containing the necessary fields for authentication.",
"$ref": "#/components/schemas/secrets_properties_slack_webhook"
}
}
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/actions/docs/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2549,8 +2549,6 @@ components:
type: string
description: The display name for the connector.
secrets:
type: object
description: The secrets object containing the necessary fields for authentication.
$ref: '#/components/schemas/secrets_properties_slack_api'
update_connector_request_slack_webhook:
title: Update Slack connector request
Expand All @@ -2563,8 +2561,6 @@ components:
type: string
description: The display name for the connector.
secrets:
type: object
description: The secrets object containing the necessary fields for authentication.
$ref: '#/components/schemas/secrets_properties_slack_webhook'
update_connector_request_swimlane:
title: Update Swimlane connector request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ properties:
type: string
description: The display name for the connector.
secrets:
type: object
description: The secrets object containing the necessary fields for authentication.
$ref: 'secrets_properties_slack_api.yaml'
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ properties:
type: string
description: The display name for the connector.
secrets:
type: object
description: The secrets object containing the necessary fields for authentication.
$ref: 'secrets_properties_slack_webhook.yaml'
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/common/constants/report_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Export Type Definitions
export const CSV_REPORT_TYPE = 'CSV';
export const CSV_REPORT_TYPE = 'csv_searchsource';
export const CSV_REPORT_TYPE_V2 = 'csv_v2';

export const PDF_REPORT_TYPE = 'printablePdf';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ class ReportingPanelContentUi extends Component<Props, State> {
case PDF_REPORT_TYPE:
case PDF_REPORT_TYPE_V2:
return 'PDF';
case 'csv_searchsource':
return CSV_REPORT_TYPE;
case CSV_REPORT_TYPE:
return 'csv';
case 'png':
case PNG_REPORT_TYPE_V2:
return PNG_REPORT_TYPE;
Expand Down
21 changes: 13 additions & 8 deletions x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,27 @@ export class ReportingCore {
* only CSV export types should be registered in the export types registry for serverless
*/
private getExportTypes(): ExportType[] {
const { csv, pdf, png } = this.config.export_types;
const exportTypes = [];
if (!this.config.export_types.pdf.enabled || !this.config.export_types.png.enabled) {
exportTypes.push(
new CsvSearchSourceExportType(this.core, this.config, this.logger, this.context)
);
exportTypes.push(new CsvV2ExportType(this.core, this.config, this.logger, this.context));
} else {

if (csv.enabled) {
// NOTE: CsvSearchSourceExportType should be deprecated and replaced with V2 in the UI: https://github.com/elastic/kibana/issues/151190
exportTypes.push(
new CsvSearchSourceExportType(this.core, this.config, this.logger, this.context)
);
exportTypes.push(new CsvV2ExportType(this.core, this.config, this.logger, this.context));
}

if (pdf.enabled) {
// NOTE: PdfV1ExportType is deprecated and tagged for removal: https://github.com/elastic/kibana/issues/154601
exportTypes.push(new PdfV1ExportType(this.core, this.config, this.logger, this.context));
exportTypes.push(new PdfExportType(this.core, this.config, this.logger, this.context));
}

if (png.enabled) {
exportTypes.push(new PngExportType(this.core, this.config, this.logger, this.context));
// deprecated export types for tests
exportTypes.push(new PdfV1ExportType(this.core, this.config, this.logger, this.context));
}

return exportTypes;
}

Expand Down
97 changes: 59 additions & 38 deletions x-pack/plugins/reporting/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

import type { CoreSetup, CoreStart, Logger } from '@kbn/core/server';
import { coreMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { PDF_REPORT_TYPE_V2, PNG_REPORT_TYPE_V2 } from '../common/constants/report_types';
import {
CSV_REPORT_TYPE,
CSV_REPORT_TYPE_V2,
PDF_REPORT_TYPE,
PDF_REPORT_TYPE_V2,
PNG_REPORT_TYPE_V2,
} from '../common/constants';
import type { ReportingCore, ReportingInternalStart } from './core';
import { ExportTypesRegistry } from './lib/export_types_registry';
import { ReportingPlugin } from './plugin';
import {
createMockConfigSchema,
Expand All @@ -30,6 +37,8 @@ describe('Reporting Plugin', () => {
let plugin: ReportingPlugin;

beforeEach(async () => {
jest.clearAllMocks();

configSchema = createMockConfigSchema();
initContext = coreMock.createPluginInitializerContext(configSchema);
coreSetup = coreMock.createSetup(configSchema);
Expand Down Expand Up @@ -81,50 +90,62 @@ describe('Reporting Plugin', () => {
`);
expect(logger.error).toHaveBeenCalledTimes(2);
});
describe('config and export types registry validation', () => {
it('expect image reporting to be in registry by default', async () => {
// wait for the setup phase background work
plugin.setup(coreSetup, pluginSetup);
await new Promise(setImmediate);

// create a way for an error to happen
const reportingCore = (plugin as unknown as { reportingCore: ReportingCore }).reportingCore;

// wait for the startup phase background work
plugin.start(coreStart, pluginStart);
await new Promise(setImmediate);
expect(reportingCore.getExportTypesRegistry().getById(PDF_REPORT_TYPE_V2)).toHaveProperty(
'id',
PDF_REPORT_TYPE_V2
);
expect(reportingCore.getExportTypesRegistry().getById(PNG_REPORT_TYPE_V2)).toHaveProperty(
'id',
PNG_REPORT_TYPE_V2
);

describe('config and export types registration', () => {
jest.mock('./lib/export_types_registry');
ExportTypesRegistry.prototype.getAll = jest.fn(() => []); // code breaks if getAll returns undefined
let registerSpy: jest.SpyInstance;

beforeEach(async () => {
registerSpy = jest.spyOn(ExportTypesRegistry.prototype, 'register');
pluginSetup = createMockPluginSetup({}) as unknown as ReportingSetupDeps;
pluginStart = await createMockPluginStart(coreStart, configSchema);
plugin = new ReportingPlugin(initContext);
});

it('expect all report types to be in registry', async () => {
// check the spy function
expect(registerSpy).toHaveBeenCalledTimes(5);
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE }));
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE_V2 }));
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PDF_REPORT_TYPE }));
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PDF_REPORT_TYPE_V2 }));
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PNG_REPORT_TYPE_V2 }));
});
it('expect pdf to not be in registry if config does not enable it', async () => {
configSchema = { ...createMockConfigSchema(), export_types: { pdf: { enabled: false } } };

it('expect image report types not to be in registry if disabled', async () => {
jest.clearAllMocks();

configSchema = createMockConfigSchema({
export_types: {
csv: { enabled: true },
pdf: { enabled: false },
png: { enabled: false },
},
});

initContext = coreMock.createPluginInitializerContext(configSchema);
coreSetup = coreMock.createSetup(configSchema);
coreStart = coreMock.createStart();
pluginSetup = createMockPluginSetup({}) as unknown as ReportingSetupDeps;
pluginStart = await createMockPluginStart(coreStart, configSchema);

plugin = new ReportingPlugin(initContext);
// wait for the setup phase background work
plugin.setup(coreSetup, pluginSetup);
await new Promise(setImmediate);

// create a way for an error to happen
const reportingCore = (plugin as unknown as { reportingCore: ReportingCore }).reportingCore;

// wait for the startup phase background work
plugin.start(coreStart, pluginStart);
await new Promise(setImmediate);
const checkPdf = () => reportingCore.getExportTypesRegistry().getById(PDF_REPORT_TYPE_V2);
const checkPng = () => reportingCore.getExportTypesRegistry().getById(PNG_REPORT_TYPE_V2);
expect(checkPdf).toThrowError(`Unknown id ${PDF_REPORT_TYPE_V2}`);
expect(checkPng).toThrowError(`Unknown id ${PNG_REPORT_TYPE_V2}`);

// check the spy function was called with CSV
expect(registerSpy).toHaveBeenCalledTimes(2);
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE }));
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE_V2 }));

// check the spy function was NOT called with anything else
expect(registerSpy).not.toHaveBeenCalledWith(
expect.objectContaining({ id: PDF_REPORT_TYPE })
);
expect(registerSpy).not.toHaveBeenCalledWith(
expect.objectContaining({ id: PDF_REPORT_TYPE_V2 })
);
expect(registerSpy).not.toHaveBeenCalledWith(
expect.objectContaining({ id: PNG_REPORT_TYPE_V2 })
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const createMockConfigSchema = (
pdf: { enabled: true },
png: { enabled: true },
csv: { enabled: true },
...overrides.export_types,
},
} as ReportingConfigType;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default ({ getService }: FtrProviderContext) => {
const log = getService('log');
const retry = getService('retry');

describe('Detection rule task telemetry', async () => {
// Failing: See https://github.com/elastic/kibana/issues/164318
describe.skip('Detection rule task telemetry', async () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/security_solution/telemetry');
});
Expand Down

0 comments on commit 33663cd

Please sign in to comment.