From 2091870c5d1316053d62298b6a4889f3b275225f Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Fri, 22 Sep 2023 12:42:19 +0200 Subject: [PATCH] [Logs onboarding] Getting elastic-agent version from fleet (#166920) Closes https://github.com/elastic/kibana/issues/165657. In https://github.com/elastic/kibana/pull/166811 we exposed the value of latest agent version available, with this PR we are aiming to use that value as the `elastic-agent` version used in the installation script of onboarding flow. ### How to test 1. Enter [System logs onboarding](https://yngrdyn-deploy-kiban-pr166920.kb.us-west2.gcp.elastic-cloud.com/app/observabilityOnboarding/systemLogs) 2. Verify the elastic agent version in the installation script image 3. Go to the [console](https://yngrdyn-deploy-kiban-pr166920.kb.us-west2.gcp.elastic-cloud.com/app/dev_tools#/console) 4. Execute `GET /` 5. Verify Kibana version As you can see the kibana version is an snapshot but the elastic agent version proposed is the latest one released `8.10.1` allowing us to construct a valid download url like https://artifacts.elastic.co/downloads/beats/elastic-agent/8.10.1-linux-x86_64.tar.gz --- .../observability_onboarding/server/plugin.ts | 5 ++++- .../server/routes/logs/route.ts | 18 ++++++++++++++++-- .../observability_onboarding/server/types.ts | 6 ++++++ .../observability_onboarding/tsconfig.json | 3 ++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability_onboarding/server/plugin.ts b/x-pack/plugins/observability_onboarding/server/plugin.ts index 6ed20935398ab..44aac3df2e5a4 100644 --- a/x-pack/plugins/observability_onboarding/server/plugin.ts +++ b/x-pack/plugins/observability_onboarding/server/plugin.ts @@ -46,7 +46,10 @@ export class ObservabilityOnboardingPlugin } public setup( - core: CoreSetup, + core: CoreSetup< + ObservabilityOnboardingPluginStartDependencies, + ObservabilityOnboardingPluginStart + >, plugins: ObservabilityOnboardingPluginSetupDependencies ) { this.logger.debug('observability_onboarding: Setup'); 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 085f7cece0d8a..a11dcd918f3ed 100644 --- a/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts +++ b/x-pack/plugins/observability_onboarding/server/routes/logs/route.ts @@ -40,9 +40,23 @@ const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ scriptDownloadUrl: string; elasticAgentVersion: string; }> { - const { core, plugins } = resources; + const { core, plugins, kibanaVersion } = resources; const coreStart = await core.start(); + const fleetPluginStart = await plugins.fleet.start(); + const agentClient = fleetPluginStart.agentService.asInternalUser; + + // If undefined, we will follow fleet's strategy to select latest available version: + // for serverless we will use the latest published version, for statefull we will use + // current Kibana version. If false, irrespective of fleet flags and logic, we are + // explicitly deciding to not append the current version. + const includeCurrentVersion = kibanaVersion.endsWith('-SNAPSHOT') + ? false + : undefined; + + const elasticAgentVersion = + await agentClient.getLatestAgentAvailableVersion(includeCurrentVersion); + const kibanaUrl = core.setup.http.basePath.publicBaseUrl ?? // priority given to server.publicBaseUrl plugins.cloud?.setup?.kibanaUrl ?? // then cloud id @@ -53,7 +67,7 @@ const installShipperSetupRoute = createObservabilityOnboardingServerRoute({ return { apiEndpoint, scriptDownloadUrl, - elasticAgentVersion: '8.9.1', + elasticAgentVersion, }; }, }); diff --git a/x-pack/plugins/observability_onboarding/server/types.ts b/x-pack/plugins/observability_onboarding/server/types.ts index 93113a5043904..6823a0087c950 100644 --- a/x-pack/plugins/observability_onboarding/server/types.ts +++ b/x-pack/plugins/observability_onboarding/server/types.ts @@ -11,6 +11,10 @@ import { PluginSetup as DataPluginSetup, PluginStart as DataPluginStart, } from '@kbn/data-plugin/server'; +import { + FleetSetupContract, + FleetStartContract, +} from '@kbn/fleet-plugin/server'; import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server'; import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; @@ -19,6 +23,7 @@ export interface ObservabilityOnboardingPluginSetupDependencies { observability: ObservabilityPluginSetup; cloud: CloudSetup; usageCollection: UsageCollectionSetup; + fleet: FleetSetupContract; } export interface ObservabilityOnboardingPluginStartDependencies { @@ -26,6 +31,7 @@ export interface ObservabilityOnboardingPluginStartDependencies { observability: undefined; cloud: CloudStart; usageCollection: undefined; + fleet: FleetStartContract; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/x-pack/plugins/observability_onboarding/tsconfig.json b/x-pack/plugins/observability_onboarding/tsconfig.json index 4e1e2bacdf437..4730fbe256009 100644 --- a/x-pack/plugins/observability_onboarding/tsconfig.json +++ b/x-pack/plugins/observability_onboarding/tsconfig.json @@ -32,7 +32,8 @@ "@kbn/use-tracked-promise", "@kbn/custom-integrations", "@kbn/share-plugin", - "@kbn/deeplinks-observability" + "@kbn/deeplinks-observability", + "@kbn/fleet-plugin", ], "exclude": [ "target/**/*",