Skip to content

Commit

Permalink
[8.16] [Fleet] Fix output id when using default output as integration…
Browse files Browse the repository at this point in the history
… output (elastic#206286) (elastic#206676)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Fleet] Fix output id when using default output as integration output
(elastic#206286)](elastic#206286)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-10T16:31:24Z","message":"[Fleet]
Fix output id when using default output as integration output
(elastic#206286)","sha":"9cda1a83a6e5b48b88a326a67a185bc8a6a703fa","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Fleet","v9.0.0","backport:prev-major"],"title":"[Fleet]
Fix output id when using default output as integration
output","number":206286,"url":"https://github.com/elastic/kibana/pull/206286","mergeCommit":{"message":"[Fleet]
Fix output id when using default output as integration output
(elastic#206286)","sha":"9cda1a83a6e5b48b88a326a67a185bc8a6a703fa"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206286","number":206286,"mergeCommit":{"message":"[Fleet]
Fix output id when using default output as integration output
(elastic#206286)","sha":"9cda1a83a6e5b48b88a326a67a185bc8a6a703fa"}}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
  • Loading branch information
kibanamachine and nchaulet authored Jan 14, 2025
1 parent c935d35 commit c96baea
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 7 deletions.

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

Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,126 @@ describe('getFullAgentPolicy', () => {
expect(agentPolicy).toMatchSnapshot();
});

it('should return the right outputs and permissions when package policies use their own outputs (with default output)', async () => {
mockedGetPackageInfo.mockResolvedValue({
data_streams: [
{
type: 'logs',
dataset: 'elastic_agent.metricbeat',
},
{
type: 'metrics',
dataset: 'elastic_agent.metricbeat',
},
{
type: 'logs',
dataset: 'elastic_agent.filebeat',
},
{
type: 'metrics',
dataset: 'elastic_agent.filebeat',
},
],
} as PackageInfo);
mockAgentPolicy({
id: 'integration-output-policy',
status: 'active',
package_policies: [
{
id: 'package-policy-using-output',
name: 'test-policy-1',
namespace: 'policyspace',
enabled: true,
package: { name: 'test_package', version: '0.0.0', title: 'Test Package' },
output_id: 'test-id',
inputs: [
{
type: 'test-logs',
enabled: true,
streams: [
{
id: 'test-logs',
enabled: true,
data_stream: { type: 'logs', dataset: 'some-logs' },
},
],
},
{
type: 'test-metrics',
enabled: false,
streams: [
{
id: 'test-logs',
enabled: false,
data_stream: { type: 'metrics', dataset: 'some-metrics' },
},
],
},
],
created_at: '',
updated_at: '',
created_by: '',
updated_by: '',
revision: 1,
policy_id: '',
policy_ids: [''],
},
{
id: 'package-policy-no-output',
name: 'test-policy-2',
namespace: '',
enabled: true,
package: { name: 'system', version: '1.0.0', title: 'System' },
inputs: [
{
type: 'test-logs',
enabled: true,
streams: [
{
id: 'test-logs',
enabled: true,
data_stream: { type: 'logs', dataset: 'some-logs' },
},
],
},
{
type: 'test-metrics',
enabled: false,
streams: [
{
id: 'test-logs',
enabled: false,
data_stream: { type: 'metrics', dataset: 'some-metrics' },
},
],
},
],
created_at: '',
updated_at: '',
created_by: '',
updated_by: '',
revision: 1,
policy_id: '',
policy_ids: [''],
},
],
is_managed: false,
namespace: 'defaultspace',
revision: 1,
name: 'Policy',
updated_at: '2020-01-01',
updated_by: 'qwerty',
is_protected: false,
data_output_id: 'data-output-id',
});

const agentPolicy = await getFullAgentPolicy(
savedObjectsClientMock.create(),
'integration-output-policy'
);
expect(agentPolicy).toMatchSnapshot();
});

it('should return the sourceURI from the agent policy', async () => {
mockAgentPolicy({
namespace: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,23 @@ export async function getFullAgentPolicy(
})
);

const inputs = await storedPackagePoliciesToAgentInputs(
agentPolicy.package_policies as PackagePolicy[],
packageInfoCache,
getOutputIdForAgentPolicy(dataOutput),
agentPolicy.namespace,
agentPolicy.global_data_tags
);
const inputs = (
await storedPackagePoliciesToAgentInputs(
agentPolicy.package_policies as PackagePolicy[],
packageInfoCache,
getOutputIdForAgentPolicy(dataOutput),
agentPolicy.namespace,
agentPolicy.global_data_tags
)
).map((input) => {
// fix output id for default output
const output = outputs.find(({ id: outputId }) => input.use_output === outputId);
if (output) {
input.use_output = getOutputIdForAgentPolicy(output);
}

return input;
});
const features = (agentPolicy.agent_features || []).reduce((acc, { name, ...featureConfig }) => {
acc[name] = featureConfig;
return acc;
Expand Down

0 comments on commit c96baea

Please sign in to comment.