From 1032cebca522bddd133dbb346cbf3f99551702b9 Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Fri, 28 Jul 2023 14:28:15 +0200 Subject: [PATCH 1/4] Removing custom_logs from routes and making them more generic --- .../public/assets/standalone_agent_setup.sh | 2 +- .../wizard/install_elastic_agent.tsx | 10 +- .../custom_logs => lib}/get_fallback_urls.ts | 2 +- .../get_observability_onboarding_state.ts | 2 +- .../server/lib/state/index.ts | 9 ++ .../save_observability_onboarding_state.ts | 1 + ...d_latest_observability_onboarding_state.ts | 36 ------ .../server/routes/elastic_agent/route.ts | 14 +-- .../server/routes/index.ts | 6 +- .../flow}/api_key/create_shipper_api_key.ts | 0 .../flow}/api_key/monitoring_config.ts | 0 .../flow}/get_has_logs.ts | 0 .../{custom_logs => logs/flow}/route.ts | 107 ++++++------------ .../server/routes/logs/index.ts | 14 +++ .../setup}/has_log_monitoring_privileges.ts | 2 +- .../server/routes/logs/setup/route.ts | 61 ++++++++++ .../server/routes/status/route.ts | 22 ---- .../observability_onboarding_status.ts | 19 ++-- .../authentication.ts | 2 +- 19 files changed, 151 insertions(+), 158 deletions(-) rename x-pack/plugins/observability_onboarding/server/{routes/custom_logs => lib}/get_fallback_urls.ts (90%) rename x-pack/plugins/observability_onboarding/server/{routes/custom_logs => lib/state}/get_observability_onboarding_state.ts (100%) create mode 100644 x-pack/plugins/observability_onboarding/server/lib/state/index.ts rename x-pack/plugins/observability_onboarding/server/{routes/custom_logs => lib/state}/save_observability_onboarding_state.ts (97%) delete mode 100644 x-pack/plugins/observability_onboarding/server/routes/custom_logs/find_latest_observability_onboarding_state.ts rename x-pack/plugins/observability_onboarding/server/routes/{custom_logs => logs/flow}/api_key/create_shipper_api_key.ts (100%) rename x-pack/plugins/observability_onboarding/server/routes/{custom_logs => logs/flow}/api_key/monitoring_config.ts (100%) rename x-pack/plugins/observability_onboarding/server/routes/{custom_logs => logs/flow}/get_has_logs.ts (100%) rename x-pack/plugins/observability_onboarding/server/routes/{custom_logs => logs/flow}/route.ts (63%) create mode 100644 x-pack/plugins/observability_onboarding/server/routes/logs/index.ts rename x-pack/plugins/observability_onboarding/server/routes/{custom_logs/api_key => logs/setup}/has_log_monitoring_privileges.ts (89%) create mode 100644 x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts delete mode 100644 x-pack/plugins/observability_onboarding/server/routes/status/route.ts diff --git a/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh b/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh index 1153b933c7b1a..7ee37fa8e5043 100755 --- a/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh +++ b/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh @@ -55,7 +55,7 @@ updateStepProgress() { local STATUS="$2" # "incomplete" | "complete" | "disabled" | "loading" | "warning" | "danger" | "current" local MESSAGE=${3:-} curl --request POST \ - --url "${API_ENDPOINT}/custom_logs/${ONBOARDING_ID}/step/${STEPNAME}" \ + --url "${API_ENDPOINT}/logs/flow/${ONBOARDING_ID}/step/${STEPNAME}" \ --header "Authorization: ApiKey ${API_KEY_ENCODED}" \ --header "Content-Type: application/json" \ --header "kbn-xsrf: true" \ diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx index e29a2d84036e9..dcdf10c7ca114 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx @@ -60,7 +60,7 @@ export function InstallElasticAgent() { (callApi) => { if (!hasAlreadySavedFlow(getState())) { return callApi( - 'GET /internal/observability_onboarding/custom_logs/privileges' + 'GET /internal/observability_onboarding/logs/setup/privileges' ); } }, @@ -69,7 +69,7 @@ export function InstallElasticAgent() { const { data: setup } = useFetcher((callApi) => { return callApi( - 'GET /internal/observability_onboarding/custom_logs/install_shipper_setup' + 'GET /internal/observability_onboarding/logs/setup/install_shipper_setup' ); }, []); @@ -88,7 +88,7 @@ export function InstallElasticAgent() { } = getState(); if (!hasAlreadySavedFlow(getState()) && monitoringRole?.hasPrivileges) { return callApi( - 'POST /internal/observability_onboarding/custom_logs/save', + 'POST /internal/observability_onboarding/logs/flow/create', { params: { body: { @@ -120,7 +120,7 @@ export function InstallElasticAgent() { } = getState(); if (onboardingId) { return callApi( - 'PUT /internal/observability_onboarding/custom_logs/{onboardingId}/save', + 'PUT /internal/observability_onboarding/logs/flow/{onboardingId}/save', { params: { path: { onboardingId }, @@ -173,7 +173,7 @@ export function InstallElasticAgent() { (callApi) => { if (onboardingId) { return callApi( - 'GET /internal/observability_onboarding/custom_logs/{onboardingId}/progress', + 'GET /internal/observability_onboarding/logs/flow/{onboardingId}/progress', { params: { path: { onboardingId } } } ); } diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_fallback_urls.ts b/x-pack/plugins/observability_onboarding/server/lib/get_fallback_urls.ts similarity index 90% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_fallback_urls.ts rename to x-pack/plugins/observability_onboarding/server/lib/get_fallback_urls.ts index 06e560315d5c3..3a8963f9d2bbc 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_fallback_urls.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/get_fallback_urls.ts @@ -6,7 +6,7 @@ */ import { CoreStart } from '@kbn/core/server'; -import { EsLegacyConfigService } from '../../services/es_legacy_config_service'; +import { EsLegacyConfigService } from '../services/es_legacy_config_service'; export function getFallbackKibanaUrl({ http }: CoreStart) { const basePath = http.basePath; diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_observability_onboarding_state.ts b/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_observability_onboarding_state.ts rename to x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts index fd0c3edfb611b..f107c825c3f0a 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_observability_onboarding_state.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts @@ -7,8 +7,8 @@ import { SavedObjectsClientContract } from '@kbn/core/server'; import { - OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, ObservabilityOnboardingState, + OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, SavedObservabilityOnboardingState, } from '../../saved_objects/observability_onboarding_status'; diff --git a/x-pack/plugins/observability_onboarding/server/lib/state/index.ts b/x-pack/plugins/observability_onboarding/server/lib/state/index.ts new file mode 100644 index 0000000000000..5e3ea9d1c69c5 --- /dev/null +++ b/x-pack/plugins/observability_onboarding/server/lib/state/index.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export * from './get_observability_onboarding_state'; +export * from './save_observability_onboarding_state'; diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/save_observability_onboarding_state.ts b/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts similarity index 97% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/save_observability_onboarding_state.ts rename to x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts index ca18c18e18f61..b4aaf86fe08aa 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/save_observability_onboarding_state.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts @@ -31,6 +31,7 @@ export async function saveObservabilityOnboardingState({ OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, savedObjectId, { + type: observabilityOnboardingState.type, state: observabilityOnboardingState.state, progress: { ...observabilityOnboardingState.progress }, } diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/find_latest_observability_onboarding_state.ts b/x-pack/plugins/observability_onboarding/server/routes/custom_logs/find_latest_observability_onboarding_state.ts deleted file mode 100644 index fa379fc089c65..0000000000000 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/find_latest_observability_onboarding_state.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 { SavedObjectsClientContract } from '@kbn/core/server'; -import { - OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, - ObservabilityOnboardingState, - SavedObservabilityOnboardingState, -} from '../../saved_objects/observability_onboarding_status'; - -export async function findLatestObservabilityOnboardingState({ - savedObjectsClient, -}: { - savedObjectsClient: SavedObjectsClientContract; -}): Promise { - const result = await savedObjectsClient.find({ - type: OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, - page: 1, - perPage: 1, - sortField: `updated_at`, - sortOrder: 'desc', - }); - if (result.total === 0) { - return undefined; - } - const { id, updated_at: updatedAt, attributes } = result.saved_objects[0]; - return { - id, - updatedAt: updatedAt ? Date.parse(updatedAt) : 0, - ...attributes, - }; -} diff --git a/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts b/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts index 1d243845d580f..c2eb56b269177 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts @@ -8,9 +8,9 @@ import * as t from 'io-ts'; import { getAuthenticationAPIKey } from '../../lib/get_authentication_api_key'; import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; -import { getObservabilityOnboardingState } from '../custom_logs/get_observability_onboarding_state'; import { generateYml } from './generate_yml'; -import { getFallbackESUrl } from '../custom_logs/get_fallback_urls'; +import { getFallbackESUrl } from '../../lib/get_fallback_urls'; +import { getObservabilityOnboardingState } from '../../lib/state'; const generateConfig = createObservabilityOnboardingServerRoute({ endpoint: 'GET /internal/observability_onboarding/elastic_agent/config', @@ -44,16 +44,16 @@ const generateConfig = createObservabilityOnboardingServerRoute({ }); const yaml = generateYml({ - datasetName: savedState?.state.datasetName, - customConfigurations: savedState?.state.customConfigurations, - logFilePaths: savedState?.state.logFilePaths, - namespace: savedState?.state.namespace, + datasetName: savedState?.state?.datasetName, + customConfigurations: savedState?.state?.customConfigurations, + logFilePaths: savedState?.state?.logFilePaths, + namespace: savedState?.state?.namespace, apiKey: authApiKey ? `${authApiKey?.apiKeyId}:${authApiKey?.apiKey}` : '$API_KEY', esHost: elasticsearchUrl, logfileId: `custom-logs-${Date.now()}`, - serviceName: savedState?.state.serviceName, + serviceName: savedState?.state?.serviceName, }); return yaml; diff --git a/x-pack/plugins/observability_onboarding/server/routes/index.ts b/x-pack/plugins/observability_onboarding/server/routes/index.ts index 4833f44a2936c..0f7f50a5d4058 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/index.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/index.ts @@ -8,14 +8,12 @@ import type { EndpointOf, ServerRouteRepository, } from '@kbn/server-route-repository'; -import { statusRouteRepository } from './status/route'; -import { customLogsRouteRepository } from './custom_logs/route'; import { elasticAgentRouteRepository } from './elastic_agent/route'; +import { logsOnboardingRoutes } from './logs'; function getTypedObservabilityOnboardingServerRouteRepository() { const repository = { - ...statusRouteRepository, - ...customLogsRouteRepository, + ...logsOnboardingRoutes, ...elasticAgentRouteRepository, }; diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/create_shipper_api_key.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/create_shipper_api_key.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/create_shipper_api_key.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/create_shipper_api_key.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/monitoring_config.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/monitoring_config.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/monitoring_config.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/monitoring_config.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_has_logs.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/flow/get_has_logs.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/get_has_logs.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/flow/get_has_logs.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/route.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts similarity index 63% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/route.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts index b71292b94aa93..faaa34776dfb7 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts @@ -7,69 +7,27 @@ import Boom from '@hapi/boom'; import * as t from 'io-ts'; -import { ObservabilityOnboardingState } from '../../saved_objects/observability_onboarding_status'; -import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; +import { + getObservabilityOnboardingState, + saveObservabilityOnboardingState, +} from '../../../lib/state'; +import { ObservabilityOnboardingState } from '../../../saved_objects/observability_onboarding_status'; +import { createObservabilityOnboardingServerRoute } from '../../create_observability_onboarding_server_route'; import { createShipperApiKey } from './api_key/create_shipper_api_key'; -import { hasLogMonitoringPrivileges } from './api_key/has_log_monitoring_privileges'; -import { getFallbackKibanaUrl } from './get_fallback_urls'; import { getHasLogs } from './get_has_logs'; -import { getObservabilityOnboardingState } from './get_observability_onboarding_state'; -import { saveObservabilityOnboardingState } from './save_observability_onboarding_state'; -const logMonitoringPrivilegesRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'GET /internal/observability_onboarding/custom_logs/privileges', - options: { tags: [] }, - - handler: async (resources): Promise<{ hasPrivileges: boolean }> => { - const { context } = resources; - - const { - elasticsearch: { client }, - } = await context.core; - - const hasPrivileges = await hasLogMonitoringPrivileges( - client.asCurrentUser - ); - - return { hasPrivileges }; - }, -}); - -const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ - endpoint: - 'GET /internal/observability_onboarding/custom_logs/install_shipper_setup', - options: { tags: [] }, - async handler(resources): Promise<{ - apiEndpoint: string; - scriptDownloadUrl: string; - elasticAgentVersion: string; - }> { - const { core, plugins, kibanaVersion } = resources; - const coreStart = await core.start(); - - const kibanaUrl = - core.setup.http.basePath.publicBaseUrl ?? // priority given to server.publicBaseUrl - plugins.cloud?.setup?.kibanaUrl ?? // then cloud id - getFallbackKibanaUrl(coreStart); // falls back to local network binding - const scriptDownloadUrl = `${kibanaUrl}/plugins/observabilityOnboarding/assets/standalone_agent_setup.sh`; - const apiEndpoint = `${kibanaUrl}/internal/observability_onboarding`; - - return { - apiEndpoint, - scriptDownloadUrl, - elasticAgentVersion: kibanaVersion, - }; - }, -}); - -const createApiKeyRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', +const createFlowRoute = createObservabilityOnboardingServerRoute({ + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', options: { tags: [] }, params: t.type({ - body: t.type({ - name: t.string, - state: t.record(t.string, t.unknown), - }), + body: t.intersection([ + t.type({ + name: t.string, + }), + t.partial({ + state: t.record(t.string, t.unknown), + }), + ]), }), async handler( resources @@ -96,6 +54,7 @@ const createApiKeyRoute = createObservabilityOnboardingServerRoute({ const { id } = await saveObservabilityOnboardingState({ savedObjectsClient, observabilityOnboardingState: { + type: 'logFiles', state: state as ObservabilityOnboardingState['state'], progress: {}, }, @@ -105,15 +64,15 @@ const createApiKeyRoute = createObservabilityOnboardingServerRoute({ }, }); -const updateOnboardingStateRoute = createObservabilityOnboardingServerRoute({ +const updateOnboardingFlowRoute = createObservabilityOnboardingServerRoute({ endpoint: - 'PUT /internal/observability_onboarding/custom_logs/{onboardingId}/save', + 'PUT /internal/observability_onboarding/logs/flow/{onboardingId}/save', options: { tags: [] }, params: t.type({ path: t.type({ onboardingId: t.string, }), - body: t.type({ + body: t.partial({ state: t.record(t.string, t.unknown), }), }), @@ -131,7 +90,11 @@ const updateOnboardingStateRoute = createObservabilityOnboardingServerRoute({ const { id } = await saveObservabilityOnboardingState({ savedObjectsClient, savedObjectId: onboardingId, - observabilityOnboardingState: { state } as ObservabilityOnboardingState, + observabilityOnboardingState: { + type: 'logFiles', + state, + progress: {}, + } as ObservabilityOnboardingState, }); return { onboardingId: id }; }, @@ -139,7 +102,7 @@ const updateOnboardingStateRoute = createObservabilityOnboardingServerRoute({ const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ endpoint: - 'POST /internal/observability_onboarding/custom_logs/{id}/step/{name}', + 'POST /internal/observability_onboarding/logs/flow/{id}/step/{name}', options: { tags: [] }, params: t.type({ path: t.type({ @@ -200,7 +163,7 @@ const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ const getProgressRoute = createObservabilityOnboardingServerRoute({ endpoint: - 'GET /internal/observability_onboarding/custom_logs/{onboardingId}/progress', + 'GET /internal/observability_onboarding/logs/flow/{onboardingId}/progress', options: { tags: [] }, params: t.type({ path: t.type({ @@ -236,9 +199,11 @@ const getProgressRoute = createObservabilityOnboardingServerRoute({ const esClient = coreStart.elasticsearch.client.asScoped(request).asCurrentUser; - const { - state: { datasetName: dataset, namespace }, - } = savedObservabilityOnboardingState; + const dataset = savedObservabilityOnboardingState.state + ?.datasetName as string; + const namespace = savedObservabilityOnboardingState.state + ?.namespace as string; + if (progress['ea-status']?.status === 'complete') { try { const hasLogs = await getHasLogs({ @@ -262,11 +227,9 @@ const getProgressRoute = createObservabilityOnboardingServerRoute({ }, }); -export const customLogsRouteRepository = { - ...logMonitoringPrivilegesRoute, - ...installShipperSetupRoute, - ...createApiKeyRoute, - ...updateOnboardingStateRoute, +export const logsFlowRouteRepository = { + ...createFlowRoute, + ...updateOnboardingFlowRoute, ...stepProgressUpdateRoute, ...getProgressRoute, }; diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts new file mode 100644 index 0000000000000..1534f1250ec85 --- /dev/null +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts @@ -0,0 +1,14 @@ +/* + * 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 { logsFlowRouteRepository } from './flow/route'; +import { logsSetupRouteRepository } from './setup/route'; + +export const logsOnboardingRoutes = { + ...logsFlowRouteRepository, + ...logsSetupRouteRepository, +}; diff --git a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/has_log_monitoring_privileges.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts similarity index 89% rename from x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/has_log_monitoring_privileges.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts index 2446f0fa04af7..234290fec3854 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/custom_logs/api_key/has_log_monitoring_privileges.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import { cluster, indices } from './monitoring_config'; +import { cluster, indices } from '../flow/api_key/monitoring_config'; export async function hasLogMonitoringPrivileges( esClient: ElasticsearchClient diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts new file mode 100644 index 0000000000000..21377bc822b45 --- /dev/null +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts @@ -0,0 +1,61 @@ +/* + * 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 { createObservabilityOnboardingServerRoute } from '../../create_observability_onboarding_server_route'; +import { getFallbackKibanaUrl } from '../../../lib/get_fallback_urls'; +import { hasLogMonitoringPrivileges } from './has_log_monitoring_privileges'; + +const logMonitoringPrivilegesRoute = createObservabilityOnboardingServerRoute({ + endpoint: 'GET /internal/observability_onboarding/logs/setup/privileges', + options: { tags: [] }, + + handler: async (resources): Promise<{ hasPrivileges: boolean }> => { + const { context } = resources; + + const { + elasticsearch: { client }, + } = await context.core; + + const hasPrivileges = await hasLogMonitoringPrivileges( + client.asCurrentUser + ); + + return { hasPrivileges }; + }, +}); + +const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ + endpoint: + 'GET /internal/observability_onboarding/logs/setup/install_shipper_setup', + options: { tags: [] }, + async handler(resources): Promise<{ + apiEndpoint: string; + scriptDownloadUrl: string; + elasticAgentVersion: string; + }> { + const { core, plugins, kibanaVersion } = resources; + const coreStart = await core.start(); + + const kibanaUrl = + core.setup.http.basePath.publicBaseUrl ?? // priority given to server.publicBaseUrl + plugins.cloud?.setup?.kibanaUrl ?? // then cloud id + getFallbackKibanaUrl(coreStart); // falls back to local network binding + const scriptDownloadUrl = `${kibanaUrl}/plugins/observabilityOnboarding/assets/standalone_agent_setup.sh`; + const apiEndpoint = `${kibanaUrl}/internal/observability_onboarding`; + + return { + apiEndpoint, + scriptDownloadUrl, + elasticAgentVersion: kibanaVersion, + }; + }, +}); + +export const logsSetupRouteRepository = { + ...logMonitoringPrivilegesRoute, + ...installShipperSetupRoute, +}; diff --git a/x-pack/plugins/observability_onboarding/server/routes/status/route.ts b/x-pack/plugins/observability_onboarding/server/routes/status/route.ts deleted file mode 100644 index 438bbe7e8b6a5..0000000000000 --- a/x-pack/plugins/observability_onboarding/server/routes/status/route.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; - -const statusRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'GET /internal/observability_onboarding/get_status', - options: { - tags: [], - }, - async handler(resources): Promise<{ status: 'incomplete' | 'complete' }> { - return { status: 'complete' }; - }, -}); - -export const statusRouteRepository = { - ...statusRoute, -}; diff --git a/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts b/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts index adc5291f73f72..533c2cbee16b2 100644 --- a/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts +++ b/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts @@ -9,15 +9,19 @@ import { SavedObjectsType } from '@kbn/core/server'; export const OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE = 'observability-onboarding-state'; +export interface LogFilesState { + datasetName: string; + serviceName?: string; + customConfigurations?: string; + logFilePaths: string[]; + namespace: string; +} + +type ObservabilityOnboardingFlowState = LogFilesState | undefined; export interface ObservabilityOnboardingState { - state: { - datasetName: string; - serviceName?: string; - customConfigurations?: string; - logFilePaths: string[]; - namespace: string; - }; + type: 'logFiles'; + state: ObservabilityOnboardingFlowState; progress: Record< string, { @@ -39,6 +43,7 @@ export const observabilityOnboardingState: SavedObjectsType = { namespaceType: 'agnostic', mappings: { properties: { + type: { type: 'keyword' }, state: { type: 'object', dynamic: false }, progress: { type: 'object', dynamic: false }, }, diff --git a/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts b/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts index 300cc029d92ce..a7fd3ae1f2338 100644 --- a/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts +++ b/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts @@ -8,7 +8,7 @@ import { cluster, indices, -} from '../../routes/custom_logs/api_key/monitoring_config'; +} from '../../routes/logs/flow/api_key/monitoring_config'; export enum ObservabilityOnboardingUsername { noAccessUser = 'no_access_user', From ae48838afb0598eaf2b3fc02e6288ea20d76258d Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Fri, 28 Jul 2023 16:58:44 +0200 Subject: [PATCH 2/4] Rearrenging endpoints for script --- .../group2/check_registered_types.test.ts | 2 +- .../public/assets/standalone_agent_setup.sh | 2 +- .../app/custom_logs/wizard/api_key_banner.tsx | 2 +- .../wizard/install_elastic_agent.tsx | 6 +- .../routes/{logs => }/flow/get_has_logs.ts | 0 .../server/routes/{logs => }/flow/route.ts | 66 ++-------- .../server/routes/index.ts | 6 +- .../api_key/create_shipper_api_key.ts | 0 .../has_log_monitoring_privileges.ts | 2 +- .../{flow => }/api_key/monitoring_config.ts | 0 .../server/routes/logs/index.ts | 14 --- .../server/routes/logs/route.ts | 113 ++++++++++++++++++ .../server/routes/logs/setup/route.ts | 61 ---------- .../authentication.ts | 5 +- .../tests/elastic_agent/config.spec.ts | 2 +- .../progress/es_utils.ts | 0 .../progress/progress.spec.ts | 6 +- .../save.spec.ts => logs/create.spec.ts} | 4 +- .../environment.spec.ts} | 2 +- .../{custom_logs => logs}/privileges.spec.ts | 2 +- .../update_step_progress.spec.ts | 4 +- 21 files changed, 142 insertions(+), 157 deletions(-) rename x-pack/plugins/observability_onboarding/server/routes/{logs => }/flow/get_has_logs.ts (100%) rename x-pack/plugins/observability_onboarding/server/routes/{logs => }/flow/route.ts (71%) rename x-pack/plugins/observability_onboarding/server/routes/logs/{flow => }/api_key/create_shipper_api_key.ts (100%) rename x-pack/plugins/observability_onboarding/server/routes/logs/{setup => api_key}/has_log_monitoring_privileges.ts (89%) rename x-pack/plugins/observability_onboarding/server/routes/logs/{flow => }/api_key/monitoring_config.ts (100%) delete mode 100644 x-pack/plugins/observability_onboarding/server/routes/logs/index.ts create mode 100644 x-pack/plugins/observability_onboarding/server/routes/logs/route.ts delete mode 100644 x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs => flow}/progress/es_utils.ts (100%) rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs => flow}/progress/progress.spec.ts (96%) rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs/save.spec.ts => logs/create.spec.ts} (94%) rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs/install_shipper_setup.spec.ts => logs/environment.spec.ts} (95%) rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs => logs}/privileges.spec.ts (95%) rename x-pack/test/observability_onboarding_api_integration/tests/{custom_logs => logs}/update_step_progress.spec.ts (96%) diff --git a/src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts index 063ed46c443f6..737522e973f98 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts @@ -120,7 +120,7 @@ describe('checking migration metadata changes on all registered SO types', () => "ml-module": "2225cbb4bd508ea5f69db4b848be9d8a74b60198", "ml-trained-model": "482195cefd6b04920e539d34d7356d22cb68e4f3", "monitoring-telemetry": "5d91bf75787d9d4dd2fae954d0b3f76d33d2e559", - "observability-onboarding-state": "55b112d6a33fedb7c1e4fec4da768d2bcc5fadc2", + "observability-onboarding-state": "c18631f47a0da568f12f859c9ab9d4ca73bdff7c", "osquery-manager-usage-metric": "983bcbc3b7dda0aad29b20907db233abba709bcc", "osquery-pack": "6ab4358ca4304a12dcfc1777c8135b75cffb4397", "osquery-pack-asset": "b14101d3172c4b60eb5404696881ce5275c84152", diff --git a/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh b/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh index 7ee37fa8e5043..cf0ed05d84462 100755 --- a/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh +++ b/x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh @@ -55,7 +55,7 @@ updateStepProgress() { local STATUS="$2" # "incomplete" | "complete" | "disabled" | "loading" | "warning" | "danger" | "current" local MESSAGE=${3:-} curl --request POST \ - --url "${API_ENDPOINT}/logs/flow/${ONBOARDING_ID}/step/${STEPNAME}" \ + --url "${API_ENDPOINT}/flow/${ONBOARDING_ID}/step/${STEPNAME}" \ --header "Authorization: ApiKey ${API_KEY_ENCODED}" \ --header "Content-Type: application/json" \ --header "kbn-xsrf: true" \ diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx index 2254105f979ff..878467853df79 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx @@ -21,7 +21,7 @@ import React from 'react'; import { APIReturnType } from '../../../../services/rest/create_call_api'; type ApiKeyPayload = - APIReturnType<'POST /internal/observability_onboarding/custom_logs/save'>; + APIReturnType<'POST /internal/observability_onboarding/logs/flow/create'>; export type HasPrivileges = boolean; diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx index dcdf10c7ca114..64bb801499d11 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx @@ -69,7 +69,7 @@ export function InstallElasticAgent() { const { data: setup } = useFetcher((callApi) => { return callApi( - 'GET /internal/observability_onboarding/logs/setup/install_shipper_setup' + 'GET /internal/observability_onboarding/logs/setup/environment' ); }, []); @@ -120,7 +120,7 @@ export function InstallElasticAgent() { } = getState(); if (onboardingId) { return callApi( - 'PUT /internal/observability_onboarding/logs/flow/{onboardingId}/save', + 'PUT /internal/observability_onboarding/flow/{onboardingId}/save', { params: { path: { onboardingId }, @@ -173,7 +173,7 @@ export function InstallElasticAgent() { (callApi) => { if (onboardingId) { return callApi( - 'GET /internal/observability_onboarding/logs/flow/{onboardingId}/progress', + 'GET /internal/observability_onboarding/flow/{onboardingId}/progress', { params: { path: { onboardingId } } } ); } diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/flow/get_has_logs.ts b/x-pack/plugins/observability_onboarding/server/routes/flow/get_has_logs.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/logs/flow/get_has_logs.ts rename to x-pack/plugins/observability_onboarding/server/routes/flow/get_has_logs.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts b/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts similarity index 71% rename from x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts rename to x-pack/plugins/observability_onboarding/server/routes/flow/route.ts index faaa34776dfb7..58aa5272a2a84 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/flow/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts @@ -10,63 +10,13 @@ import * as t from 'io-ts'; import { getObservabilityOnboardingState, saveObservabilityOnboardingState, -} from '../../../lib/state'; -import { ObservabilityOnboardingState } from '../../../saved_objects/observability_onboarding_status'; -import { createObservabilityOnboardingServerRoute } from '../../create_observability_onboarding_server_route'; -import { createShipperApiKey } from './api_key/create_shipper_api_key'; +} from '../../lib/state'; +import { ObservabilityOnboardingState } from '../../saved_objects/observability_onboarding_status'; +import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; import { getHasLogs } from './get_has_logs'; -const createFlowRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', - options: { tags: [] }, - params: t.type({ - body: t.intersection([ - t.type({ - name: t.string, - }), - t.partial({ - state: t.record(t.string, t.unknown), - }), - ]), - }), - async handler( - resources - ): Promise<{ apiKeyEncoded: string; onboardingId: string }> { - const { - context, - params: { - body: { name, state }, - }, - core, - request, - } = resources; - const coreStart = await core.start(); - const { - elasticsearch: { client }, - } = await context.core; - const { encoded: apiKeyEncoded } = await createShipperApiKey( - client.asCurrentUser, - name - ); - - const savedObjectsClient = coreStart.savedObjects.getScopedClient(request); - - const { id } = await saveObservabilityOnboardingState({ - savedObjectsClient, - observabilityOnboardingState: { - type: 'logFiles', - state: state as ObservabilityOnboardingState['state'], - progress: {}, - }, - }); - - return { apiKeyEncoded, onboardingId: id }; - }, -}); - const updateOnboardingFlowRoute = createObservabilityOnboardingServerRoute({ - endpoint: - 'PUT /internal/observability_onboarding/logs/flow/{onboardingId}/save', + endpoint: 'PUT /internal/observability_onboarding/flow/{onboardingId}/save', options: { tags: [] }, params: t.type({ path: t.type({ @@ -101,8 +51,7 @@ const updateOnboardingFlowRoute = createObservabilityOnboardingServerRoute({ }); const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ - endpoint: - 'POST /internal/observability_onboarding/logs/flow/{id}/step/{name}', + endpoint: 'POST /internal/observability_onboarding/flow/{id}/step/{name}', options: { tags: [] }, params: t.type({ path: t.type({ @@ -163,7 +112,7 @@ const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ const getProgressRoute = createObservabilityOnboardingServerRoute({ endpoint: - 'GET /internal/observability_onboarding/logs/flow/{onboardingId}/progress', + 'GET /internal/observability_onboarding/flow/{onboardingId}/progress', options: { tags: [] }, params: t.type({ path: t.type({ @@ -227,8 +176,7 @@ const getProgressRoute = createObservabilityOnboardingServerRoute({ }, }); -export const logsFlowRouteRepository = { - ...createFlowRoute, +export const flowRouteRepository = { ...updateOnboardingFlowRoute, ...stepProgressUpdateRoute, ...getProgressRoute, diff --git a/x-pack/plugins/observability_onboarding/server/routes/index.ts b/x-pack/plugins/observability_onboarding/server/routes/index.ts index 0f7f50a5d4058..133ba446d3442 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/index.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/index.ts @@ -9,11 +9,13 @@ import type { ServerRouteRepository, } from '@kbn/server-route-repository'; import { elasticAgentRouteRepository } from './elastic_agent/route'; -import { logsOnboardingRoutes } from './logs'; +import { flowRouteRepository } from './flow/route'; +import { logsOnboardingRouteRepository } from './logs/route'; function getTypedObservabilityOnboardingServerRouteRepository() { const repository = { - ...logsOnboardingRoutes, + ...flowRouteRepository, + ...logsOnboardingRouteRepository, ...elasticAgentRouteRepository, }; diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/create_shipper_api_key.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/api_key/create_shipper_api_key.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/create_shipper_api_key.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/api_key/create_shipper_api_key.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/api_key/has_log_monitoring_privileges.ts similarity index 89% rename from x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/api_key/has_log_monitoring_privileges.ts index 234290fec3854..2446f0fa04af7 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/setup/has_log_monitoring_privileges.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/api_key/has_log_monitoring_privileges.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import { cluster, indices } from '../flow/api_key/monitoring_config'; +import { cluster, indices } from './monitoring_config'; export async function hasLogMonitoringPrivileges( esClient: ElasticsearchClient diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/monitoring_config.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/api_key/monitoring_config.ts similarity index 100% rename from x-pack/plugins/observability_onboarding/server/routes/logs/flow/api_key/monitoring_config.ts rename to x-pack/plugins/observability_onboarding/server/routes/logs/api_key/monitoring_config.ts diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts deleted file mode 100644 index 1534f1250ec85..0000000000000 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 { logsFlowRouteRepository } from './flow/route'; -import { logsSetupRouteRepository } from './setup/route'; - -export const logsOnboardingRoutes = { - ...logsFlowRouteRepository, - ...logsSetupRouteRepository, -}; diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts new file mode 100644 index 0000000000000..df7d3b169eb5a --- /dev/null +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts @@ -0,0 +1,113 @@ +/* + * 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 * as t from 'io-ts'; +import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; +import { getFallbackKibanaUrl } from '../../lib/get_fallback_urls'; +import { hasLogMonitoringPrivileges } from './api_key/has_log_monitoring_privileges'; +import { saveObservabilityOnboardingState } from '../../lib/state'; +import { createShipperApiKey } from './api_key/create_shipper_api_key'; +import { ObservabilityOnboardingState } from '../../saved_objects/observability_onboarding_status'; + +const logMonitoringPrivilegesRoute = createObservabilityOnboardingServerRoute({ + endpoint: 'GET /internal/observability_onboarding/logs/setup/privileges', + options: { tags: [] }, + + handler: async (resources): Promise<{ hasPrivileges: boolean }> => { + const { context } = resources; + + const { + elasticsearch: { client }, + } = await context.core; + + const hasPrivileges = await hasLogMonitoringPrivileges( + client.asCurrentUser + ); + + return { hasPrivileges }; + }, +}); + +const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ + endpoint: 'GET /internal/observability_onboarding/logs/setup/environment', + options: { tags: [] }, + async handler(resources): Promise<{ + apiEndpoint: string; + scriptDownloadUrl: string; + elasticAgentVersion: string; + }> { + const { core, plugins, kibanaVersion } = resources; + const coreStart = await core.start(); + + const kibanaUrl = + core.setup.http.basePath.publicBaseUrl ?? // priority given to server.publicBaseUrl + plugins.cloud?.setup?.kibanaUrl ?? // then cloud id + getFallbackKibanaUrl(coreStart); // falls back to local network binding + const scriptDownloadUrl = `${kibanaUrl}/plugins/observabilityOnboarding/assets/standalone_agent_setup.sh`; + const apiEndpoint = `${kibanaUrl}/internal/observability_onboarding`; + + return { + apiEndpoint, + scriptDownloadUrl, + elasticAgentVersion: kibanaVersion, + }; + }, +}); + +const createFlowRoute = createObservabilityOnboardingServerRoute({ + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + options: { tags: [] }, + params: t.type({ + body: t.intersection([ + t.type({ + name: t.string, + }), + t.partial({ + state: t.record(t.string, t.unknown), + }), + ]), + }), + async handler( + resources + ): Promise<{ apiKeyEncoded: string; onboardingId: string }> { + const { + context, + params: { + body: { name, state }, + }, + core, + request, + } = resources; + const coreStart = await core.start(); + const { + elasticsearch: { client }, + } = await context.core; + const { encoded: apiKeyEncoded } = await createShipperApiKey( + client.asCurrentUser, + name + ); + + const savedObjectsClient = coreStart.savedObjects.getScopedClient(request); + + const { id } = await saveObservabilityOnboardingState({ + savedObjectsClient, + observabilityOnboardingState: { + type: 'logFiles', + state: state as ObservabilityOnboardingState['state'], + progress: {}, + }, + }); + + return { apiKeyEncoded, onboardingId: id }; + }, +}); + +export const logsOnboardingRouteRepository = { + ...logMonitoringPrivilegesRoute, + ...installShipperSetupRoute, + ...createFlowRoute, +}; diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts deleted file mode 100644 index 21377bc822b45..0000000000000 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/setup/route.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 { createObservabilityOnboardingServerRoute } from '../../create_observability_onboarding_server_route'; -import { getFallbackKibanaUrl } from '../../../lib/get_fallback_urls'; -import { hasLogMonitoringPrivileges } from './has_log_monitoring_privileges'; - -const logMonitoringPrivilegesRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'GET /internal/observability_onboarding/logs/setup/privileges', - options: { tags: [] }, - - handler: async (resources): Promise<{ hasPrivileges: boolean }> => { - const { context } = resources; - - const { - elasticsearch: { client }, - } = await context.core; - - const hasPrivileges = await hasLogMonitoringPrivileges( - client.asCurrentUser - ); - - return { hasPrivileges }; - }, -}); - -const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ - endpoint: - 'GET /internal/observability_onboarding/logs/setup/install_shipper_setup', - options: { tags: [] }, - async handler(resources): Promise<{ - apiEndpoint: string; - scriptDownloadUrl: string; - elasticAgentVersion: string; - }> { - const { core, plugins, kibanaVersion } = resources; - const coreStart = await core.start(); - - const kibanaUrl = - core.setup.http.basePath.publicBaseUrl ?? // priority given to server.publicBaseUrl - plugins.cloud?.setup?.kibanaUrl ?? // then cloud id - getFallbackKibanaUrl(coreStart); // falls back to local network binding - const scriptDownloadUrl = `${kibanaUrl}/plugins/observabilityOnboarding/assets/standalone_agent_setup.sh`; - const apiEndpoint = `${kibanaUrl}/internal/observability_onboarding`; - - return { - apiEndpoint, - scriptDownloadUrl, - elasticAgentVersion: kibanaVersion, - }; - }, -}); - -export const logsSetupRouteRepository = { - ...logMonitoringPrivilegesRoute, - ...installShipperSetupRoute, -}; diff --git a/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts b/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts index a7fd3ae1f2338..95da640fa40ae 100644 --- a/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts +++ b/x-pack/plugins/observability_onboarding/server/test_helpers/create_observability_onboarding_users/authentication.ts @@ -5,10 +5,7 @@ * 2.0. */ -import { - cluster, - indices, -} from '../../routes/logs/flow/api_key/monitoring_config'; +import { cluster, indices } from '../../routes/logs/api_key/monitoring_config'; export enum ObservabilityOnboardingUsername { noAccessUser = 'no_access_user', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts index 0deffa986676a..38fc040c9c3b6 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts @@ -33,7 +33,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', params: { body: { name: 'name', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/progress/es_utils.ts b/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/es_utils.ts similarity index 100% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/progress/es_utils.ts rename to x-pack/test/observability_onboarding_api_integration/tests/flow/progress/es_utils.ts diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/progress/progress.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts similarity index 96% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/progress/progress.spec.ts rename to x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts index c22b555b398d7..4efd52417bf86 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/progress/progress.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts @@ -25,7 +25,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { user?: ObservabilityOnboardingApiClientKey; }) { return await observabilityOnboardingApiClient[user]({ - endpoint: 'GET /internal/observability_onboarding/custom_logs/{onboardingId}/progress', + endpoint: 'GET /internal/observability_onboarding/flow/{onboardingId}/progress', params: { path: { onboardingId, @@ -41,7 +41,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', params: { body: { name: 'name', @@ -104,7 +104,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { describe('should not skip logs verification', () => { before(async () => { await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/{id}/step/{name}', + endpoint: 'POST /internal/observability_onboarding/flow/{id}/step/{name}', params: { path: { id: onboardingId, diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/save.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts similarity index 94% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/save.spec.ts rename to x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts index ad00d135d423e..d4464d82145e7 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/save.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts @@ -18,7 +18,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiWithoutPrivileges(state = {}) { return await observabilityOnboardingApiClient.readUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', params: { body: { name: 'name', @@ -30,7 +30,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiWithPrivileges(state = {}) { return await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', params: { body: { name: 'name', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/install_shipper_setup.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/environment.spec.ts similarity index 95% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/install_shipper_setup.spec.ts rename to x-pack/test/observability_onboarding_api_integration/tests/logs/environment.spec.ts index b2a1c601f3905..95626901d452a 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/install_shipper_setup.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/environment.spec.ts @@ -15,7 +15,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiWithPrivileges() { return await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'GET /internal/observability_onboarding/custom_logs/install_shipper_setup', + endpoint: 'GET /internal/observability_onboarding/logs/setup/environment', }); } diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/privileges.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/privileges.spec.ts similarity index 95% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/privileges.spec.ts rename to x-pack/test/observability_onboarding_api_integration/tests/logs/privileges.spec.ts index eefce48cde878..02de274373b20 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/privileges.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/privileges.spec.ts @@ -15,7 +15,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiAs(user: ObservabilityOnboardingApiClientKey) { return await observabilityOnboardingApiClient[user]({ - endpoint: 'GET /internal/observability_onboarding/custom_logs/privileges', + endpoint: 'GET /internal/observability_onboarding/logs/setup/privileges', }); } diff --git a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/update_step_progress.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts similarity index 96% rename from x-pack/test/observability_onboarding_api_integration/tests/custom_logs/update_step_progress.spec.ts rename to x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts index 1fd7c77abb7f2..eb235f8fb523f 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/custom_logs/update_step_progress.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts @@ -28,7 +28,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { message?: string; }) { return await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/{id}/step/{name}', + endpoint: 'POST /internal/observability_onboarding/flow/{id}/step/{name}', params: { path: { id, @@ -64,7 +64,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { beforeEach(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/custom_logs/save', + endpoint: 'POST /internal/observability_onboarding/logs/flow/create', params: { body: { name: 'name', From 83aaaa63f3ce6885f7c0247d5b5dd4e22274c7d3 Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Mon, 31 Jul 2023 13:03:59 +0200 Subject: [PATCH 3/4] fixing build --- .../tests/logs/create.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts index d4464d82145e7..4d0e969ebeda4 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts @@ -76,7 +76,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { id: request.body.onboardingId, }); - expect(savedState.attributes).to.be.eql({ state, progress: {} }); + expect(savedState.attributes).to.be.eql({ type: 'logFiles', state, progress: {} }); }); }); }); From b02287b424f0f7c8d6a6760ffc510978227887eb Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Mon, 31 Jul 2023 17:50:35 +0200 Subject: [PATCH 4/4] Attending PR comments --- .../current_mappings.json | 3 ++ .../app/custom_logs/wizard/api_key_banner.tsx | 2 +- .../wizard/install_elastic_agent.tsx | 29 +++++++++---------- ...s => get_observability_onboarding_flow.ts} | 10 +++---- .../server/lib/state/index.ts | 4 +-- ... => save_observability_onboarding_flow.ts} | 16 +++++----- .../observability_onboarding/server/plugin.ts | 4 +-- .../server/routes/elastic_agent/route.ts | 4 +-- .../server/routes/flow/route.ts | 18 ++++++------ .../server/routes/logs/route.ts | 10 +++---- .../observability_onboarding_status.ts | 8 ++--- .../tests/elastic_agent/config.spec.ts | 2 +- .../tests/flow/progress/progress.spec.ts | 2 +- .../tests/logs/create.spec.ts | 4 +-- .../tests/logs/update_step_progress.spec.ts | 2 +- 15 files changed, 59 insertions(+), 59 deletions(-) rename x-pack/plugins/observability_onboarding/server/lib/state/{get_observability_onboarding_state.ts => get_observability_onboarding_flow.ts} (82%) rename x-pack/plugins/observability_onboarding/server/lib/state/{save_observability_onboarding_state.ts => save_observability_onboarding_flow.ts} (80%) diff --git a/packages/kbn-check-mappings-update-cli/current_mappings.json b/packages/kbn-check-mappings-update-cli/current_mappings.json index cb78e060d6edc..cddc8e363a49e 100644 --- a/packages/kbn-check-mappings-update-cli/current_mappings.json +++ b/packages/kbn-check-mappings-update-cli/current_mappings.json @@ -2249,6 +2249,9 @@ }, "observability-onboarding-state": { "properties": { + "type": { + "type": "keyword" + }, "state": { "type": "object", "dynamic": false diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx index 878467853df79..57a7ba7b4cab1 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/api_key_banner.tsx @@ -21,7 +21,7 @@ import React from 'react'; import { APIReturnType } from '../../../../services/rest/create_call_api'; type ApiKeyPayload = - APIReturnType<'POST /internal/observability_onboarding/logs/flow/create'>; + APIReturnType<'POST /internal/observability_onboarding/logs/flow'>; export type HasPrivileges = boolean; diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx index 64bb801499d11..7fc7c12fa47d4 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx @@ -87,23 +87,20 @@ export function InstallElasticAgent() { logFilePaths, } = getState(); if (!hasAlreadySavedFlow(getState()) && monitoringRole?.hasPrivileges) { - return callApi( - 'POST /internal/observability_onboarding/logs/flow/create', - { - params: { - body: { - name: datasetName, - state: { - datasetName, - serviceName, - namespace, - customConfigurations, - logFilePaths, - }, + return callApi('POST /internal/observability_onboarding/logs/flow', { + params: { + body: { + name: datasetName, + state: { + datasetName, + serviceName, + namespace, + customConfigurations, + logFilePaths, }, }, - } - ); + }, + }); } }, [monitoringRole?.hasPrivileges] @@ -120,7 +117,7 @@ export function InstallElasticAgent() { } = getState(); if (onboardingId) { return callApi( - 'PUT /internal/observability_onboarding/flow/{onboardingId}/save', + 'PUT /internal/observability_onboarding/flow/{onboardingId}', { params: { path: { onboardingId }, diff --git a/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts b/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_flow.ts similarity index 82% rename from x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts rename to x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_flow.ts index f107c825c3f0a..70232fffe7794 100644 --- a/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_state.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/state/get_observability_onboarding_flow.ts @@ -7,20 +7,20 @@ import { SavedObjectsClientContract } from '@kbn/core/server'; import { - ObservabilityOnboardingState, + ObservabilityOnboardingFlow, OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, - SavedObservabilityOnboardingState, + SavedObservabilityOnboardingFlow, } from '../../saved_objects/observability_onboarding_status'; -export async function getObservabilityOnboardingState({ +export async function getObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId, }: { savedObjectsClient: SavedObjectsClientContract; savedObjectId: string; -}): Promise { +}): Promise { try { - const result = await savedObjectsClient.get( + const result = await savedObjectsClient.get( OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, savedObjectId ); diff --git a/x-pack/plugins/observability_onboarding/server/lib/state/index.ts b/x-pack/plugins/observability_onboarding/server/lib/state/index.ts index 5e3ea9d1c69c5..4308f5f9b1239 100644 --- a/x-pack/plugins/observability_onboarding/server/lib/state/index.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/state/index.ts @@ -5,5 +5,5 @@ * 2.0. */ -export * from './get_observability_onboarding_state'; -export * from './save_observability_onboarding_state'; +export * from './get_observability_onboarding_flow'; +export * from './save_observability_onboarding_flow'; diff --git a/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts b/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_flow.ts similarity index 80% rename from x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts rename to x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_flow.ts index b4aaf86fe08aa..13eb2e871d2a7 100644 --- a/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_state.ts +++ b/x-pack/plugins/observability_onboarding/server/lib/state/save_observability_onboarding_flow.ts @@ -8,26 +8,26 @@ import { SavedObjectsClientContract, SavedObject } from '@kbn/core/server'; import { OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, - ObservabilityOnboardingState, - SavedObservabilityOnboardingState, + ObservabilityOnboardingFlow, + SavedObservabilityOnboardingFlow, } from '../../saved_objects/observability_onboarding_status'; interface Options { savedObjectsClient: SavedObjectsClientContract; - observabilityOnboardingState: ObservabilityOnboardingState; + observabilityOnboardingState: ObservabilityOnboardingFlow; savedObjectId?: string; } -export async function saveObservabilityOnboardingState({ +export async function saveObservabilityOnboardingFlow({ savedObjectsClient, observabilityOnboardingState, savedObjectId, -}: Options): Promise { +}: Options): Promise { let savedObject: Omit< - SavedObject, + SavedObject, 'attributes' | 'references' >; if (savedObjectId) { - savedObject = await savedObjectsClient.update( + savedObject = await savedObjectsClient.update( OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, savedObjectId, { @@ -37,7 +37,7 @@ export async function saveObservabilityOnboardingState({ } ); } else { - savedObject = await savedObjectsClient.create( + savedObject = await savedObjectsClient.create( OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, observabilityOnboardingState ); diff --git a/x-pack/plugins/observability_onboarding/server/plugin.ts b/x-pack/plugins/observability_onboarding/server/plugin.ts index 9dc78fea2c6d5..6ed20935398ab 100644 --- a/x-pack/plugins/observability_onboarding/server/plugin.ts +++ b/x-pack/plugins/observability_onboarding/server/plugin.ts @@ -23,7 +23,7 @@ import { ObservabilityOnboardingPluginStartDependencies, } from './types'; import { ObservabilityOnboardingConfig } from '.'; -import { observabilityOnboardingState } from './saved_objects/observability_onboarding_status'; +import { observabilityOnboardingFlow } from './saved_objects/observability_onboarding_status'; import { EsLegacyConfigService } from './services/es_legacy_config_service'; export class ObservabilityOnboardingPlugin @@ -52,7 +52,7 @@ export class ObservabilityOnboardingPlugin this.logger.debug('observability_onboarding: Setup'); this.esLegacyConfigService.setup(core.elasticsearch.legacy.config$); - core.savedObjects.registerType(observabilityOnboardingState); + core.savedObjects.registerType(observabilityOnboardingFlow); const resourcePlugins = mapValues(plugins, (value, key) => { return { diff --git a/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts b/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts index c2eb56b269177..fe5549b7b8f16 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/elastic_agent/route.ts @@ -10,7 +10,7 @@ import { getAuthenticationAPIKey } from '../../lib/get_authentication_api_key'; import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; import { generateYml } from './generate_yml'; import { getFallbackESUrl } from '../../lib/get_fallback_urls'; -import { getObservabilityOnboardingState } from '../../lib/state'; +import { getObservabilityOnboardingFlow } from '../../lib/state'; const generateConfig = createObservabilityOnboardingServerRoute({ endpoint: 'GET /internal/observability_onboarding/elastic_agent/config', @@ -38,7 +38,7 @@ const generateConfig = createObservabilityOnboardingServerRoute({ ? [plugins.cloud?.setup?.elasticsearchUrl] : await getFallbackESUrl(esLegacyConfigService); - const savedState = await getObservabilityOnboardingState({ + const savedState = await getObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId: onboardingId, }); diff --git a/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts b/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts index 58aa5272a2a84..2776af522388f 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/flow/route.ts @@ -8,15 +8,15 @@ import Boom from '@hapi/boom'; import * as t from 'io-ts'; import { - getObservabilityOnboardingState, - saveObservabilityOnboardingState, + getObservabilityOnboardingFlow, + saveObservabilityOnboardingFlow, } from '../../lib/state'; -import { ObservabilityOnboardingState } from '../../saved_objects/observability_onboarding_status'; +import { ObservabilityOnboardingFlow } from '../../saved_objects/observability_onboarding_status'; import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; import { getHasLogs } from './get_has_logs'; const updateOnboardingFlowRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'PUT /internal/observability_onboarding/flow/{onboardingId}/save', + endpoint: 'PUT /internal/observability_onboarding/flow/{onboardingId}', options: { tags: [] }, params: t.type({ path: t.type({ @@ -37,14 +37,14 @@ const updateOnboardingFlowRoute = createObservabilityOnboardingServerRoute({ } = resources; const coreStart = await core.start(); const savedObjectsClient = coreStart.savedObjects.getScopedClient(request); - const { id } = await saveObservabilityOnboardingState({ + const { id } = await saveObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId: onboardingId, observabilityOnboardingState: { type: 'logFiles', state, progress: {}, - } as ObservabilityOnboardingState, + } as ObservabilityOnboardingFlow, }); return { onboardingId: id }; }, @@ -78,7 +78,7 @@ const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ coreStart.savedObjects.createInternalRepository(); const savedObservabilityOnboardingState = - await getObservabilityOnboardingState({ + await getObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId: id, }); @@ -95,7 +95,7 @@ const stepProgressUpdateRoute = createObservabilityOnboardingServerRoute({ ...observabilityOnboardingState } = savedObservabilityOnboardingState; - await saveObservabilityOnboardingState({ + await saveObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId, observabilityOnboardingState: { @@ -132,7 +132,7 @@ const getProgressRoute = createObservabilityOnboardingServerRoute({ const coreStart = await core.start(); const savedObjectsClient = coreStart.savedObjects.getScopedClient(request); const savedObservabilityOnboardingState = - await getObservabilityOnboardingState({ + await getObservabilityOnboardingFlow({ savedObjectsClient, savedObjectId: onboardingId, }); diff --git a/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts b/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts index df7d3b169eb5a..4afe189ed7279 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts @@ -9,9 +9,9 @@ import * as t from 'io-ts'; import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route'; import { getFallbackKibanaUrl } from '../../lib/get_fallback_urls'; import { hasLogMonitoringPrivileges } from './api_key/has_log_monitoring_privileges'; -import { saveObservabilityOnboardingState } from '../../lib/state'; +import { saveObservabilityOnboardingFlow } from '../../lib/state'; import { createShipperApiKey } from './api_key/create_shipper_api_key'; -import { ObservabilityOnboardingState } from '../../saved_objects/observability_onboarding_status'; +import { ObservabilityOnboardingFlow } from '../../saved_objects/observability_onboarding_status'; const logMonitoringPrivilegesRoute = createObservabilityOnboardingServerRoute({ endpoint: 'GET /internal/observability_onboarding/logs/setup/privileges', @@ -59,7 +59,7 @@ const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ }); const createFlowRoute = createObservabilityOnboardingServerRoute({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', options: { tags: [] }, params: t.type({ body: t.intersection([ @@ -93,11 +93,11 @@ const createFlowRoute = createObservabilityOnboardingServerRoute({ const savedObjectsClient = coreStart.savedObjects.getScopedClient(request); - const { id } = await saveObservabilityOnboardingState({ + const { id } = await saveObservabilityOnboardingFlow({ savedObjectsClient, observabilityOnboardingState: { type: 'logFiles', - state: state as ObservabilityOnboardingState['state'], + state: state as ObservabilityOnboardingFlow['state'], progress: {}, }, }); diff --git a/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts b/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts index 533c2cbee16b2..4c151e29a1b2a 100644 --- a/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts +++ b/x-pack/plugins/observability_onboarding/server/saved_objects/observability_onboarding_status.ts @@ -19,7 +19,7 @@ export interface LogFilesState { type ObservabilityOnboardingFlowState = LogFilesState | undefined; -export interface ObservabilityOnboardingState { +export interface ObservabilityOnboardingFlow { type: 'logFiles'; state: ObservabilityOnboardingFlowState; progress: Record< @@ -31,13 +31,13 @@ export interface ObservabilityOnboardingState { >; } -export interface SavedObservabilityOnboardingState - extends ObservabilityOnboardingState { +export interface SavedObservabilityOnboardingFlow + extends ObservabilityOnboardingFlow { id: string; updatedAt: number; } -export const observabilityOnboardingState: SavedObjectsType = { +export const observabilityOnboardingFlow: SavedObjectsType = { name: OBSERVABILITY_ONBOARDING_STATE_SAVED_OBJECT_TYPE, hidden: false, namespaceType: 'agnostic', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts index 38fc040c9c3b6..5b4f5041d1d11 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/elastic_agent/config.spec.ts @@ -33,7 +33,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', params: { body: { name: 'name', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts index 4efd52417bf86..a6076261d81c4 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/flow/progress/progress.spec.ts @@ -41,7 +41,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', params: { body: { name: 'name', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts index 4d0e969ebeda4..1de222e2d2368 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/create.spec.ts @@ -18,7 +18,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiWithoutPrivileges(state = {}) { return await observabilityOnboardingApiClient.readUser({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', params: { body: { name: 'name', @@ -30,7 +30,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { async function callApiWithPrivileges(state = {}) { return await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', params: { body: { name: 'name', diff --git a/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts b/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts index eb235f8fb523f..0826b3719837b 100644 --- a/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts +++ b/x-pack/test/observability_onboarding_api_integration/tests/logs/update_step_progress.spec.ts @@ -64,7 +64,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { beforeEach(async () => { const req = await observabilityOnboardingApiClient.logMonitoringUser({ - endpoint: 'POST /internal/observability_onboarding/logs/flow/create', + endpoint: 'POST /internal/observability_onboarding/logs/flow', params: { body: { name: 'name',