[Reporting][Serverless] Make screenshotting in reporting plugin optional and disable in serverless (#168373)

## Summary

Closes [#168379](https://github.com/elastic/kibana/issues/168379)

### After
In logs for yarn serverless-es
```[2023-10-09T15:09:02.887-06:00][INFO ][plugins-service] Plugin "screenshotting" is disabled.```

### 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
This commit is contained in:
Rachel Shen 2023-10-12 13:32:32 -06:00 committed by GitHub
parent bc8f45f529
commit f5caf787af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 24 additions and 13 deletions

View file

@ -52,6 +52,7 @@ xpack.canvas.enabled: false
xpack.cloud_integrations.data_migration.enabled: false
data.search.sessions.enabled: false
advanced_settings.enabled: false
xpack.screenshotting.enabled: false
# Disable the browser-side functionality that depends on SecurityCheckupGetStateRoutes
xpack.security.showInsecureClusterWarning: false

View file

@ -22,7 +22,6 @@
"uiActions",
"taskManager",
"embeddable",
"screenshotting",
"screenshotMode",
"share",
"features"
@ -30,7 +29,8 @@
"optionalPlugins": [
"security",
"spaces",
"usageCollection"
"usageCollection",
"screenshotting",
],
"requiredBundles": [
"kibanaReact",

View file

@ -78,7 +78,7 @@ export interface ReportingInternalStart {
fieldFormats: FieldFormatsStart;
licensing: LicensingPluginStart;
logger: Logger;
screenshotting: ScreenshottingStart;
screenshotting?: ScreenshottingStart;
security?: SecurityPluginStart;
taskManager: TaskManagerStartContract;
}
@ -134,7 +134,7 @@ export class ReportingCore {
this.getContract = () => ({
usesUiCapabilities: () => config.roles.enabled === false,
registerExportTypes: (id) => id,
getScreenshots: this.getScreenshots.bind(this),
getScreenshots: config.statefulSettings.enabled ? this.getScreenshots.bind(this) : undefined,
getSpaceId: this.getSpaceId.bind(this),
});
@ -408,7 +408,7 @@ export class ReportingCore {
): Rx.Observable<PngScreenshotResult | PdfScreenshotResult> {
return Rx.defer(() => this.getPluginStartDeps()).pipe(
switchMap(({ screenshotting }) => {
return screenshotting.getScreenshots({
return screenshotting!.getScreenshots({
...options,
urls: options.urls.map((url) =>
typeof url === 'string'

View file

@ -37,7 +37,7 @@ export interface BaseExportTypeStartDeps {
savedObjects: SavedObjectsServiceStart;
uiSettings: UiSettingsServiceStart;
esClient: IClusterClient;
screenshotting: ScreenshottingStart;
screenshotting?: ScreenshottingStart;
reporting: ReportingStart;
}

View file

@ -104,7 +104,7 @@ export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2>
return generatePngObservable(
() =>
this.startDeps.reporting.getScreenshots({
this.startDeps.reporting.getScreenshots!({
format: 'png',
headers,
layout: { ...payload.layout, id: 'preserve_layout' },

View file

@ -85,7 +85,7 @@ export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayl
apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute');
// make a new function that will call reporting.getScreenshots
const snapshotFn = () =>
this.startDeps.reporting.getScreenshots({
this.startDeps.reporting.getScreenshots!({
format: 'pdf',
title,
logo,

View file

@ -108,7 +108,7 @@ export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2>
this.config,
this.getServerInfo(),
() =>
this.startDeps.reporting.getScreenshots({
this.startDeps.reporting.getScreenshots!({
format: 'pdf',
title,
logo,

View file

@ -54,6 +54,7 @@ export const registerDiagnoseBrowser = (reporting: ReportingCore, logger: Logger
const logsToHelpMap = logsToHelpMapFactory(docLinks);
try {
const { screenshotting } = await reporting.getPluginStartDeps();
if (!screenshotting) throw new Error('Screenshotting is not enabled!');
const logs = await lastValueFrom(screenshotting.diagnose());
const knownIssues = Object.keys(logsToHelpMap) as Array<keyof typeof logsToHelpMap>;

View file

@ -41,7 +41,7 @@ import { ExportTypesRegistry } from './lib';
export interface ReportingSetup {
registerExportTypes: ExportTypesRegistry['register'];
getSpaceId: ReportingCore['getSpaceId'];
getScreenshots: ReportingCore['getScreenshots'];
getScreenshots?: ReportingCore['getScreenshots'];
/**
* Used to inform plugins if Reporting config is compatible with UI Capabilities / Application Sub-Feature Controls
*/
@ -93,7 +93,7 @@ export type RunTaskFn<TaskPayloadType = BasePayload> = (
export interface ReportingSetupDeps {
features: FeaturesPluginSetup;
screenshotMode: ScreenshotModePluginSetup;
screenshotMode?: ScreenshotModePluginSetup;
security?: SecurityPluginSetup;
spaces?: SpacesPluginSetup;
taskManager: TaskManagerSetupContract;
@ -105,7 +105,7 @@ export interface ReportingStartDeps {
discover: DiscoverServerPluginStart;
fieldFormats: FieldFormatsStart;
licensing: LicensingPluginStart;
screenshotting: ScreenshottingStart;
screenshotting?: ScreenshottingStart;
security?: SecurityPluginStart;
taskManager: TaskManagerStartContract;
}

View file

@ -26,6 +26,7 @@ describe('chromium driver', () => {
mockLogger.get = () => mockLogger;
mockConfig = {
enabled: true,
networkPolicy: {
enabled: false,
rules: [],

View file

@ -27,6 +27,7 @@ describe('ConfigSchema', () => {
},
"zoom": 2,
},
"enabled": true,
"networkPolicy": Object {
"enabled": true,
"rules": Array [
@ -87,6 +88,7 @@ describe('ConfigSchema', () => {
},
"zoom": 2,
},
"enabled": true,
"networkPolicy": Object {
"enabled": true,
"rules": Array [

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { schema, TypeOf } from '@kbn/config-schema';
import { schema, TypeOf, offeringBasedSchema } from '@kbn/config-schema';
import moment from 'moment';
const RulesSchema = schema.object({
@ -23,6 +23,10 @@ const RulesSchema = schema.object({
});
export const ConfigSchema = schema.object({
enabled: offeringBasedSchema({
serverless: schema.boolean({ defaultValue: false }),
traditional: schema.boolean({ defaultValue: true }),
}),
networkPolicy: schema.object({
enabled: schema.boolean({ defaultValue: true }),
rules: schema.arrayOf(RulesSchema, {

View file

@ -68,6 +68,7 @@ describe('Screenshot Observable Pipeline', () => {
urls: ['/welcome/home/start/index.htm'],
};
config = {
enabled: true,
poolSize: 1,
capture: {
timeouts: {

View file

@ -37,6 +37,7 @@ describe('class Screenshots', () => {
mockLogger = loggerMock.create();
mockConfig = {
enabled: true,
networkPolicy: {
enabled: false,
rules: [],