[Synthetics] Auto enable monitor management where possible (#155231)

This commit is contained in:
Shahzad 2023-04-20 15:17:43 +02:00 committed by GitHub
parent c13a3ab603
commit c936210ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 90 additions and 59 deletions

View file

@ -7,20 +7,6 @@
import { i18n } from '@kbn/i18n';
export const SYNTHETICS_ENABLE_FAILURE = i18n.translate(
'xpack.synthetics.monitorManagement.syntheticsEnabledFailure',
{
defaultMessage: 'Monitor Management was not able to be enabled. Please contact support.',
}
);
export const SYNTHETICS_DISABLE_FAILURE = i18n.translate(
'xpack.synthetics.monitorManagement.syntheticsDisabledFailure',
{
defaultMessage: 'Monitor Management was not able to be disabled. Please contact support.',
}
);
export const SYNTHETICS_ENABLE_SUCCESS = i18n.translate(
'xpack.synthetics.monitorManagement.syntheticsEnableSuccess',
{
@ -42,10 +28,10 @@ export const MONITOR_MANAGEMENT_ENABLEMENT_LABEL = i18n.translate(
}
);
export const MONITOR_MANAGEMENT_DISABLED_LABEL = i18n.translate(
'xpack.synthetics.monitorManagement.emptyState.enablement.disabled.title',
export const SYNTHETICS_APP_DISABLED_LABEL = i18n.translate(
'xpack.synthetics.emptyState.enablement.disabled.title',
{
defaultMessage: 'Monitor Management is disabled',
defaultMessage: 'Synthetics App is disabled',
}
);
@ -58,10 +44,10 @@ export const MONITOR_MANAGEMENT_ENABLEMENT_MESSAGE = i18n.translate(
);
export const MONITOR_MANAGEMENT_DISABLED_MESSAGE = i18n.translate(
'xpack.synthetics.monitorManagement.emptyState.enablement.disabledDescription',
'xpack.synthetics.emptyState.enablement.disabledDescription',
{
defaultMessage:
'Monitor Management is currently disabled. Monitor Management allows you to run lightweight and real-browser monitors from hosted testing locations around the world. To enable Monitor Management, please contact an administrator.',
'Synthetics App is currently disabled. Synthetics App allows you to run lightweight and real-browser monitors from hosted testing locations around the world. To enable Synthetics App, please contact an administrator.',
}
);

View file

@ -61,7 +61,7 @@ export const EnablementEmptyState = () => {
<h2>
{canEnable
? labels.MONITOR_MANAGEMENT_ENABLEMENT_LABEL
: labels.MONITOR_MANAGEMENT_DISABLED_LABEL}
: labels.SYNTHETICS_APP_DISABLED_LABEL}
</h2>
}
body={

View file

@ -19,12 +19,24 @@ export const getSyntheticsEnablementRoute: UMRestApiRouteFactory = (libs) => ({
method: 'GET',
path: API_URLS.SYNTHETICS_ENABLEMENT,
validate: {},
handler: async ({ response, server }): Promise<any> => {
handler: async ({ savedObjectsClient, request, server }): Promise<any> => {
try {
return response.ok({
body: await libs.requests.getSyntheticsEnablement({
const result = await libs.requests.getSyntheticsEnablement({
server,
});
const { canEnable, isEnabled } = result;
if (canEnable && !isEnabled && server.config.service?.manifestUrl) {
await generateAndSaveServiceAPIKey({
request,
authSavedObjectsClient: savedObjectsClient,
server,
}),
});
} else {
return result;
}
return libs.requests.getSyntheticsEnablement({
server,
});
} catch (e) {
server.logger.error(e);
@ -69,12 +81,12 @@ export const enableSyntheticsRoute: UMRestApiRouteFactory = (libs) => ({
method: 'POST',
path: API_URLS.SYNTHETICS_ENABLEMENT,
validate: {},
handler: async ({ request, response, server }): Promise<any> => {
const { authSavedObjectsClient, logger } = server;
handler: async ({ request, response, server, savedObjectsClient }): Promise<any> => {
const { logger } = server;
try {
await generateAndSaveServiceAPIKey({
request,
authSavedObjectsClient,
authSavedObjectsClient: savedObjectsClient,
server,
});
return response.ok({

View file

@ -158,7 +158,17 @@ export const generateAndSaveServiceAPIKey = async ({
};
export const getSyntheticsEnablement = async ({ server }: { server: UptimeServerSetup }) => {
const { security } = server;
const { security, config } = server;
if (!config.service?.manifestUrl) {
return {
canEnable: true,
canManageApiKeys: true,
isEnabled: true,
isValidApiKey: true,
areApiKeysEnabled: true,
};
}
const [apiKey, hasPrivileges, areApiKeysEnabled] = await Promise.all([
getAPIKeyForSyntheticsService({ server }),

View file

@ -33,8 +33,9 @@ export async function getServiceLocations(server: UptimeServerSetup) {
if (server.config.service?.devUrl) {
locations = [getDevLocation(server.config.service.devUrl)];
}
const manifestUrl = server.config.service?.manifestUrl;
if (!server.config.service?.manifestUrl) {
if (!manifestUrl || manifestUrl === 'mockDevUrl') {
return { locations };
}

View file

@ -100,7 +100,9 @@ describe('SyntheticsService', () => {
status: LocationStatus.GA,
};
});
serverMock.config = { service: { devUrl: 'http://localhost' } };
serverMock.config = {
service: { devUrl: 'http://localhost', manifestUrl: 'https://test-manifest.com' },
};
if (serverMock.savedObjectsClient) {
serverMock.savedObjectsClient.find = jest.fn().mockResolvedValue({
saved_objects: [

View file

@ -174,7 +174,7 @@ export class SyntheticsService {
service.isAllowed = allowed;
service.signupUrl = signupUrl;
if (service.isAllowed) {
if (service.isAllowed && service.config.manifestUrl) {
service.setupIndexTemplates();
await service.pushConfigs();
}
@ -349,7 +349,7 @@ export class SyntheticsService {
subject.subscribe(async (monitors) => {
try {
if (monitors.length === 0) {
if (monitors.length === 0 || !this.config.manifestUrl) {
return;
}

View file

@ -35020,8 +35020,6 @@
"xpack.synthetics.monitorManagement.editMonitorError": "Erreur lors du chargement de la liste Gestion des moniteurs",
"xpack.synthetics.monitorManagement.editMonitorError.description": "Les paramètres de Gestion des moniteurs n'ont pas pu être chargés. Veuillez contacter le support technique.",
"xpack.synthetics.monitorManagement.emptyState.enablement": "Activez la Gestion des moniteurs pour exécuter des moniteurs légers et basés sur un navigateur réel à partir d'emplacements de test hébergés dans le monde entier. L'activation de la Gestion des moniteurs générera une clé d'API pour autoriser le service Synthetics à mettre à jour votre cluster Elasticsearch.",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabled.title": "La Gestion des moniteurs est désactivée",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabledDescription": "La Gestion des moniteurs est actuellement désactivée. La Gestion des moniteurs vous permet d'exécuter des moniteurs légers et basés sur un navigateur réel à partir d'emplacements de test hébergés dans le monde entier. Pour activer la Gestion des moniteurs, veuillez contacter un administrateur.",
"xpack.synthetics.monitorManagement.emptyState.enablement.doc": "Lisez les documents",
"xpack.synthetics.monitorManagement.emptyState.enablement.enabled.title": "Activer la Gestion des moniteurs",
"xpack.synthetics.monitorManagement.emptyState.enablement.learnMore": "Envie d'en savoir plus ?",
@ -35090,9 +35088,7 @@
"xpack.synthetics.monitorManagement.startAddingLocationsDescription": "Les emplacements privés vous permettent d'exploiter des moniteurs depuis vos propres locaux. Ils nécessitent un agent Elastic et une politique d'agent que vous pouvez contrôler et maintenir via Fleet.",
"xpack.synthetics.monitorManagement.steps": "Étapes",
"xpack.synthetics.monitorManagement.summary.heading": "Résumé",
"xpack.synthetics.monitorManagement.syntheticsDisabledFailure": "La Gestion des moniteurs n'a pas pu être désactivée. Veuillez contacter le support technique.",
"xpack.synthetics.monitorManagement.syntheticsDisabledSuccess": "Gestion des moniteurs désactivée avec succès.",
"xpack.synthetics.monitorManagement.syntheticsEnabledFailure": "La Gestion des moniteurs n'a pas pu être activée. Veuillez contacter le support technique.",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.invalidKey": "Activer la Gestion des moniteurs",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.management": "Activer la Gestion des moniteurs",
"xpack.synthetics.monitorManagement.syntheticsEnableSuccess": "Gestion des moniteurs activée avec succès.",
@ -38041,4 +38037,4 @@
"xpack.painlessLab.title": "Painless Lab",
"xpack.painlessLab.walkthroughButtonLabel": "Présentation"
}
}
}

View file

@ -34999,8 +34999,6 @@
"xpack.synthetics.monitorManagement.editMonitorError": "モニター管理の読み込みエラー",
"xpack.synthetics.monitorManagement.editMonitorError.description": "モニター管理設定を読み込めませんでした。サポートに問い合わせてください。",
"xpack.synthetics.monitorManagement.emptyState.enablement": "モニター管理を有効にすると、世界中のホスティングされたテスト場所から軽量でリアルなブラウザーモニターを実行できます。モニター管理を有効にすると、APIキーが生成され、SyntheticsサービスはElasticsearchクラスターに書き込むことができます。",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabled.title": "モニター管理が無効です",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabledDescription": "モニター管理は現在無効です。モニター管理では、世界中のホスティングされたテスト場所から軽量でリアルなブラウザーモニターを実行できます。モニター管理を有効にするには、管理者に連絡してください。",
"xpack.synthetics.monitorManagement.emptyState.enablement.doc": "<b>ドキュメント</b><b>を読む</b>",
"xpack.synthetics.monitorManagement.emptyState.enablement.enabled.title": "モニター管理を有効にする",
"xpack.synthetics.monitorManagement.emptyState.enablement.learnMore": "詳細について",
@ -35069,9 +35067,7 @@
"xpack.synthetics.monitorManagement.startAddingLocationsDescription": "非公開の場所では、独自の施設からモニターを実行できます。Fleet経由で制御および保守できるElasticエージェントとエージェントポリシーが必要です。",
"xpack.synthetics.monitorManagement.steps": "ステップ",
"xpack.synthetics.monitorManagement.summary.heading": "まとめ",
"xpack.synthetics.monitorManagement.syntheticsDisabledFailure": "モニター管理を無効にできませんでした。サポートに問い合わせてください。",
"xpack.synthetics.monitorManagement.syntheticsDisabledSuccess": "モニター管理は正常に無効にされました。",
"xpack.synthetics.monitorManagement.syntheticsEnabledFailure": "モニター管理を有効にできませんでした。サポートに問い合わせてください。",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.invalidKey": "モニター管理を有効にする",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.management": "モニター管理を有効にする",
"xpack.synthetics.monitorManagement.syntheticsEnableSuccess": "モニター管理は正常に有効にされました。",
@ -38009,4 +38005,4 @@
"xpack.painlessLab.title": "Painless Lab",
"xpack.painlessLab.walkthroughButtonLabel": "実地検証"
}
}
}

View file

@ -35015,8 +35015,6 @@
"xpack.synthetics.monitorManagement.editMonitorError": "加载监测管理时出错",
"xpack.synthetics.monitorManagement.editMonitorError.description": "无法加载监测管理设置。请联系支持人员。",
"xpack.synthetics.monitorManagement.emptyState.enablement": "启用监测管理以从全球托管测试地点运行轻量级、真正的浏览器监测。启用监测管理将生成 API 密钥,以便 Synthetics 服务回写 Elasticsearch 集群。",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabled.title": "已禁用监测管理",
"xpack.synthetics.monitorManagement.emptyState.enablement.disabledDescription": "监测管理当前处于禁用状态。通过监测管理,您可以从全球托管测试地点运行轻量级、真正的浏览器监测。要启用监测管理,请与管理员联系。",
"xpack.synthetics.monitorManagement.emptyState.enablement.doc": "阅读文档",
"xpack.synthetics.monitorManagement.emptyState.enablement.enabled.title": "启用监测管理",
"xpack.synthetics.monitorManagement.emptyState.enablement.learnMore": "希望了解详情?",
@ -35085,9 +35083,7 @@
"xpack.synthetics.monitorManagement.startAddingLocationsDescription": "专用位置供您从自己的场所运行监测。它们需要可以通过 Fleet 进行控制和维护的 Elastic 代理和代理策略。",
"xpack.synthetics.monitorManagement.steps": "步长",
"xpack.synthetics.monitorManagement.summary.heading": "摘要",
"xpack.synthetics.monitorManagement.syntheticsDisabledFailure": "无法禁用监测管理。请联系支持人员。",
"xpack.synthetics.monitorManagement.syntheticsDisabledSuccess": "已成功禁用监测管理。",
"xpack.synthetics.monitorManagement.syntheticsEnabledFailure": "无法启用监测管理。请联系支持人员。",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.invalidKey": "启用监测管理",
"xpack.synthetics.monitorManagement.syntheticsEnableLabel.management": "启用监测管理",
"xpack.synthetics.monitorManagement.syntheticsEnableSuccess": "已成功启用监测管理。",
@ -38036,4 +38032,4 @@
"xpack.painlessLab.title": "Painless 实验室",
"xpack.painlessLab.walkthroughButtonLabel": "指导"
}
}
}

View file

@ -12,6 +12,16 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
return {
...baseIntegrationTestsConfig.getAll(),
kbnTestServer: {
...baseIntegrationTestsConfig.get('kbnTestServer'),
serverArgs: [
...baseIntegrationTestsConfig.get('kbnTestServer.serverArgs'),
'--xpack.uptime.service.password=test',
'--xpack.uptime.service.username=localKibanaIntegrationTestsUser',
'--xpack.uptime.service.devUrl=mockDevUrl',
'--xpack.uptime.service.manifestUrl=mockDevUrl',
],
},
testFiles: [require.resolve('.')],
};
}

View file

@ -11,7 +11,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
describe('/internal/uptime/service/enablement', () => {
describe('SyntheticsEnablement', () => {
const supertestWithAuth = getService('supertest');
const supertest = getService('supertestWithoutAuth');
const security = getService('security');
@ -22,7 +22,7 @@ export default function ({ getService }: FtrProviderContext) {
});
describe('[GET] - /internal/uptime/service/enablement', () => {
['manage_security', 'manage_api_key', 'manage_own_api_key'].forEach((privilege) => {
['manage_security', 'manage_own_api_key', 'manage_api_key'].forEach((privilege) => {
it(`returns response for an admin with privilege ${privilege}`, async () => {
const username = 'admin';
const roleName = `synthetics_admin-${privilege}`;
@ -59,9 +59,16 @@ export default function ({ getService }: FtrProviderContext) {
areApiKeysEnabled: true,
canManageApiKeys: true,
canEnable: true,
isEnabled: false,
isValidApiKey: false,
isEnabled: true,
isValidApiKey: true,
});
if (privilege !== 'manage_own_api_key') {
await supertest
.delete(API_URLS.SYNTHETICS_ENABLEMENT)
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(200);
}
} finally {
await security.user.delete(username);
await security.role.delete(roleName);
@ -247,11 +254,12 @@ export default function ({ getService }: FtrProviderContext) {
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(200);
await supertest
const delResponse = await supertest
.delete(API_URLS.SYNTHETICS_ENABLEMENT)
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(200);
expect(delResponse.body).eql({});
const apiResponse = await supertest
.get(API_URLS.SYNTHETICS_ENABLEMENT)
.auth(username, password)
@ -262,8 +270,8 @@ export default function ({ getService }: FtrProviderContext) {
areApiKeysEnabled: true,
canManageApiKeys: true,
canEnable: true,
isEnabled: false,
isValidApiKey: false,
isEnabled: true,
isValidApiKey: true,
});
} finally {
await security.user.delete(username);
@ -354,7 +362,21 @@ export default function ({ getService }: FtrProviderContext) {
full_name: 'a kibana user',
});
// can disable synthetics in default space when enabled in a non default space
// can enable synthetics in default space when enabled in a non default space
const apiResponseGet = await supertest
.get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_ENABLEMENT}`)
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(200);
expect(apiResponseGet.body).eql({
areApiKeysEnabled: true,
canManageApiKeys: true,
canEnable: true,
isEnabled: true,
isValidApiKey: true,
});
await supertest
.post(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_ENABLEMENT}`)
.auth(username, password)
@ -375,8 +397,8 @@ export default function ({ getService }: FtrProviderContext) {
areApiKeysEnabled: true,
canManageApiKeys: true,
canEnable: true,
isEnabled: false,
isValidApiKey: false,
isEnabled: true,
isValidApiKey: true,
});
// can disable synthetics in non default space when enabled in default space
@ -400,8 +422,8 @@ export default function ({ getService }: FtrProviderContext) {
areApiKeysEnabled: true,
canManageApiKeys: true,
canEnable: true,
isEnabled: false,
isValidApiKey: false,
isEnabled: true,
isValidApiKey: true,
});
} finally {
await security.user.delete(username);