actually pass the cloud plugin to Screenshots 🤦

This commit is contained in:
Jean-Louis Leysens 2022-04-20 19:11:14 +02:00
parent d21e8080e1
commit 0dc497bd72
No known key found for this signature in database
GPG key ID: 28B3B4DFF3677CDC
2 changed files with 16 additions and 7 deletions

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import type { CloudSetup } from '@kbn/cloud-plugin/server';
import type { Logger } from '@kbn/core/server';
import type { CloudSetup } from '@kbn/cloud-plugin/server';
import { readMemoryLimit } from './read_cgroup_mem_limit';
const MIN_CLOUD_OS_MEM_GB: number = 2;
@ -21,12 +21,12 @@ export function systemHasInsufficientMemory(
cloud: undefined | CloudSetup,
logger: Logger
): boolean {
logger.fatal(`isCloudEnabled ${Boolean(cloud?.isCloudEnabled)}`);
logger.fatal(`hasDeploymentId ${Boolean(cloud?.deploymentId)}`);
logger.fatal(`has cloud ${Boolean(cloud?.isCloudEnabled || cloud?.deploymentId)}`);
logger.fatal(`TEST isCloudEnabled ${Boolean(cloud?.isCloudEnabled)}`);
logger.fatal(`TEST hasDeploymentId ${Boolean(cloud?.deploymentId)}`);
logger.fatal(`TEST has cloud ${Boolean(cloud?.isCloudEnabled || cloud?.deploymentId)}`);
if (!Boolean(cloud?.isCloudEnabled || cloud?.deploymentId)) return false;
const limit = readMemoryLimit();
logger.fatal(`memory limit from cgroups ${limit}`);
logger.fatal(`TEST memory limit from cgroups ${limit}`);
logger.info(`Memory limit from cgroup (in bytes): ${limit}`);
return limit < MIN_CLOUD_OS_MEM_BYTES;
}

View file

@ -16,6 +16,7 @@ import type {
PluginInitializerContext,
} from '@kbn/core/server';
import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server';
import type { CloudSetup } from '@kbn/cloud-plugin/server';
import { ChromiumArchivePaths, HeadlessChromiumDriverFactory, install } from './browsers';
import { ConfigType, createConfig } from './config';
import { Screenshots } from './screenshots';
@ -23,6 +24,7 @@ import { getChromiumPackage } from './utils';
interface SetupDeps {
screenshotMode: ScreenshotModePluginSetup;
cloud?: CloudSetup;
}
/**
@ -57,7 +59,7 @@ export class ScreenshottingPlugin implements Plugin<void, ScreenshottingStart, S
this.packageInfo = context.env.packageInfo;
}
setup({ http }: CoreSetup, { screenshotMode }: SetupDeps) {
setup({ http }: CoreSetup, { screenshotMode, cloud }: SetupDeps) {
this.screenshotMode = screenshotMode;
this.browserDriverFactory = (async () => {
const paths = new ChromiumArchivePaths();
@ -85,7 +87,14 @@ export class ScreenshottingPlugin implements Plugin<void, ScreenshottingStart, S
const browserDriverFactory = await this.browserDriverFactory;
const logger = this.logger.get('screenshot');
return new Screenshots(browserDriverFactory, logger, this.packageInfo, http, this.config);
return new Screenshots(
browserDriverFactory,
logger,
this.packageInfo,
http,
this.config,
cloud
);
})();
// Already handled in `browserDriverFactory`
this.screenshots.catch(() => {});