Skip to content

Commit

Permalink
[Logs onboarding] Getting elastic-agent version from fleet (elastic#1…
Browse files Browse the repository at this point in the history
…66920)

Closes elastic#165657.

In elastic#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
<img width="870" alt="image"
src="https://github.com/elastic/kibana/assets/1313018/c2d99244-6e5a-4d2e-a3fd-eea6041636d2">

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
  • Loading branch information
yngrdyn authored Sep 22, 2023
1 parent f5ab497 commit 2091870
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/observability_onboarding/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export class ObservabilityOnboardingPlugin
}

public setup(
core: CoreSetup<ObservabilityOnboardingPluginStartDependencies>,
core: CoreSetup<
ObservabilityOnboardingPluginStartDependencies,
ObservabilityOnboardingPluginStart
>,
plugins: ObservabilityOnboardingPluginSetupDependencies
) {
this.logger.debug('observability_onboarding: Setup');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,7 +67,7 @@ const installShipperSetupRoute = createObservabilityOnboardingServerRoute({
return {
apiEndpoint,
scriptDownloadUrl,
elasticAgentVersion: '8.9.1',
elasticAgentVersion,
};
},
});
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/observability_onboarding/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -19,13 +23,15 @@ export interface ObservabilityOnboardingPluginSetupDependencies {
observability: ObservabilityPluginSetup;
cloud: CloudSetup;
usageCollection: UsageCollectionSetup;
fleet: FleetSetupContract;
}

export interface ObservabilityOnboardingPluginStartDependencies {
data: DataPluginStart;
observability: undefined;
cloud: CloudStart;
usageCollection: undefined;
fleet: FleetStartContract;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/observability_onboarding/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand Down

0 comments on commit 2091870

Please sign in to comment.