mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Updating APM labels from kibana.yml (#144036)
* register apm config listen to config file changes and update apm labels * lint * code review * fixes
This commit is contained in:
parent
7fe732728b
commit
0f95ae4b39
5 changed files with 81 additions and 1 deletions
|
@ -10,3 +10,4 @@ export { getConfiguration } from './src/config_loader';
|
|||
export { initApm } from './src/init_apm';
|
||||
export { shouldInstrumentClient } from './src/rum_agent_configuration';
|
||||
export type { ApmConfiguration } from './src/config';
|
||||
export { apmConfigSchema } from './src/apm_config';
|
||||
|
|
21
packages/kbn-apm-config-loader/src/apm_config.ts
Normal file
21
packages/kbn-apm-config-loader/src/apm_config.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
export const apmConfigSchema = schema.object({
|
||||
apm: schema.object(
|
||||
{
|
||||
active: schema.maybe(schema.boolean()),
|
||||
serverUrl: schema.maybe(schema.uri()),
|
||||
secretToken: schema.maybe(schema.string()),
|
||||
globalLabels: schema.object({}, { unknowns: 'allow' }),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
});
|
22
src/core/server/root/elastic_config.ts
Normal file
22
src/core/server/root/elastic_config.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { schema, TypeOf } from '@kbn/config-schema';
|
||||
import { apmConfigSchema } from '@kbn/apm-config-loader';
|
||||
import type { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';
|
||||
|
||||
const elasticConfig = schema.object({
|
||||
apm: apmConfigSchema,
|
||||
});
|
||||
|
||||
export type ElasticConfigType = TypeOf<typeof elasticConfig>;
|
||||
|
||||
export const elasticApmConfig: ServiceConfigDescriptor<ElasticConfigType> = {
|
||||
path: 'elastic',
|
||||
schema: elasticConfig,
|
||||
};
|
|
@ -7,10 +7,20 @@
|
|||
*/
|
||||
|
||||
import { ConnectableObservable, Subscription } from 'rxjs';
|
||||
import { first, publishReplay, switchMap, concatMap, tap } from 'rxjs/operators';
|
||||
import {
|
||||
first,
|
||||
publishReplay,
|
||||
switchMap,
|
||||
concatMap,
|
||||
tap,
|
||||
distinctUntilChanged,
|
||||
} from 'rxjs/operators';
|
||||
import type { Logger, LoggerFactory } from '@kbn/logging';
|
||||
import { Env, RawConfigurationProvider } from '@kbn/config';
|
||||
import { LoggingConfigType, LoggingSystem } from '@kbn/core-logging-server-internal';
|
||||
import apm from 'elastic-apm-node';
|
||||
import { isEqual } from 'lodash';
|
||||
import type { ElasticConfigType } from './elastic_config';
|
||||
import { Server } from '../server';
|
||||
|
||||
/**
|
||||
|
@ -22,6 +32,7 @@ export class Root {
|
|||
private readonly loggingSystem: LoggingSystem;
|
||||
private readonly server: Server;
|
||||
private loggingConfigSubscription?: Subscription;
|
||||
private apmConfigSubscription?: Subscription;
|
||||
|
||||
constructor(
|
||||
rawConfigProvider: RawConfigurationProvider,
|
||||
|
@ -37,7 +48,9 @@ export class Root {
|
|||
public async preboot() {
|
||||
try {
|
||||
this.server.setupCoreConfig();
|
||||
this.setupApmLabelSync();
|
||||
await this.setupLogging();
|
||||
|
||||
this.log.debug('prebooting root');
|
||||
return await this.server.preboot();
|
||||
} catch (e) {
|
||||
|
@ -85,6 +98,10 @@ export class Root {
|
|||
this.loggingConfigSubscription.unsubscribe();
|
||||
this.loggingConfigSubscription = undefined;
|
||||
}
|
||||
if (this.apmConfigSubscription !== undefined) {
|
||||
this.apmConfigSubscription.unsubscribe();
|
||||
this.apmConfigSubscription = undefined;
|
||||
}
|
||||
await this.loggingSystem.stop();
|
||||
|
||||
if (this.onShutdown !== undefined) {
|
||||
|
@ -92,6 +109,23 @@ export class Root {
|
|||
}
|
||||
}
|
||||
|
||||
private setupApmLabelSync() {
|
||||
const { configService } = this.server;
|
||||
|
||||
// Update APM labels on config change
|
||||
this.apmConfigSubscription = configService
|
||||
.getConfig$()
|
||||
.pipe(
|
||||
switchMap(() => configService.atPath<ElasticConfigType>('elastic')),
|
||||
distinctUntilChanged(isEqual),
|
||||
tap((elasticConfig) => {
|
||||
const labels = elasticConfig.apm?.globalLabels || {};
|
||||
apm.addLabels(labels);
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
private async setupLogging() {
|
||||
const { configService } = this.server;
|
||||
// Stream that maps config updates to logger updates, including update failures.
|
||||
|
|
|
@ -80,6 +80,7 @@ import {
|
|||
config as pluginsConfig,
|
||||
} from '@kbn/core-plugins-server-internal';
|
||||
import { CoreApp } from './core_app';
|
||||
import { elasticApmConfig } from './root/elastic_config';
|
||||
|
||||
const coreId = Symbol('core');
|
||||
const rootConfigPath = '';
|
||||
|
@ -457,6 +458,7 @@ export class Server {
|
|||
cspConfig,
|
||||
deprecationConfig,
|
||||
elasticsearchConfig,
|
||||
elasticApmConfig,
|
||||
executionContextConfig,
|
||||
externalUrlConfig,
|
||||
httpConfig,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue