[APM] Deprecate old routes, move remaining bits to apm-sources-access (#216507)

## Summary

Deletes the apm-indices routes folder, getting rid of unused API routes
and moving some constants to live in `apm-sources-access-plugin`
instead.

Closes #214570

## How to test

* Go to Observability -> Applications -> Settings -> Indices
* Make sure everything loads/saves correctly when editing indices

The CI should build and pass all tests without errors relating to
missing APM API routes.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Gonçalo Rica Pais da Silva 2025-04-07 16:37:49 +02:00 committed by GitHub
parent 9f932a099b
commit 8d4b875b3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 50 additions and 181 deletions

View file

@ -18,6 +18,12 @@ const plugin = async (initContext: PluginInitializerContext) => {
return new ApmSourcesAccessPlugin(initContext);
};
export {
APM_AGENT_CONFIGURATION_INDEX,
APM_CUSTOM_LINK_INDEX,
APM_SOURCE_MAP_INDEX,
} from './constants';
export type {
APIEndpoint,
APIReturnType,

View file

@ -11,7 +11,10 @@ import { Client, HttpConnection } from '@elastic/elasticsearch';
import fs from 'fs/promises';
import type { AxiosRequestConfig } from 'axios';
import axios from 'axios';
import type { APMIndices } from '@kbn/apm-sources-access-plugin/server';
import type {
APMIndices,
APIReturnType as SourcesAPIReturnType,
} from '@kbn/apm-sources-access-plugin/server';
import type { APIReturnType } from '../../public/services/rest/create_call_apm_api';
import { getDiagnosticsBundle } from '../../server/routes/diagnostics/get_diagnostics_bundle';
@ -87,23 +90,15 @@ async function saveReportToFile(combinedReport: DiagnosticsBundle) {
console.log(`Diagnostics report written to "${filename}"`);
}
async function getApmIndices(kbnClientOpts: AxiosRequestConfig) {
interface Response {
apmIndexSettings: Array<{
configurationName: string;
defaultValue: string;
savedValue?: string;
}>;
}
async function getApmIndices(kbnClientOpts: AxiosRequestConfig): Promise<APMIndices> {
type Response = SourcesAPIReturnType<'GET /internal/apm-sources/settings/apm-indices'>;
const res = await axios.get<Response>('/internal/apm/settings/apm-index-settings', kbnClientOpts);
const res = await axios.get<Response>(
'/internal/apm-sources/settings/apm-indices',
kbnClientOpts
);
return Object.fromEntries(
res.data.apmIndexSettings.map(({ configurationName, defaultValue, savedValue }) => [
configurationName,
savedValue ?? defaultValue,
])
) as APMIndices;
return res.data;
}
async function getFleetPackageInfo(kbnClientOpts: AxiosRequestConfig) {

View file

@ -10,7 +10,10 @@ import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { createHash } from 'crypto';
import { flatten, merge, pickBy, sortBy, sum, uniq, without } from 'lodash';
import type { SavedObjectsClient } from '@kbn/core/server';
import type { APMIndices } from '@kbn/apm-sources-access-plugin/server';
import {
type APMIndices,
APM_AGENT_CONFIGURATION_INDEX,
} from '@kbn/apm-sources-access-plugin/server';
import {
AGENT_NAMES,
OPEN_TELEMETRY_AGENT_NAMES,
@ -72,7 +75,6 @@ import type {
MetricRollupIntervals,
MetricSupportingRollUp,
} from '../types';
import { APM_AGENT_CONFIGURATION_INDEX } from '../../../routes/settings/apm_indices/apm_system_index_constants';
import type { IndicesStatsResponse, TelemetryClient } from '../telemetry_client';
import { RollupInterval } from '../../../../common/rollup';
import type { SavedApmCustomDashboard } from '../../../../common/custom_dashboards';

View file

@ -34,7 +34,6 @@ import { serviceGroupRouteRepository } from '../service_groups/route';
import { serviceMapRouteRepository } from '../service_map/route';
import { agentConfigurationRouteRepository } from '../settings/agent_configuration/route';
import { anomalyDetectionRouteRepository } from '../settings/anomaly_detection/route';
import { apmIndicesRouteRepository } from '../settings/apm_indices/route';
import { customLinkRouteRepository } from '../settings/custom_link/route';
import { labsRouteRepository } from '../settings/labs/route';
import { sourceMapsRouteRepository } from '../source_maps/route';
@ -64,7 +63,6 @@ function getTypedGlobalApmServerRouteRepository() {
...alertsChartPreviewRouteRepository,
...agentConfigurationRouteRepository,
...anomalyDetectionRouteRepository,
...apmIndicesRouteRepository,
...customLinkRouteRepository,
...sourceMapsRouteRepository,
...apmFleetRouteRepository,

View file

@ -9,7 +9,7 @@ import type { CoreStart, Logger } from '@kbn/core/server';
import {
APM_AGENT_CONFIGURATION_INDEX,
APM_SOURCE_MAP_INDEX,
} from '../../settings/apm_indices/apm_system_index_constants';
} from '@kbn/apm-sources-access-plugin/server';
const apiKeyMetadata = {
application: 'apm',

View file

@ -8,7 +8,7 @@
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import type { Mappings } from '@kbn/observability-plugin/server';
import { createOrUpdateIndex } from '@kbn/observability-plugin/server';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
export async function createApmAgentConfigurationIndex({
client,

View file

@ -6,6 +6,7 @@
*/
import hash from 'object-hash';
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type {
AgentConfiguration,
AgentConfigurationIntake,
@ -14,7 +15,6 @@ import type {
APMIndexDocumentParams,
APMInternalESClient,
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
export function createOrUpdateConfiguration({
configurationId,

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
export async function deleteConfiguration({
configurationId,

View file

@ -6,11 +6,11 @@
*/
import type { SearchHit } from '@kbn/es-types';
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import type { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
import { SERVICE_ENVIRONMENT, SERVICE_NAME } from '../../../../common/es_fields/apm';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
import { convertConfigSettingsToString } from './convert_settings_to_string';
import { getAgentConfigEtagMetrics } from './get_agent_config_etag_metrics';

View file

@ -5,10 +5,10 @@
* 2.0.
*/
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import { SERVICE_NAME, SERVICE_ENVIRONMENT } from '../../../../../common/es_fields/apm';
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/all_option';
import type { APMInternalESClient } from '../../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../../apm_indices/apm_system_index_constants';
export async function getExistingEnvironmentsForService({
serviceName,

View file

@ -6,12 +6,12 @@
*/
import type { APMIndices } from '@kbn/apm-sources-access-plugin/server';
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import type { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
import { convertConfigSettingsToString } from './convert_settings_to_string';
import { getAgentConfigEtagMetrics } from './get_agent_config_etag_metrics';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
export async function listConfigurations({
internalESClient,

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
// We're not wrapping this function with a span as it is not blocking the request
export async function markAppliedByAgent({

View file

@ -6,11 +6,11 @@
*/
import type { SearchHit } from '@kbn/es-types';
import { APM_AGENT_CONFIGURATION_INDEX } from '@kbn/apm-sources-access-plugin/server';
import { SERVICE_NAME, SERVICE_ENVIRONMENT } from '../../../../common/es_fields/apm';
import type { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types';
import { convertConfigSettingsToString } from './convert_settings_to_string';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_AGENT_CONFIGURATION_INDEX } from '../apm_indices/apm_system_index_constants';
export async function searchConfigurations({
service,

View file

@ -1,34 +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 { getApmIndicesSavedObject } from '@kbn/apm-sources-access-plugin/server/saved_objects/apm_indices';
import type { APMRouteHandlerResources } from '../../apm_routes/register_apm_server_routes';
export type ApmIndexSettingsResponse = Array<{
configurationName: 'transaction' | 'span' | 'error' | 'metric' | 'onboarding' | 'sourcemap';
defaultValue: string; // value defined in kibana[.dev].yml
savedValue: string | undefined;
}>;
export async function getApmIndexSettings(
resources: APMRouteHandlerResources
): Promise<ApmIndexSettingsResponse> {
const { apmIndicesFromConfigFile } = resources.plugins.apmDataAccess.setup;
const soClient = (await resources.context.core).savedObjects.client;
const apmIndicesSavedObject = await getApmIndicesSavedObject(soClient);
const apmIndicesKeys = Object.keys(apmIndicesFromConfigFile) as Array<
keyof typeof apmIndicesFromConfigFile
>;
return apmIndicesKeys.map((configurationName) => ({
configurationName,
defaultValue: apmIndicesFromConfigFile[configurationName], // value defined in kibana[.dev].yml
savedValue: apmIndicesSavedObject?.[configurationName], // value saved via Saved Objects service
}));
}

View file

@ -1,83 +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 * as t from 'io-ts';
import type { SavedObject } from '@kbn/core/server';
import type { APMIndices } from '@kbn/apm-sources-access-plugin/server';
import { saveApmIndices } from '@kbn/apm-sources-access-plugin/server/saved_objects/apm_indices';
import { createApmServerRoute } from '../../apm_routes/create_apm_server_route';
import type { ApmIndexSettingsResponse } from './get_apm_indices';
import { getApmIndexSettings } from './get_apm_indices';
// TODO: Deprecate and remove these API routes. https://github.com/elastic/kibana/issues/214570
// get list of apm indices and values
const apmIndexSettingsRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/settings/apm-index-settings',
security: { authz: { requiredPrivileges: ['apm'] } },
handler: async (
resources
): Promise<{
apmIndexSettings: ApmIndexSettingsResponse;
}> => {
const apmIndexSettings = await getApmIndexSettings(resources);
return { apmIndexSettings };
},
});
// TODO: Deprecate and remove these API routes. https://github.com/elastic/kibana/issues/214570
// get apm indices configuration object
const apmIndicesRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/settings/apm-indices',
security: { authz: { requiredPrivileges: ['apm'] } },
handler: async (resources): Promise<APMIndices> => {
return await resources.getApmIndices();
},
});
type SaveApmIndicesBodySchema = {
[Property in keyof APMIndices]: t.StringC;
};
// TODO: Deprecate and remove these API routes. https://github.com/elastic/kibana/issues/214570
// save ui indices
const saveApmIndicesRoute = createApmServerRoute({
endpoint: 'POST /internal/apm/settings/apm-indices/save',
security: {
authz: {
requiredPrivileges: ['apm', 'apm_settings_write'],
},
},
params: t.type({
body: t.partial({
error: t.string,
onboarding: t.string,
span: t.string,
transaction: t.string,
metric: t.string,
// Keeping this one here for backward compatibility
sourcemap: t.string,
} as SaveApmIndicesBodySchema),
}),
handler: async (resources): Promise<SavedObject<{}>> => {
const { params, context } = resources;
const { body } = params;
const savedObjectsClient = (await context.core).savedObjects.client;
const indices = { ...body };
if (indices.sourcemap) {
// Delete this as we stopped supporting it from 8.7.
delete indices.sourcemap;
}
return await saveApmIndices(savedObjectsClient, indices);
},
});
export const apmIndicesRouteRepository = {
...apmIndexSettingsRoute,
...apmIndicesRoute,
...saveApmIndicesRoute,
};

View file

@ -9,7 +9,7 @@ import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import type { estypes } from '@elastic/elasticsearch';
import type { Mappings } from '@kbn/observability-plugin/server';
import { createOrUpdateIndex } from '@kbn/observability-plugin/server';
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
import { APM_CUSTOM_LINK_INDEX } from '@kbn/apm-sources-access-plugin/server';
export const createApmCustomLinkIndex = async ({
client,

View file

@ -5,13 +5,13 @@
* 2.0.
*/
import { APM_CUSTOM_LINK_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { CustomLink, CustomLinkES } from '../../../../common/custom_link/custom_link_types';
import { toESFormat } from './helper';
import type {
APMIndexDocumentParams,
APMInternalESClient,
} from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
export function createOrUpdateCustomLink({
customLinkId,

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { APM_CUSTOM_LINK_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
export function deleteCustomLink({
customLinkId,

View file

@ -7,11 +7,11 @@
import type * as t from 'io-ts';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { APM_CUSTOM_LINK_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { CustomLink, CustomLinkES } from '../../../../common/custom_link/custom_link_types';
import { fromESFormat } from './helper';
import type { filterOptionsRt } from './custom_link_types';
import type { APMInternalESClient } from '../../../lib/helpers/create_es_client/create_internal_es_client';
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/apm_system_index_constants';
export async function listCustomLinks({
internalESClient,

View file

@ -7,8 +7,8 @@
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { Artifact } from '@kbn/fleet-plugin/server';
import { APM_SOURCE_MAP_INDEX } from '@kbn/apm-sources-access-plugin/server';
import { getUnzippedArtifactBody } from '../fleet/source_maps';
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
import type { ApmSourceMap } from './create_apm_source_map_index_template';
import { getEncodedContent, getSourceMapId } from './sourcemap_utils';

View file

@ -7,7 +7,7 @@
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { Logger } from '@kbn/core/server';
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
import { APM_SOURCE_MAP_INDEX } from '@kbn/apm-sources-access-plugin/server';
import type { ApmSourceMap } from './create_apm_source_map_index_template';
import type { SourceMap } from './route';
import { getEncodedContent, getSourceMapId } from './sourcemap_utils';

View file

@ -8,7 +8,7 @@
import type { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import { createOrUpdateIndexTemplate } from '@kbn/observability-plugin/server';
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
import { APM_SOURCE_MAP_INDEX } from '@kbn/apm-sources-access-plugin/server';
const indexTemplate: IndicesPutIndexTemplateRequest = {
name: 'apm-source-map',

View file

@ -6,7 +6,7 @@
*/
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
import { APM_SOURCE_MAP_INDEX } from '@kbn/apm-sources-access-plugin/server';
export async function deleteApmSourceMap({
internalESClient,

View file

@ -10,9 +10,9 @@ import type { FleetStartContract } from '@kbn/fleet-plugin/server';
import type { ArtifactsClientInterface } from '@kbn/fleet-plugin/server/services';
import type { TaskManagerSetupContract } from '@kbn/task-manager-plugin/server';
import type { CoreStart, Logger } from '@kbn/core/server';
import { APM_SOURCE_MAP_INDEX } from '@kbn/apm-sources-access-plugin/server';
import { getApmArtifactClient } from '../fleet/source_maps';
import { bulkCreateApmSourceMaps } from './bulk_create_apm_source_maps';
import { APM_SOURCE_MAP_INDEX } from '../settings/apm_indices/apm_system_index_constants';
import type { ApmSourceMap } from './create_apm_source_map_index_template';
import type { APMPluginStartDependencies } from '../../types';
import { createApmSourceMapIndexTemplate } from './create_apm_source_map_index_template';

View file

@ -40,7 +40,8 @@
"uiActions",
"unifiedSearch",
"usageCollection",
"fieldsMetadata"
"fieldsMetadata",
"apmSourcesAccess"
],
"optionalPlugins": [
"cloud",
@ -60,4 +61,4 @@
"unifiedSearch"
]
}
}
}

View file

@ -18,35 +18,16 @@ export interface UseFetchApmIndex {
isError: boolean;
}
interface ApiResponse {
apmIndexSettings: Array<{
configurationName: string;
defaultValue: string;
savedValue?: string;
}>;
}
export function useFetchApmIndex(): UseFetchApmIndex {
const { http } = useKibana().services;
const { apmSourcesAccess } = useKibana().services;
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({
queryKey: ['fetchApmIndices'],
queryFn: async ({ signal }) => {
try {
const response = await http.get<ApiResponse>('/internal/apm/settings/apm-index-settings', {
signal,
});
const response = await apmSourcesAccess.getApmIndices({ signal });
const metricSettings = response.apmIndexSettings.find(
(settings) => settings.configurationName === 'metric'
);
let index = '';
if (!!metricSettings) {
index = metricSettings.savedValue ?? metricSettings.defaultValue;
}
return index;
return response.metric ?? '';
} catch (error) {
// ignore error
}

View file

@ -50,6 +50,7 @@ import type {
} from '@kbn/usage-collection-plugin/public';
import { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin-types-public';
import { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import { ApmSourceAccessPluginStart } from '@kbn/apm-sources-access-plugin/public';
import type { SLORouteRepository } from '../server/routes/get_slo_server_route_repository';
import { SLOPlugin } from './plugin';
@ -101,6 +102,7 @@ export interface SLOPublicPluginsStart {
usageCollection: UsageCollectionStart;
security?: SecurityPluginStart;
fieldsMetadata: FieldsMetadataPublicStart;
apmSourcesAccess: ApmSourceAccessPluginStart;
}
export type SLOPublicSetup = ReturnType<SLOPlugin['setup']>;

View file

@ -105,6 +105,7 @@
"@kbn/security-plugin",
"@kbn/response-ops-rule-form",
"@kbn/server-route-repository-utils",
"@kbn/fields-metadata-plugin"
"@kbn/fields-metadata-plugin",
"@kbn/apm-sources-access-plugin"
]
}

View file

@ -20,7 +20,7 @@ import { createEsClientForFtrConfig } from '@kbn/test';
import {
APM_AGENT_CONFIGURATION_INDEX,
APM_SOURCE_MAP_INDEX,
} from '@kbn/apm-plugin/server/routes/settings/apm_indices/apm_system_index_constants';
} from '@kbn/apm-sources-access-plugin/server';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import {
createAgentPolicy,