[APM] Fix timeout in APM setup (#58727)
* [APM] Fix timeout in APM setup * Update plugin.ts
This commit is contained in:
parent
2a03dffdad
commit
d474ccf244
|
@ -38,4 +38,4 @@ export function plugin(initializerContext: PluginInitializerContext) {
|
||||||
|
|
||||||
export type APMOSSConfig = TypeOf<typeof config.schema>;
|
export type APMOSSConfig = TypeOf<typeof config.schema>;
|
||||||
|
|
||||||
export { APMOSSPlugin as Plugin };
|
export { APMOSSPluginSetup } from './plugin';
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { Plugin, CoreSetup, PluginInitializerContext } from 'src/core/server';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { APMOSSConfig } from './';
|
import { APMOSSConfig } from './';
|
||||||
|
|
||||||
export class APMOSSPlugin implements Plugin<{ config$: Observable<APMOSSConfig> }> {
|
export class APMOSSPlugin implements Plugin<APMOSSPluginSetup> {
|
||||||
constructor(private readonly initContext: PluginInitializerContext) {
|
constructor(private readonly initContext: PluginInitializerContext) {
|
||||||
this.initContext = initContext;
|
this.initContext = initContext;
|
||||||
}
|
}
|
||||||
|
@ -36,3 +36,7 @@ export class APMOSSPlugin implements Plugin<{ config$: Observable<APMOSSConfig>
|
||||||
start() {}
|
start() {}
|
||||||
stop() {}
|
stop() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface APMOSSPluginSetup {
|
||||||
|
config$: Observable<APMOSSConfig>;
|
||||||
|
}
|
||||||
|
|
|
@ -62,8 +62,7 @@ export const getDynamicIndexPattern = async ({
|
||||||
cache.set(CACHE_KEY, undefined);
|
cache.set(CACHE_KEY, undefined);
|
||||||
const notExists = e.output?.statusCode === 404;
|
const notExists = e.output?.statusCode === 404;
|
||||||
if (notExists) {
|
if (notExists) {
|
||||||
// eslint-disable-next-line no-console
|
context.logger.error(
|
||||||
console.error(
|
|
||||||
`Could not get dynamic index pattern because indices "${indexPatternTitle}" don't exist`
|
`Could not get dynamic index pattern because indices "${indexPatternTitle}" don't exist`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,17 +4,19 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IClusterClient } from 'src/core/server';
|
import { IClusterClient, Logger } from 'src/core/server';
|
||||||
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
|
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
|
||||||
import { APMConfig } from '../../..';
|
import { APMConfig } from '../../..';
|
||||||
import { getApmIndicesConfig } from '../apm_indices/get_apm_indices';
|
import { getApmIndicesConfig } from '../apm_indices/get_apm_indices';
|
||||||
|
|
||||||
export async function createApmAgentConfigurationIndex({
|
export async function createApmAgentConfigurationIndex({
|
||||||
esClient,
|
esClient,
|
||||||
config
|
config,
|
||||||
|
logger
|
||||||
}: {
|
}: {
|
||||||
esClient: IClusterClient;
|
esClient: IClusterClient;
|
||||||
config: APMConfig;
|
config: APMConfig;
|
||||||
|
logger: Logger;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
const index = getApmIndicesConfig(config).apmAgentConfigurationIndex;
|
const index = getApmIndicesConfig(config).apmAgentConfigurationIndex;
|
||||||
|
@ -32,8 +34,7 @@ export async function createApmAgentConfigurationIndex({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line no-console
|
logger.error(`Could not create APM Agent configuration: ${e.message}`);
|
||||||
console.error('Could not create APM Agent configuration:', e.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
*/
|
*/
|
||||||
import { PluginInitializerContext, Plugin, CoreSetup } from 'src/core/server';
|
import { PluginInitializerContext, Plugin, CoreSetup } from 'src/core/server';
|
||||||
import { Observable, combineLatest, AsyncSubject } from 'rxjs';
|
import { Observable, combineLatest, AsyncSubject } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map, take } from 'rxjs/operators';
|
||||||
import { Server } from 'hapi';
|
import { Server } from 'hapi';
|
||||||
import { once } from 'lodash';
|
import { once } from 'lodash';
|
||||||
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
||||||
|
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
|
||||||
import { makeApmUsageCollector } from './lib/apm_telemetry';
|
import { makeApmUsageCollector } from './lib/apm_telemetry';
|
||||||
import { Plugin as APMOSSPlugin } from '../../../../src/plugins/apm_oss/server';
|
|
||||||
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
|
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
|
||||||
import { createApmApi } from './routes/create_apm_api';
|
import { createApmApi } from './routes/create_apm_api';
|
||||||
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
|
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
|
||||||
|
@ -33,26 +33,23 @@ export interface APMPluginContract {
|
||||||
|
|
||||||
export class APMPlugin implements Plugin<APMPluginContract> {
|
export class APMPlugin implements Plugin<APMPluginContract> {
|
||||||
legacySetup$: AsyncSubject<LegacySetup>;
|
legacySetup$: AsyncSubject<LegacySetup>;
|
||||||
currentConfig: APMConfig;
|
|
||||||
constructor(private readonly initContext: PluginInitializerContext) {
|
constructor(private readonly initContext: PluginInitializerContext) {
|
||||||
this.initContext = initContext;
|
this.initContext = initContext;
|
||||||
this.legacySetup$ = new AsyncSubject();
|
this.legacySetup$ = new AsyncSubject();
|
||||||
this.currentConfig = {} as APMConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setup(
|
public async setup(
|
||||||
core: CoreSetup,
|
core: CoreSetup,
|
||||||
plugins: {
|
plugins: {
|
||||||
apm_oss: APMOSSPlugin extends Plugin<infer TSetup> ? TSetup : never;
|
apm_oss: APMOSSPluginSetup;
|
||||||
home: HomeServerPluginSetup;
|
home: HomeServerPluginSetup;
|
||||||
licensing: LicensingPluginSetup;
|
licensing: LicensingPluginSetup;
|
||||||
cloud?: CloudSetup;
|
cloud?: CloudSetup;
|
||||||
usageCollection?: UsageCollectionSetup;
|
usageCollection?: UsageCollectionSetup;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const config$ = this.initContext.config.create<APMXPackConfig>();
|
|
||||||
const logger = this.initContext.logger.get('apm');
|
const logger = this.initContext.logger.get('apm');
|
||||||
|
const config$ = this.initContext.config.create<APMXPackConfig>();
|
||||||
const mergedConfig$ = combineLatest(plugins.apm_oss.config$, config$).pipe(
|
const mergedConfig$ = combineLatest(plugins.apm_oss.config$, config$).pipe(
|
||||||
map(([apmOssConfig, apmConfig]) => mergeConfigs(apmOssConfig, apmConfig))
|
map(([apmOssConfig, apmConfig]) => mergeConfigs(apmOssConfig, apmConfig))
|
||||||
);
|
);
|
||||||
|
@ -61,28 +58,26 @@ export class APMPlugin implements Plugin<APMPluginContract> {
|
||||||
createApmApi().init(core, { config$: mergedConfig$, logger, __LEGACY });
|
createApmApi().init(core, { config$: mergedConfig$, logger, __LEGACY });
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => {
|
const currentConfig = await mergedConfig$.pipe(take(1)).toPromise();
|
||||||
mergedConfig$.subscribe(async config => {
|
|
||||||
this.currentConfig = config;
|
// create agent configuration index without blocking setup lifecycle
|
||||||
await createApmAgentConfigurationIndex({
|
createApmAgentConfigurationIndex({
|
||||||
esClient: core.elasticsearch.dataClient,
|
esClient: core.elasticsearch.dataClient,
|
||||||
config
|
config: currentConfig,
|
||||||
});
|
logger
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
plugins.home.tutorials.registerTutorial(
|
plugins.home.tutorials.registerTutorial(
|
||||||
tutorialProvider({
|
tutorialProvider({
|
||||||
isEnabled: this.currentConfig['xpack.apm.ui.enabled'],
|
isEnabled: currentConfig['xpack.apm.ui.enabled'],
|
||||||
indexPatternTitle: this.currentConfig['apm_oss.indexPattern'],
|
indexPatternTitle: currentConfig['apm_oss.indexPattern'],
|
||||||
cloud: plugins.cloud,
|
cloud: plugins.cloud,
|
||||||
indices: {
|
indices: {
|
||||||
errorIndices: this.currentConfig['apm_oss.errorIndices'],
|
errorIndices: currentConfig['apm_oss.errorIndices'],
|
||||||
metricsIndices: this.currentConfig['apm_oss.metricsIndices'],
|
metricsIndices: currentConfig['apm_oss.metricsIndices'],
|
||||||
onboardingIndices: this.currentConfig['apm_oss.onboardingIndices'],
|
onboardingIndices: currentConfig['apm_oss.onboardingIndices'],
|
||||||
sourcemapIndices: this.currentConfig['apm_oss.sourcemapIndices'],
|
sourcemapIndices: currentConfig['apm_oss.sourcemapIndices'],
|
||||||
transactionIndices: this.currentConfig['apm_oss.transactionIndices']
|
transactionIndices: currentConfig['apm_oss.transactionIndices']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -108,7 +103,7 @@ export class APMPlugin implements Plugin<APMPluginContract> {
|
||||||
getApmIndices: async () =>
|
getApmIndices: async () =>
|
||||||
getApmIndices({
|
getApmIndices({
|
||||||
savedObjectsClient: await getInternalSavedObjectsClient(core),
|
savedObjectsClient: await getInternalSavedObjectsClient(core),
|
||||||
config: this.currentConfig
|
config: currentConfig
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue