mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[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
5 changed files with 31 additions and 32 deletions
|
@ -38,4 +38,4 @@ export function plugin(initializerContext: PluginInitializerContext) {
|
|||
|
||||
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 { APMOSSConfig } from './';
|
||||
|
||||
export class APMOSSPlugin implements Plugin<{ config$: Observable<APMOSSConfig> }> {
|
||||
export class APMOSSPlugin implements Plugin<APMOSSPluginSetup> {
|
||||
constructor(private readonly initContext: PluginInitializerContext) {
|
||||
this.initContext = initContext;
|
||||
}
|
||||
|
@ -36,3 +36,7 @@ export class APMOSSPlugin implements Plugin<{ config$: Observable<APMOSSConfig>
|
|||
start() {}
|
||||
stop() {}
|
||||
}
|
||||
|
||||
export interface APMOSSPluginSetup {
|
||||
config$: Observable<APMOSSConfig>;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,7 @@ export const getDynamicIndexPattern = async ({
|
|||
cache.set(CACHE_KEY, undefined);
|
||||
const notExists = e.output?.statusCode === 404;
|
||||
if (notExists) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
context.logger.error(
|
||||
`Could not get dynamic index pattern because indices "${indexPatternTitle}" don't exist`
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -4,17 +4,19 @@
|
|||
* 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 { APMConfig } from '../../..';
|
||||
import { getApmIndicesConfig } from '../apm_indices/get_apm_indices';
|
||||
|
||||
export async function createApmAgentConfigurationIndex({
|
||||
esClient,
|
||||
config
|
||||
config,
|
||||
logger
|
||||
}: {
|
||||
esClient: IClusterClient;
|
||||
config: APMConfig;
|
||||
logger: Logger;
|
||||
}) {
|
||||
try {
|
||||
const index = getApmIndicesConfig(config).apmAgentConfigurationIndex;
|
||||
|
@ -32,8 +34,7 @@ export async function createApmAgentConfigurationIndex({
|
|||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Could not create APM Agent configuration:', e.message);
|
||||
logger.error(`Could not create APM Agent configuration: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
*/
|
||||
import { PluginInitializerContext, Plugin, CoreSetup } from 'src/core/server';
|
||||
import { Observable, combineLatest, AsyncSubject } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { Server } from 'hapi';
|
||||
import { once } from 'lodash';
|
||||
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
||||
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
|
||||
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 { createApmApi } from './routes/create_apm_api';
|
||||
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
|
||||
|
@ -33,26 +33,23 @@ export interface APMPluginContract {
|
|||
|
||||
export class APMPlugin implements Plugin<APMPluginContract> {
|
||||
legacySetup$: AsyncSubject<LegacySetup>;
|
||||
currentConfig: APMConfig;
|
||||
constructor(private readonly initContext: PluginInitializerContext) {
|
||||
this.initContext = initContext;
|
||||
this.legacySetup$ = new AsyncSubject();
|
||||
this.currentConfig = {} as APMConfig;
|
||||
}
|
||||
|
||||
public async setup(
|
||||
core: CoreSetup,
|
||||
plugins: {
|
||||
apm_oss: APMOSSPlugin extends Plugin<infer TSetup> ? TSetup : never;
|
||||
apm_oss: APMOSSPluginSetup;
|
||||
home: HomeServerPluginSetup;
|
||||
licensing: LicensingPluginSetup;
|
||||
cloud?: CloudSetup;
|
||||
usageCollection?: UsageCollectionSetup;
|
||||
}
|
||||
) {
|
||||
const config$ = this.initContext.config.create<APMXPackConfig>();
|
||||
const logger = this.initContext.logger.get('apm');
|
||||
|
||||
const config$ = this.initContext.config.create<APMXPackConfig>();
|
||||
const mergedConfig$ = combineLatest(plugins.apm_oss.config$, config$).pipe(
|
||||
map(([apmOssConfig, apmConfig]) => mergeConfigs(apmOssConfig, apmConfig))
|
||||
);
|
||||
|
@ -61,28 +58,26 @@ export class APMPlugin implements Plugin<APMPluginContract> {
|
|||
createApmApi().init(core, { config$: mergedConfig$, logger, __LEGACY });
|
||||
});
|
||||
|
||||
await new Promise(resolve => {
|
||||
mergedConfig$.subscribe(async config => {
|
||||
this.currentConfig = config;
|
||||
await createApmAgentConfigurationIndex({
|
||||
esClient: core.elasticsearch.dataClient,
|
||||
config
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
const currentConfig = await mergedConfig$.pipe(take(1)).toPromise();
|
||||
|
||||
// create agent configuration index without blocking setup lifecycle
|
||||
createApmAgentConfigurationIndex({
|
||||
esClient: core.elasticsearch.dataClient,
|
||||
config: currentConfig,
|
||||
logger
|
||||
});
|
||||
|
||||
plugins.home.tutorials.registerTutorial(
|
||||
tutorialProvider({
|
||||
isEnabled: this.currentConfig['xpack.apm.ui.enabled'],
|
||||
indexPatternTitle: this.currentConfig['apm_oss.indexPattern'],
|
||||
isEnabled: currentConfig['xpack.apm.ui.enabled'],
|
||||
indexPatternTitle: currentConfig['apm_oss.indexPattern'],
|
||||
cloud: plugins.cloud,
|
||||
indices: {
|
||||
errorIndices: this.currentConfig['apm_oss.errorIndices'],
|
||||
metricsIndices: this.currentConfig['apm_oss.metricsIndices'],
|
||||
onboardingIndices: this.currentConfig['apm_oss.onboardingIndices'],
|
||||
sourcemapIndices: this.currentConfig['apm_oss.sourcemapIndices'],
|
||||
transactionIndices: this.currentConfig['apm_oss.transactionIndices']
|
||||
errorIndices: currentConfig['apm_oss.errorIndices'],
|
||||
metricsIndices: currentConfig['apm_oss.metricsIndices'],
|
||||
onboardingIndices: currentConfig['apm_oss.onboardingIndices'],
|
||||
sourcemapIndices: currentConfig['apm_oss.sourcemapIndices'],
|
||||
transactionIndices: currentConfig['apm_oss.transactionIndices']
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -108,7 +103,7 @@ export class APMPlugin implements Plugin<APMPluginContract> {
|
|||
getApmIndices: async () =>
|
||||
getApmIndices({
|
||||
savedObjectsClient: await getInternalSavedObjectsClient(core),
|
||||
config: this.currentConfig
|
||||
config: currentConfig
|
||||
})
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue