Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Make input IDs unique in agent policy yaml #127343

Merged
merged 5 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
],
};

const mockInput2: PackagePolicyInput = {
type: 'test-metrics',
policy_template: 'some-template',
enabled: true,
vars: {
inputVar: { value: 'input-value' },
inputVar2: { value: undefined },
inputVar3: {
type: 'yaml',
value: 'testField: test',
},
inputVar4: { value: '' },
},
streams: [
{
id: 'test-metrics-foo',
enabled: true,
data_stream: { dataset: 'foo', type: 'metrics' },
vars: {
fooVar: { value: 'foo-value' },
fooVar2: { value: [1, 2] },
},
compiled_stream: {
fooKey: 'fooValue1',
fooKey2: ['fooValue2'],
},
},
],
};

it('returns no inputs for package policy with no inputs, or only disabled inputs', () => {
expect(storedPackagePoliciesToAgentInputs([mockPackagePolicy])).toEqual([]);

Expand Down Expand Up @@ -118,7 +148,7 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
])
).toEqual([
{
id: 'some-uuid',
id: 'test-logs-some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-logs',
Expand Down Expand Up @@ -146,6 +176,71 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
]);
});

it('returns unique agent inputs IDs, with policy template name if one exists', () => {
expect(
storedPackagePoliciesToAgentInputs([
{
...mockPackagePolicy,
package: {
name: 'mock-package',
title: 'Mock package',
version: '0.0.0',
},
inputs: [mockInput, mockInput2],
},
])
).toEqual([
{
id: 'test-logs-some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-logs',
data_stream: { namespace: 'default' },
use_output: 'default',
meta: {
package: {
name: 'mock-package',
version: '0.0.0',
},
},
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' },
},
],
},
{
id: 'test-metrics-some-template-some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-metrics',
data_stream: { namespace: 'default' },
use_output: 'default',
meta: {
package: {
name: 'mock-package',
version: '0.0.0',
},
},
streams: [
{
id: 'test-metrics-foo',
data_stream: { dataset: 'foo', type: 'metrics' },
fooKey: 'fooValue1',
fooKey2: ['fooValue2'],
},
],
},
]);
});

it('returns agent inputs without streams', () => {
expect(
storedPackagePoliciesToAgentInputs([
Expand All @@ -169,7 +264,7 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
])
).toEqual([
{
id: 'some-uuid',
id: 'test-logs-some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-logs',
Expand Down Expand Up @@ -201,7 +296,7 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
])
).toEqual([
{
id: 'some-uuid',
id: 'test-logs-some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-logs',
Expand Down Expand Up @@ -263,7 +358,7 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
])
).toEqual([
{
id: 'some-uuid',
id: 'test-logs-some-uuid',
revision: 1,
name: 'mock-package-policy',
type: 'test-logs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const storedPackagePoliciesToAgentInputs = (
}

const fullInput: FullAgentPolicyInput = {
id: packagePolicy.id || packagePolicy.name,
id: `${input.type}${input.policy_template ? `-${input.policy_template}-` : '-'}${
packagePolicy.id
}`,
revision: packagePolicy.revision,
name: packagePolicy.name,
type: input.type,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.