Skip to content

Commit

Permalink
[UII] Drop processors.add_fields when global data tag array is empty (
Browse files Browse the repository at this point in the history
#187012)

## Summary

Resolves #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
  • Loading branch information
jen-huang authored Jun 26, 2024
1 parent 22e0545 commit 24470dd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 24470dd

Please sign in to comment.