mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[APM] Fleet support for merging input.config values with other nested properties in the policy input (#101690)
* [APM] Improvments in the APM fleet integration (#95501) * added unit test and line comment * fixes eslint issues
This commit is contained in:
parent
e9a4028005
commit
befd30ff6c
3 changed files with 89 additions and 4 deletions
|
@ -115,6 +115,7 @@ export function getPackagePolicyWithAgentConfigurations(
|
|||
{
|
||||
...firstInput,
|
||||
config: {
|
||||
...firstInput.config,
|
||||
[APM_SERVER]: {
|
||||
value: {
|
||||
...apmServerValue,
|
||||
|
|
|
@ -218,4 +218,81 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
|
|||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns agent inputs with deeply merged config values', () => {
|
||||
expect(
|
||||
storedPackagePoliciesToAgentInputs([
|
||||
{
|
||||
...mockPackagePolicy,
|
||||
inputs: [
|
||||
{
|
||||
...mockInput,
|
||||
compiled_input: {
|
||||
agent_input_template_group1_vars: {
|
||||
inputVar: 'input-value',
|
||||
},
|
||||
agent_input_template_group2_vars: {
|
||||
inputVar3: {
|
||||
testFieldGroup: {
|
||||
subField1: 'subfield1',
|
||||
},
|
||||
testField: 'test',
|
||||
},
|
||||
},
|
||||
},
|
||||
config: {
|
||||
agent_input_template_group1_vars: {
|
||||
value: {
|
||||
inputVar2: {},
|
||||
},
|
||||
},
|
||||
agent_input_template_group2_vars: {
|
||||
value: {
|
||||
inputVar3: {
|
||||
testFieldGroup: {
|
||||
subField2: 'subfield2',
|
||||
},
|
||||
},
|
||||
inputVar4: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
).toEqual([
|
||||
{
|
||||
id: 'some-uuid',
|
||||
revision: 1,
|
||||
name: 'mock-package-policy',
|
||||
type: 'test-logs',
|
||||
data_stream: { namespace: 'default' },
|
||||
use_output: 'default',
|
||||
agent_input_template_group1_vars: {
|
||||
inputVar: 'input-value',
|
||||
inputVar2: {},
|
||||
},
|
||||
agent_input_template_group2_vars: {
|
||||
inputVar3: {
|
||||
testField: 'test',
|
||||
testFieldGroup: {
|
||||
subField1: 'subfield1',
|
||||
subField2: 'subfield2',
|
||||
},
|
||||
},
|
||||
inputVar4: '',
|
||||
},
|
||||
streams: [
|
||||
{
|
||||
id: 'test-logs-foo',
|
||||
data_stream: { dataset: 'foo', type: 'logs' },
|
||||
fooKey: 'fooValue1',
|
||||
fooKey2: ['fooValue2'],
|
||||
},
|
||||
{ id: 'test-logs-bar', data_stream: { dataset: 'bar', type: 'logs' } },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { merge } from 'lodash';
|
||||
|
||||
import type { PackagePolicy, FullAgentPolicyInput, FullAgentPolicyInputStream } from '../types';
|
||||
import { DEFAULT_OUTPUT } from '../constants';
|
||||
|
||||
|
@ -31,10 +33,6 @@ export const storedPackagePoliciesToAgentInputs = (
|
|||
namespace: packagePolicy.namespace || 'default',
|
||||
},
|
||||
use_output: DEFAULT_OUTPUT.name,
|
||||
...Object.entries(input.config || {}).reduce((acc, [key, { value }]) => {
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {} as { [k: string]: any }),
|
||||
...(input.compiled_input || {}),
|
||||
...(input.streams.length
|
||||
? {
|
||||
|
@ -56,6 +54,15 @@ export const storedPackagePoliciesToAgentInputs = (
|
|||
: {}),
|
||||
};
|
||||
|
||||
// deeply merge the input.config values with the full policy input
|
||||
merge(
|
||||
fullInput,
|
||||
Object.entries(input.config || {}).reduce(
|
||||
(acc, [key, { value }]) => ({ ...acc, [key]: value }),
|
||||
{}
|
||||
)
|
||||
);
|
||||
|
||||
if (packagePolicy.package) {
|
||||
fullInput.meta = {
|
||||
package: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue