Revert "deepmerge in merging apm-configuration (#179048)" (#180005)

## Summary

Reverting #179048 because it creates a false expectation that
environment vars and config will be merged. This is true for the RUM
agent. However, the NodeJS agent reads the environment vars and discards
any provided config, leading to inconsistent behavior between both
agents.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
Alejandro Fernández Haro 2024-04-04 22:02:48 +02:00 committed by GitHub
parent 759e1a5466
commit 2ad38df5cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 23 deletions

View file

@ -7,9 +7,9 @@
*/
import type { AgentConfigOptions, Labels } from 'elastic-apm-node';
import {
gitRevExecMock,
mockedRootDir,
packageMock,
mockedRootDir,
gitRevExecMock,
readUuidFileMock,
resetAllMocks,
} from './config.test.mocks';
@ -153,7 +153,6 @@ describe('ApmConfiguration', () => {
delete process.env.ELASTIC_APM_API_KEY;
delete process.env.ELASTIC_APM_KIBANA_FRONTEND_ACTIVE;
delete process.env.ELASTIC_APM_SERVER_URL;
delete process.env.ELASTIC_APM_GLOBAL_LABELS;
delete process.env.NODE_ENV;
});
@ -186,21 +185,6 @@ describe('ApmConfiguration', () => {
})
);
});
it('ELASTIC_APM_GLOBAL_LABELS', () => {
process.env.ELASTIC_APM_GLOBAL_LABELS = 'test1=1,test2=2';
const config = new ApmConfiguration(mockedRootDir, {}, true);
expect(config.getConfig('serviceName')).toEqual(
expect.objectContaining({
globalLabels: {
git_rev: 'sha',
test1: '1',
test2: '2',
},
})
);
});
});
it('ELASTIC_APM_KIBANA_FRONTEND_ACTIVE', () => {

View file

@ -7,7 +7,6 @@
*/
import { join } from 'path';
import deepmerge from 'deepmerge';
import { merge, isEmpty } from 'lodash';
import { execSync } from 'child_process';
import { getDataPath } from '@kbn/utils';
@ -310,10 +309,7 @@ export class ApmConfiguration {
const { servicesOverrides, redactUsers, ...configFromKibanaConfig } =
this.getConfigFromKibanaConfig();
const configFromEnv = this.getConfigFromEnv(configFromKibanaConfig);
const config = [configFromKibanaConfig, configFromEnv].reduce<AgentConfigOptions>(
(acc, conf) => deepmerge(acc, conf),
{}
);
const config = merge({}, configFromKibanaConfig, configFromEnv);
if (config.active === false && config.contextPropagationOnly !== false) {
throw new Error(