From 615f2e29f806977980233ea15e28376dee2d694d Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Fri, 11 Feb 2022 11:54:15 +0100 Subject: [PATCH 1/2] update configs --- x-pack/plugins/uptime/e2e/config.ts | 18 ++++++++++++--- .../uptime/e2e/tasks/read_kibana_config.ts | 22 +++++++++++++++++++ x-pack/test/api_integration/config.ts | 1 - 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 x-pack/plugins/uptime/e2e/tasks/read_kibana_config.ts diff --git a/x-pack/plugins/uptime/e2e/config.ts b/x-pack/plugins/uptime/e2e/config.ts index 4d509d4045be9..48b4e048000f2 100644 --- a/x-pack/plugins/uptime/e2e/config.ts +++ b/x-pack/plugins/uptime/e2e/config.ts @@ -8,6 +8,12 @@ import { FtrConfigProviderContext } from '@kbn/test'; import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { readKibanaConfig } from './tasks/read_kibana_config'; + +const MANIFEST_KEY = 'xpack.uptime.service.manifestUrl'; +const SERVICE_PASSWORD = 'xpack.uptime.service.password'; +const SERVICE_USERNAME = 'xpack.uptime.service.username'; + async function config({ readConfigFile }: FtrConfigProviderContext) { const kibanaCommonTestsConfig = await readConfigFile( require.resolve('../../../../test/common/config.js') @@ -16,6 +22,12 @@ async function config({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../../test/functional/config.js') ); + const kibanaConfig = readKibanaConfig(); + + const manifestUrl = process.env.SYNTHETICS_SERVICE_MANIFEST ?? kibanaConfig[MANIFEST_KEY]; + const serviceUsername = process.env.SYNTHETICS_SERVICE_USERNAME ?? kibanaConfig[SERVICE_USERNAME]; + const servicPassword = process.env.SYNTHETICS_SERVICE_PASSWORD ?? kibanaConfig[SERVICE_PASSWORD]; + return { ...kibanaCommonTestsConfig.getAll(), @@ -44,9 +56,9 @@ async function config({ readConfigFile }: FtrConfigProviderContext) { `--elasticsearch.username=kibana_system`, `--elasticsearch.password=changeme`, '--xpack.reporting.enabled=false', - `--xpack.uptime.service.manifestUrl=${process.env.SYNTHETICS_SERVICE_MANIFEST}`, - `--xpack.uptime.service.username=${process.env.SYNTHETICS_SERVICE_USERNAME}`, - `--xpack.uptime.service.password=${process.env.SYNTHETICS_SERVICE_PASSWORD}`, + `--xpack.uptime.service.manifestUrl=${manifestUrl}`, + `--xpack.uptime.service.username=${serviceUsername}`, + `--xpack.uptime.service.password=${servicPassword}`, '--xpack.uptime.ui.monitorManagement.enabled=true', ], }, diff --git a/x-pack/plugins/uptime/e2e/tasks/read_kibana_config.ts b/x-pack/plugins/uptime/e2e/tasks/read_kibana_config.ts new file mode 100644 index 0000000000000..3867386e41104 --- /dev/null +++ b/x-pack/plugins/uptime/e2e/tasks/read_kibana_config.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import path from 'path'; +import fs from 'fs'; +import yaml from 'js-yaml'; + +export type KibanaConfig = ReturnType; + +export const readKibanaConfig = () => { + const kibanaConfigDir = path.join(__filename, '../../../../../../config'); + const kibanaDevConfig = path.join(kibanaConfigDir, 'kibana.dev.yml'); + const kibanaConfig = path.join(kibanaConfigDir, 'kibana.yml'); + + return (yaml.safeLoad( + fs.readFileSync(fs.existsSync(kibanaDevConfig) ? kibanaDevConfig : kibanaConfig, 'utf8') + ) || {}) as Record; +}; diff --git a/x-pack/test/api_integration/config.ts b/x-pack/test/api_integration/config.ts index aa2a61f8b0092..af355695f3ed8 100644 --- a/x-pack/test/api_integration/config.ts +++ b/x-pack/test/api_integration/config.ts @@ -37,7 +37,6 @@ export async function getApiIntegrationConfig({ readConfigFile }: FtrConfigProvi '--xpack.ruleRegistry.write.cache.enabled=false', '--xpack.uptime.ui.monitorManagement.enabled=true', '--xpack.uptime.service.password=test', - '--xpack.uptime.service.manifestUrl=http://test.com', '--xpack.uptime.service.username=localKibanaIntegrationTestsUser', `--xpack.securitySolution.enableExperimental=${JSON.stringify(['ruleRegistryEnabled'])}`, ], From 93870fb9aa0a061d78e99bc21d73e6c334c930f1 Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Fri, 11 Feb 2022 12:01:39 +0100 Subject: [PATCH 2/2] update --- .../server/lib/synthetics_service/get_service_locations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts index a58c4dd421cbe..ffec06259f4e7 100644 --- a/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts +++ b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts @@ -16,7 +16,7 @@ import { UptimeServerSetup } from '../adapters/framework'; export async function getServiceLocations(server: UptimeServerSetup) { const locations: ServiceLocations = []; - if (!server.config.service!.manifestUrl!) { + if (!server.config.service?.manifestUrl) { return { locations }; }