Skip to content

Commit

Permalink
[APM] Always uses the latest available apm package for the fleet migr…
Browse files Browse the repository at this point in the history
…ation UI (#128339)

* [APM] Always uses the latest available apm package for the fleet migration UI (#123477)

* fixes linting error

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
ogupte and kibanamachine authored Mar 28, 2022
1 parent b1f9201 commit a50e87c
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 290 deletions.
59 changes: 53 additions & 6 deletions x-pack/plugins/apm/common/fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,61 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import semverParse from 'semver/functions/parse';

export const POLICY_ELASTIC_AGENT_ON_CLOUD = 'policy-elastic-agent-on-cloud';

export const SUPPORTED_APM_PACKAGE_VERSION = '8.1.0';
export const INPUT_VAR_NAME_TO_SCHEMA_PATH: Record<string, string> = {
host: 'apm-server.host',
url: 'apm-server.url',
enable_rum: 'apm-server.rum.enabled',
default_service_environment: 'apm-server.default_service_environment',
rum_allow_origins: 'apm-server.rum.allow_origins',
rum_allow_headers: 'apm-server.rum.allow_headers',
rum_event_rate_limit: 'apm-server.rum.event_rate.limit',
rum_allow_service_names: 'apm-server.rum.allow_service_names',
rum_event_rate_lru_size: 'apm-server.rum.event_rate.lru_size',
rum_response_headers: 'apm-server.rum.response_headers',
rum_library_pattern: 'apm-server.rum.library_pattern',
rum_exclude_from_grouping: 'apm-server.rum.exclude_from_grouping',
max_event_bytes: 'apm-server.max_event_size',
capture_personal_data: 'apm-server.capture_personal_data',
max_header_bytes: 'apm-server.max_header_size',
idle_timeout: 'apm-server.idle_timeout',
read_timeout: 'apm-server.read_timeout',
shutdown_timeout: 'apm-server.shutdown_timeout',
write_timeout: 'apm-server.write_timeout',
max_connections: 'apm-server.max_connections',
response_headers: 'apm-server.response_headers',
expvar_enabled: 'apm-server.expvar.enabled',
tls_enabled: 'apm-server.ssl.enabled',
tls_certificate: 'apm-server.ssl.certificate',
tls_key: 'apm-server.ssl.key',
tls_supported_protocols: 'apm-server.ssl.supported_protocols',
tls_cipher_suites: 'apm-server.ssl.cipher_suites',
tls_curve_types: 'apm-server.ssl.curve_types',
secret_token: 'apm-server.auth.secret_token',
api_key_enabled: 'apm-server.auth.api_key.enabled',
api_key_limit: 'apm-server.auth.api_key.limit',
anonymous_enabled: 'apm-server.auth.anonymous.enabled',
anonymous_allow_agent: 'apm-server.auth.anonymous.allow_agent',
anonymous_allow_service: 'apm-server.auth.anonymous.allow_service',
anonymous_rate_limit_ip_limit:
'apm-server.auth.anonymous.rate_limit.ip_limit',
anonymous_rate_limit_event_limit:
'apm-server.auth.anonymous.rate_limit.event_limit',
tail_sampling_enabled: 'apm-server.sampling.tail.enabled',
tail_sampling_interval: 'apm-server.sampling.tail.interval',
tail_sampling_policies: 'apm-server.sampling.tail.policies',
};

export function isPrereleaseVersion(version: string) {
return semverParse(version)?.prerelease?.length ?? 0 > 0;
}
export const LEGACY_TO_CURRENT_SCHEMA_PATHS: Record<string, string> = {
'apm-server.rum.event_rate.limit':
'apm-server.auth.anonymous.rate_limit.event_limit',
'apm-server.rum.event_rate.lru_size':
'apm-server.auth.anonymous.rate_limit.ip_limit',
'apm-server.rum.allow_service_names':
'apm-server.auth.anonymous.allow_service',
'apm-server.secret_token': 'apm-server.auth.secret_token',
'apm-server.api_key.enabled': 'apm-server.auth.api_key.enabled',
};

export const ELASTIC_CLOUD_APM_AGENT_POLICY_ID = 'elastic-cloud-apm';
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function Schema() {
const cloudApmPackagePolicy = data.cloud_apm_package_policy;
const hasCloudApmPackagePolicy = !!cloudApmPackagePolicy;
const hasRequiredRole = !!data.has_required_role;
const latestApmPackageVersion = data.latest_apm_package_version;

function updateLocalStorage(newStatus: FETCH_STATUS) {
setApmDataStreamsMigrationStatus({
Expand Down Expand Up @@ -91,6 +92,7 @@ export function Schema() {
hasCloudAgentPolicy={hasCloudAgentPolicy}
hasRequiredRole={hasRequiredRole}
cloudApmPackagePolicy={cloudApmPackagePolicy}
latestApmPackageVersion={latestApmPackageVersion}
/>
{isSwitchActive && (
<ConfirmSwitchModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import semverLt from 'semver/functions/lt';
import { SUPPORTED_APM_PACKAGE_VERSION } from '../../../../../common/fleet';
import { PackagePolicy } from '../../../../../../fleet/common/types';
import { ElasticDocsLink } from '../../../shared/links/elastic_docs_link';
import rocketLaunchGraphic from './blog_rocket_720x420.png';
Expand All @@ -38,6 +37,7 @@ interface Props {
hasCloudAgentPolicy: boolean;
hasRequiredRole: boolean;
cloudApmPackagePolicy: PackagePolicy | undefined;
latestApmPackageVersion: string;
}
export function SchemaOverview({
onSwitch,
Expand All @@ -49,12 +49,13 @@ export function SchemaOverview({
hasCloudAgentPolicy,
hasRequiredRole,
cloudApmPackagePolicy,
latestApmPackageVersion,
}: Props) {
const isDisabled =
!cloudApmMigrationEnabled || !hasCloudAgentPolicy || !hasRequiredRole;
const packageVersion = cloudApmPackagePolicy?.package?.version;
const isUpgradeAvailable =
packageVersion && semverLt(packageVersion, SUPPORTED_APM_PACKAGE_VERSION);
packageVersion && semverLt(packageVersion, latestApmPackageVersion);

if (isLoading) {
return (
Expand Down
8 changes: 1 addition & 7 deletions x-pack/plugins/apm/public/tutorial/config_agent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { i18n } from '@kbn/i18n';
import { HttpStart } from 'kibana/public';
import React, { useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import {
isPrereleaseVersion,
SUPPORTED_APM_PACKAGE_VERSION,
} from '../../../common/fleet';
import { APIReturnType } from '../../services/rest/create_call_apm_api';
import { getCommands } from './commands/get_commands';
import { getPolicyOptions, PolicyOption } from './get_policy_options';
Expand Down Expand Up @@ -72,9 +68,7 @@ function getFleetLink({
}
: {
label: GET_STARTED_WITH_FLEET_LABEL,
href: isPrereleaseVersion(kibanaVersion)
? `${basePath}/app/integrations#/detail/apm/overview`
: `${basePath}/app/integrations#/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/overview`,
href: `${basePath}/app/integrations#/detail/apm/overview`,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import { i18n } from '@kbn/i18n';
import { HttpStart } from 'kibana/public';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import {
isPrereleaseVersion,
SUPPORTED_APM_PACKAGE_VERSION,
} from '../../../common/fleet';
import { APIReturnType } from '../../services/rest/create_call_apm_api';

interface Props {
Expand Down Expand Up @@ -78,9 +74,7 @@ function TutorialFleetInstructions({

const apmIntegrationHref = shouldLinkToMigration
? `${basePath}/app/apm/settings/schema`
: isPrereleaseVersion(kibanaVersion)
? `${basePath}/app/integrations#/detail/apm/overview`
: `${basePath}/app/integrations/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/overview`;
: `${basePath}/app/integrations#/detail/apm/overview`;

if (isLoading) {
return (
Expand All @@ -96,7 +90,7 @@ function TutorialFleetInstructions({
<EuiButton
iconType="gear"
fill
href={`${basePath}/app/integrations/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/policies`}
href={`${basePath}/app/integrations/detail/apm/policies`}
>
{i18n.translate(
'xpack.apm.tutorial.apmServer.fleet.manageApmIntegration.button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ElasticsearchClient,
SavedObjectsClientContract,
Logger,
KibanaRequest,
} from 'kibana/server';
import { PackagePolicy } from '../../../../fleet/common';
import {
Expand All @@ -30,15 +31,15 @@ export async function createCloudApmPackgePolicy({
esClient,
logger,
setup,
kibanaVersion,
request,
}: {
cloudPluginSetup: APMPluginSetupDependencies['cloud'];
fleetPluginStart: NonNullable<APMPluginStartDependencies['fleet']>;
savedObjectsClient: SavedObjectsClientContract;
esClient: ElasticsearchClient;
logger: Logger;
setup: Setup;
kibanaVersion: string;
request: KibanaRequest;
}): Promise<PackagePolicy> {
const { attributes } = await savedObjectsClient.get(
APM_SERVER_SCHEMA_SAVED_OBJECT_TYPE,
Expand All @@ -52,7 +53,7 @@ export async function createCloudApmPackgePolicy({
apmServerSchema,
cloudPluginSetup,
fleetPluginStart,
kibanaVersion,
request,
});
const mergedAPMPackagePolicy = await mergePackagePolicyWithApm({
setup,
Expand Down
Loading

0 comments on commit a50e87c

Please sign in to comment.