mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[APM] Add index.fast_refresh to .apm-custom-link
(#159674)
Closes: https://github.com/elastic/kibana/issues/155330 Adds `index.fast_refresh` to `.apm-custom-link` in order to ensure fast index refreshes on serverless (1 second periodic refreshes instead of 5 second which is the new default on serverless). This is pending on Elasticsearch adding support for `index.fast_refresh` (https://github.com/elastic/elasticsearch/pull/96660) --------- Co-authored-by: miriam.aparicio <miriam.aparicio@gmail.com> Co-authored-by: Miriam <31922082+MiriamAparicio@users.noreply.github.com>
This commit is contained in:
parent
86e7aca951
commit
efdc760a42
11 changed files with 45 additions and 73 deletions
|
@ -35,6 +35,7 @@ xpack.apm.featureFlags.infraUiAvailable: false
|
|||
xpack.apm.featureFlags.migrationToFleetAvailable: false
|
||||
xpack.apm.featureFlags.sourcemapApiAvailable: false
|
||||
xpack.apm.featureFlags.storageExplorerAvailable: false
|
||||
xpack.apm.featureFlags.fastRefreshAvailable: true
|
||||
|
||||
# Specify in telemetry the project type
|
||||
telemetry.labels.serverless: observability
|
||||
|
|
|
@ -186,6 +186,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
|
|||
'xpack.apm.latestAgentVersionsUrl (string)',
|
||||
'xpack.apm.featureFlags.agentConfigurationAvailable (any)',
|
||||
'xpack.apm.featureFlags.configurableIndicesAvailable (any)',
|
||||
'xpack.apm.featureFlags.fastRefreshAvailable (any)',
|
||||
'xpack.apm.featureFlags.infrastructureTabAvailable (any)',
|
||||
'xpack.apm.featureFlags.infraUiAvailable (any)',
|
||||
'xpack.apm.featureFlags.migrationToFleetAvailable (any)',
|
||||
|
|
|
@ -16,6 +16,7 @@ export enum ApmFeatureFlagName {
|
|||
MigrationToFleetAvailable = 'migrationToFleetAvailable',
|
||||
SourcemapApiAvailable = 'sourcemapApiAvailable',
|
||||
StorageExplorerAvailable = 'storageExplorerAvailable',
|
||||
FastRefreshAvailable = 'fastRefreshAvailable',
|
||||
}
|
||||
|
||||
const apmFeatureFlagMap = {
|
||||
|
@ -47,6 +48,10 @@ const apmFeatureFlagMap = {
|
|||
default: true,
|
||||
type: t.boolean,
|
||||
},
|
||||
[ApmFeatureFlagName.FastRefreshAvailable]: {
|
||||
default: false,
|
||||
type: t.boolean,
|
||||
},
|
||||
};
|
||||
|
||||
type ApmFeatureFlagMap = typeof apmFeatureFlagMap;
|
||||
|
|
|
@ -79,6 +79,7 @@ const mockConfig: ConfigSchema = {
|
|||
migrationToFleetAvailable: true,
|
||||
sourcemapApiAvailable: true,
|
||||
storageExplorerAvailable: true,
|
||||
fastRefreshAvailable: false,
|
||||
},
|
||||
serverless: { enabled: false },
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@ export interface ConfigSchema {
|
|||
migrationToFleetAvailable: boolean;
|
||||
sourcemapApiAvailable: boolean;
|
||||
storageExplorerAvailable: boolean;
|
||||
fastRefreshAvailable: boolean;
|
||||
};
|
||||
serverless: {
|
||||
enabled: boolean;
|
||||
|
|
|
@ -1,66 +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 { ESClient } from './get_es_client';
|
||||
|
||||
export async function createOrUpdateIndex({
|
||||
client,
|
||||
clear,
|
||||
indexName,
|
||||
template,
|
||||
}: {
|
||||
client: ESClient;
|
||||
clear: boolean;
|
||||
indexName: string;
|
||||
template: any;
|
||||
}) {
|
||||
if (clear) {
|
||||
try {
|
||||
await client.indices.delete({
|
||||
index: indexName,
|
||||
});
|
||||
} catch (err) {
|
||||
// 404 = index not found, totally okay
|
||||
if (err.body.status !== 404) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Some settings are non-updateable and need to be removed.
|
||||
const settings = { ...template.settings };
|
||||
delete settings?.index?.number_of_shards;
|
||||
delete settings?.index?.sort;
|
||||
|
||||
const indexExists = await client.indices.exists({
|
||||
index: indexName,
|
||||
});
|
||||
|
||||
if (!indexExists) {
|
||||
await client.indices.create({
|
||||
index: indexName,
|
||||
body: template,
|
||||
});
|
||||
} else {
|
||||
await client.indices.close({ index: indexName });
|
||||
await Promise.all([
|
||||
template.mappings
|
||||
? client.indices.putMapping({
|
||||
index: indexName,
|
||||
body: template.mappings,
|
||||
})
|
||||
: Promise.resolve(undefined as any),
|
||||
settings
|
||||
? client.indices.putSettings({
|
||||
index: indexName,
|
||||
body: settings,
|
||||
})
|
||||
: Promise.resolve(undefined as any),
|
||||
]);
|
||||
await client.indices.open({ index: indexName });
|
||||
}
|
||||
}
|
|
@ -23,6 +23,15 @@ const disabledOnServerless = schema.conditional(
|
|||
schema.oneOf([schema.literal(true)], { defaultValue: true })
|
||||
);
|
||||
|
||||
const enabledOnServerless = schema.conditional(
|
||||
schema.contextRef('serverless'),
|
||||
true,
|
||||
schema.boolean({
|
||||
defaultValue: true,
|
||||
}),
|
||||
schema.oneOf([schema.literal(false)], { defaultValue: false })
|
||||
);
|
||||
|
||||
// All options should be documented in the APM configuration settings: https://github.com/elastic/kibana/blob/main/docs/settings/apm-settings.asciidoc
|
||||
// and be included on cloud allow list unless there are specific reasons not to
|
||||
const configSchema = schema.object({
|
||||
|
@ -88,6 +97,7 @@ const configSchema = schema.object({
|
|||
migrationToFleetAvailable: disabledOnServerless,
|
||||
sourcemapApiAvailable: disabledOnServerless,
|
||||
storageExplorerAvailable: disabledOnServerless,
|
||||
fastRefreshAvailable: enabledOnServerless,
|
||||
}),
|
||||
serverless: schema.object({
|
||||
enabled: schema.conditional(
|
||||
|
|
|
@ -277,6 +277,7 @@ export class APMPlugin
|
|||
|
||||
const logger = this.logger;
|
||||
const client = core.elasticsearch.client.asInternalUser;
|
||||
const { featureFlags } = this.currentConfig;
|
||||
|
||||
// create .apm-agent-configuration index without blocking start lifecycle
|
||||
createApmAgentConfigurationIndex({ client, logger }).catch((e) => {
|
||||
|
@ -285,7 +286,7 @@ export class APMPlugin
|
|||
});
|
||||
|
||||
// create .apm-custom-link index without blocking start lifecycle
|
||||
createApmCustomLinkIndex({ client, logger }).catch((e) => {
|
||||
createApmCustomLinkIndex({ client, logger, featureFlags }).catch((e) => {
|
||||
logger.error('Failed to create .apm-custom-link index');
|
||||
logger.error(e);
|
||||
});
|
||||
|
|
|
@ -12,19 +12,29 @@ import {
|
|||
Mappings,
|
||||
} from '@kbn/observability-plugin/server';
|
||||
import { APM_CUSTOM_LINK_INDEX } from '../apm_indices/get_apm_indices';
|
||||
import { ApmFeatureFlags } from '../../../../common/apm_feature_flags';
|
||||
|
||||
export const createApmCustomLinkIndex = async ({
|
||||
client,
|
||||
logger,
|
||||
featureFlags,
|
||||
}: {
|
||||
client: ElasticsearchClient;
|
||||
logger: Logger;
|
||||
featureFlags: ApmFeatureFlags;
|
||||
}) => {
|
||||
return createOrUpdateIndex({
|
||||
index: APM_CUSTOM_LINK_INDEX,
|
||||
client,
|
||||
logger,
|
||||
mappings,
|
||||
settings: featureFlags.fastRefreshAvailable
|
||||
? {
|
||||
index: {
|
||||
fast_refresh: true,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ export function createAnnotationsClient(params: {
|
|||
const initIndex = () =>
|
||||
createOrUpdateIndex({
|
||||
index,
|
||||
mappings,
|
||||
client: esClient,
|
||||
logger,
|
||||
mappings,
|
||||
});
|
||||
|
||||
function ensureGoldLicense<T extends (...args: any[]) => any>(fn: T): T {
|
||||
|
|
|
@ -7,18 +7,23 @@
|
|||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import pRetry from 'p-retry';
|
||||
import { Logger, ElasticsearchClient } from '@kbn/core/server';
|
||||
import { merge } from 'lodash';
|
||||
|
||||
export type Mappings = Required<estypes.IndicesCreateRequest>['body']['mappings'] &
|
||||
Required<estypes.IndicesPutMappingRequest>['body'];
|
||||
|
||||
type IndexSettings = Required<estypes.IndicesPutSettingsRequest>['body']['settings'];
|
||||
|
||||
export async function createOrUpdateIndex({
|
||||
index,
|
||||
mappings,
|
||||
settings,
|
||||
client,
|
||||
logger,
|
||||
}: {
|
||||
index: string;
|
||||
mappings: Mappings;
|
||||
settings?: IndexSettings;
|
||||
client: ElasticsearchClient;
|
||||
logger: Logger;
|
||||
}) {
|
||||
|
@ -44,6 +49,7 @@ export async function createOrUpdateIndex({
|
|||
index,
|
||||
client,
|
||||
mappings,
|
||||
settings,
|
||||
});
|
||||
|
||||
if (!result.acknowledged) {
|
||||
|
@ -64,26 +70,28 @@ export async function createOrUpdateIndex({
|
|||
}
|
||||
}
|
||||
|
||||
function createNewIndex({
|
||||
async function createNewIndex({
|
||||
index,
|
||||
client,
|
||||
mappings,
|
||||
settings,
|
||||
}: {
|
||||
index: string;
|
||||
client: ElasticsearchClient;
|
||||
mappings: Required<estypes.IndicesCreateRequest>['body']['mappings'];
|
||||
settings: Required<estypes.IndicesPutSettingsRequest>['body']['settings'];
|
||||
}) {
|
||||
return client.indices.create({
|
||||
return await client.indices.create({
|
||||
index,
|
||||
body: {
|
||||
// auto_expand_replicas: Allows cluster to not have replicas for this index
|
||||
settings: { index: { auto_expand_replicas: '0-1' } },
|
||||
settings: merge({ index: { auto_expand_replicas: '0-1' } }, settings),
|
||||
mappings,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function updateExistingIndex({
|
||||
async function updateExistingIndex({
|
||||
index,
|
||||
client,
|
||||
mappings,
|
||||
|
@ -92,7 +100,7 @@ function updateExistingIndex({
|
|||
client: ElasticsearchClient;
|
||||
mappings: estypes.IndicesPutMappingRequest['body'];
|
||||
}) {
|
||||
return client.indices.putMapping({
|
||||
return await client.indices.putMapping({
|
||||
index,
|
||||
body: mappings,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue