Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Migrate fleet sourcemaps to APM managed index #147208

Merged
merged 27 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
538f89b
[APM] Add sourcemap index
sorenlouv Dec 7, 2022
b67460f
Fix test
sorenlouv Dec 7, 2022
4050578
Remove option `xpack.apm.indices.sourcemap`
sorenlouv Dec 7, 2022
203dd76
Add migration
sorenlouv Dec 7, 2022
b78f4c2
Fix jest
sorenlouv Dec 7, 2022
9c3528e
Remove fleet related fields from source map index
sorenlouv Dec 8, 2022
b7d43ab
Refactoring: remove static indices from config
sorenlouv Dec 9, 2022
99d4e41
Fix telemetry lint
sorenlouv Dec 9, 2022
0ba0f91
Renaming
sorenlouv Dec 9, 2022
2e1038f
Remove APM from fleet workaround
sorenlouv Dec 9, 2022
255873c
Update translations
sorenlouv Dec 9, 2022
612d986
Recursively paginate artifacts
sorenlouv Dec 9, 2022
70740cf
Minor rewording
sorenlouv Dec 9, 2022
b642b08
Fix search bug
sorenlouv Dec 9, 2022
0e76e26
Update x-pack/plugins/apm/server/routes/source_maps/bulk_create_apm_s…
sorenlouv Dec 12, 2022
637121b
Use task manager to run source map migration
sorenlouv Dec 12, 2022
d0405d4
Use index templates
sorenlouv Dec 13, 2022
9e7d786
Add api test for migration
sorenlouv Dec 13, 2022
b9b9cba
Fix issues
sorenlouv Dec 13, 2022
aa53e1d
fix test
sorenlouv Dec 13, 2022
16e761e
Fix e2e
sorenlouv Dec 14, 2022
4fa0cf9
Don’t swallow errors
sorenlouv Dec 14, 2022
45f55a4
Changed to 1h
sorenlouv Dec 15, 2022
f441cc4
Remove uncommented code
sorenlouv Dec 15, 2022
1a53580
Add abort logic
sorenlouv Dec 15, 2022
325d4a1
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Dec 15, 2022
87a95f0
Make taskState optional
sorenlouv Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('No data screen', () => {
before(() => {
// Change indices
setApmIndices({
sourcemap: 'foo-*',
error: 'foo-*',
onboarding: 'foo-*',
span: 'foo-*',
Expand All @@ -37,7 +36,6 @@ describe('No data screen', () => {
after(() => {
// reset to default indices
setApmIndices({
sourcemap: '',
error: '',
onboarding: '',
span: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ import {
} from '../../../../services/rest/create_call_apm_api';

const APM_INDEX_LABELS = [
{
configurationName: 'sourcemap',
label: i18n.translate(
'xpack.apm.settings.apmIndices.sourcemapIndicesLabel',
{ defaultMessage: 'Sourcemap Indices' }
),
},
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
{
configurationName: 'error',
label: i18n.translate('xpack.apm.settings.apmIndices.errorIndicesLabel', {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/scripts/shared/read_kibana_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const readKibanaConfig = () => {
'xpack.apm.indices.error': 'logs-apm*,apm-*',
'xpack.apm.indices.span': 'traces-apm*,apm-*',
'xpack.apm.indices.onboarding': 'apm-*',
'xpack.apm.indices.sourcemap': 'apm-*',
'elasticsearch.hosts': 'http://localhost:9200',
...loadedKibanaConfig,
...cliEsCredentials,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const configSchema = schema.object({
span: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
error: schema.string({ defaultValue: 'logs-apm*,apm-*' }),
metric: schema.string({ defaultValue: 'metrics-apm*,apm-*' }),
sourcemap: schema.string({ defaultValue: 'apm-*' }),
onboarding: schema.string({ defaultValue: 'apm-*' }),
}),
forceSyntheticSource: schema.boolean({ defaultValue: false }),
Expand All @@ -61,10 +60,12 @@ const configSchema = schema.object({
export const config: PluginConfigDescriptor<APMConfig> = {
deprecations: ({
rename,
unused,
renameFromRoot,
deprecateFromRoot,
unusedFromRoot,
}) => [
unused('indices.sourcemap', { level: 'warning' }),
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
rename('autocreateApmIndexPattern', 'autoCreateApmDataView', {
level: 'warning',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ describe('data telemetry collection tasks', () => {
'1d': 1,
all: 1,
},
sourcemap: {
'1d': 1,
all: 1,
},
span: {
'1d': 1,
all: 1,
Expand All @@ -321,9 +317,6 @@ describe('data telemetry collection tasks', () => {
onboarding: {
ms: 0,
},
sourcemap: {
ms: 0,
},
span: {
ms: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
import { Span } from '../../../../typings/es_schemas/ui/span';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
import { APMTelemetry, APMPerService, APMDataTelemetry } from '../types';
import { ApmIndicesConfig } from '../../../routes/settings/apm_indices/get_apm_indices';
import {
ApmIndicesConfig,
APM_AGENT_CONFIGURATION_INDEX,
} from '../../../routes/settings/apm_indices/get_apm_indices';
import { TelemetryClient } from '../telemetry_client';

type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;
Expand Down Expand Up @@ -464,7 +467,6 @@ export const tasks: TelemetryTask[] = [
span: indices.span,
transaction: indices.transaction,
onboarding: indices.onboarding,
sourcemap: indices.sourcemap,
};

type ProcessorEvent = keyof typeof indicesByProcessorEvent;
Expand Down Expand Up @@ -558,7 +560,7 @@ export const tasks: TelemetryTask[] = [
name: 'agent_configuration',
executor: async ({ indices, telemetryClient }) => {
const agentConfigurationCount = await telemetryClient.search({
index: indices.apmAgentConfigurationIndex,
index: APM_AGENT_CONFIGURATION_INDEX,
body: {
size: 0,
timeout,
Expand Down Expand Up @@ -1033,11 +1035,10 @@ export const tasks: TelemetryTask[] = [
executor: async ({ indices, telemetryClient }) => {
const response = await telemetryClient.indicesStats({
index: [
indices.apmAgentConfigurationIndex,
APM_AGENT_CONFIGURATION_INDEX,
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
indices.error,
indices.metric,
indices.onboarding,
indices.sourcemap,
indices.span,
indices.transaction,
],
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export const apmSchema: MakeSchemaFrom<APMUsage> = {
span: timeframeMapSchema,
error: timeframeMapSchema,
metric: timeframeMapSchema,
sourcemap: timeframeMapSchema,
onboarding: timeframeMapSchema,
agent_configuration: timeframeMapAllSchema,
max_transaction_groups_per_service: timeframeMapSchema,
Expand Down Expand Up @@ -221,7 +220,6 @@ export const apmSchema: MakeSchemaFrom<APMUsage> = {
transaction: { ms: long },
error: { ms: long },
metric: { ms: long },
sourcemap: { ms: long },
onboarding: { ms: long },
},
integrations: { ml: { all_jobs_count: long } },
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/apm/server/lib/apm_telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export interface APMUsage {
span: TimeframeMap;
error: TimeframeMap;
metric: TimeframeMap;
sourcemap: TimeframeMap;
onboarding: TimeframeMap;
agent_configuration: TimeframeMapAll;
max_transaction_groups_per_service: TimeframeMap;
Expand All @@ -125,7 +124,7 @@ export interface APMUsage {
};
};
retainment: Record<
'span' | 'transaction' | 'error' | 'metric' | 'sourcemap' | 'onboarding',
'span' | 'transaction' | 'error' | 'metric' | 'onboarding',
{ ms: number }
>;
integrations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('unpackProcessorEvents', () => {
error: 'my-apm-*-error-*',
span: 'my-apm-*-span-*',
onboarding: 'my-apm-*-onboarding-*',
sourcemap: 'my-apm-*-sourcemap-*',
} as ApmIndicesConfig;

res = unpackProcessorEvents(request, indices);
Expand Down
59 changes: 45 additions & 14 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import {
} from '../common/es_fields/apm';
import { tutorialProvider } from './tutorial';
import { migrateLegacyAPMIndicesToSpaceAware } from './saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware';
import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source_map_migration';
import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm_source_map_index_template';

export class APMPlugin
implements
Expand Down Expand Up @@ -110,6 +112,9 @@ export class APMPlugin
const getCoreStart = () =>
core.getStartServices().then(([coreStart]) => coreStart);

const getPluginStart = () =>
core.getStartServices().then(([coreStart, pluginStart]) => pluginStart);

const { ruleDataService } = plugins.ruleRegistry;
const ruleDataClient = ruleDataService.initializeIndex({
feature: APM_SERVER_FEATURE_ID,
Expand Down Expand Up @@ -220,6 +225,21 @@ export class APMPlugin
kibanaVersion: this.initContext.env.packageInfo.version,
});

const fleetStartPromise = resourcePlugins.fleet?.start();
const taskManager = plugins.taskManager;

// create source map index and run migrations
scheduleSourceMapMigration({
coreStartPromise: getCoreStart(),
pluginStartPromise: getPluginStart(),
fleetStartPromise,
taskManager,
logger: this.logger,
}).catch((e) => {
this.logger?.error('Failed to schedule APM source map migration');
this.logger?.error(e);
});

return {
config$,
getApmIndices: boundGetApmIndices,
Expand Down Expand Up @@ -254,28 +274,39 @@ export class APMPlugin
};
}

public start(core: CoreStart) {
public start(core: CoreStart, plugins: APMPluginStartDependencies) {
if (this.currentConfig == null || this.logger == null) {
throw new Error('APMPlugin needs to be setup before calling start()');
}

// create agent configuration index without blocking start lifecycle
createApmAgentConfigurationIndex({
client: core.elasticsearch.client.asInternalUser,
config: this.currentConfig,
logger: this.logger,
const logger = this.logger;
const client = core.elasticsearch.client.asInternalUser;

// create .apm-agent-configuration index without blocking start lifecycle
createApmAgentConfigurationIndex({ client, logger }).catch((e) => {
logger.error('Failed to create .apm-agent-configuration index');
logger.error(e);
});
// create custom action index without blocking start lifecycle
createApmCustomLinkIndex({
client: core.elasticsearch.client.asInternalUser,
config: this.currentConfig,
logger: this.logger,

// create .apm-custom-link index without blocking start lifecycle
createApmCustomLinkIndex({ client, logger }).catch((e) => {
logger.error('Failed to create .apm-custom-link index');
logger.error(e);
});

migrateLegacyAPMIndicesToSpaceAware({
coreStart: core,
logger: this.logger,
// create .apm-source-map index without blocking start lifecycle
createApmSourceMapIndexTemplate({ client, logger }).catch((e) => {
logger.error('Failed to create apm-source-map index template');
logger.error(e);
});

// TODO: remove in 9.0
migrateLegacyAPMIndicesToSpaceAware({ coreStart: core, logger }).catch(
(e) => {
logger.error('Failed to run migration making APM indices space aware');
logger.error(e);
}
);
}

public stop() {}
Expand Down
Loading