[UII] Drop processors.add_fields when global data tag array is empty (#187012)

## Summary

Resolves https://github.com/elastic/kibana/issues/186993.

When `global_data_tags` array on an agent policy is empty due to user
deleting all existing fields, this PR fixes the generated yaml by
dropping the `processors.add_fields` entirely. Previously, it was being
set with null values leading to agent health issues.

### 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
This commit is contained in:
Jen Huang 2024-06-26 15:40:07 -07:00 committed by GitHub
parent 22e0545d0e
commit 24470dde7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 1 deletions

View file

@ -877,4 +877,51 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
},
]);
});
it('does not include processor add_fields when global tags array is empty', async () => {
expect(
await storedPackagePoliciesToAgentInputs(
[
{
...mockPackagePolicy,
package: {
name: 'mock_package',
title: 'Mock package',
version: '0.0.0',
},
inputs: [
{
...mockInput,
compiled_input: {
inputVar: 'input-value',
},
streams: [],
},
],
},
],
packageInfoCache,
undefined,
undefined,
[]
)
).toEqual([
{
id: 'test-logs-some-uuid',
name: 'mock_package-policy',
package_policy_id: 'some-uuid',
revision: 1,
type: 'test-logs',
data_stream: { namespace: 'default' },
use_output: 'default',
meta: {
package: {
name: 'mock_package',
version: '0.0.0',
},
},
inputVar: 'input-value',
},
]);
});
});

View file

@ -146,7 +146,10 @@ export const storedPackagePoliciesToAgentInputs = async (
): Promise<FullAgentPolicyInput[]> => {
const fullInputs: FullAgentPolicyInput[] = [];
const addFields = globalDataTags ? globalDataTagsToAddFields(globalDataTags) : undefined;
const addFields =
globalDataTags && globalDataTags.length > 0
? globalDataTagsToAddFields(globalDataTags)
: undefined;
for (const packagePolicy of packagePolicies) {
if (!isPolicyEnabled(packagePolicy)) {