mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.16`: - [[Fleet] Fix output id when using default output as integration output (#206286)](https://github.com/elastic/kibana/pull/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":"nicolas.chaulet@elastic.co"},"sourceCommit":{"committedDate":"2025-01-10T16:31:24Z","message":"[Fleet] Fix output id when using default output as integration output (#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 (#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 (#206286)","sha":"9cda1a83a6e5b48b88a326a67a185bc8a6a703fa"}}]}] BACKPORT--> Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
parent
c935d356eb
commit
c96baea737
3 changed files with 291 additions and 7 deletions
|
@ -1,5 +1,159 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`getFullAgentPolicy should return the right outputs and permissions when package policies use their own outputs (with default output) 1`] = `
|
||||
Object {
|
||||
"agent": Object {
|
||||
"download": Object {
|
||||
"sourceURI": "http://default-registry.co",
|
||||
},
|
||||
"features": Object {},
|
||||
"monitoring": Object {
|
||||
"enabled": false,
|
||||
"logs": false,
|
||||
"metrics": false,
|
||||
"traces": false,
|
||||
},
|
||||
"protection": Object {
|
||||
"enabled": false,
|
||||
"signing_key": "",
|
||||
"uninstall_token_hash": "",
|
||||
},
|
||||
},
|
||||
"fleet": Object {
|
||||
"hosts": Array [
|
||||
"http://fleetserver:8220",
|
||||
],
|
||||
},
|
||||
"id": "integration-output-policy",
|
||||
"inputs": Array [
|
||||
Object {
|
||||
"data_stream": Object {
|
||||
"namespace": "policyspace",
|
||||
},
|
||||
"id": "test-logs-package-policy-using-output",
|
||||
"meta": Object {
|
||||
"package": Object {
|
||||
"name": "test_package",
|
||||
"version": "0.0.0",
|
||||
},
|
||||
},
|
||||
"name": "test-policy-1",
|
||||
"package_policy_id": "package-policy-using-output",
|
||||
"revision": 1,
|
||||
"streams": Array [
|
||||
Object {
|
||||
"data_stream": Object {
|
||||
"dataset": "some-logs",
|
||||
"type": "logs",
|
||||
},
|
||||
"id": "test-logs",
|
||||
},
|
||||
],
|
||||
"type": "test-logs",
|
||||
"use_output": "default",
|
||||
},
|
||||
Object {
|
||||
"data_stream": Object {
|
||||
"namespace": "defaultspace",
|
||||
},
|
||||
"id": "test-logs-package-policy-no-output",
|
||||
"meta": Object {
|
||||
"package": Object {
|
||||
"name": "system",
|
||||
"version": "1.0.0",
|
||||
},
|
||||
},
|
||||
"name": "test-policy-2",
|
||||
"package_policy_id": "package-policy-no-output",
|
||||
"revision": 1,
|
||||
"streams": Array [
|
||||
Object {
|
||||
"data_stream": Object {
|
||||
"dataset": "some-logs",
|
||||
"type": "logs",
|
||||
},
|
||||
"id": "test-logs",
|
||||
},
|
||||
],
|
||||
"type": "test-logs",
|
||||
"use_output": "data-output-id",
|
||||
},
|
||||
],
|
||||
"output_permissions": Object {
|
||||
"data-output-id": Object {
|
||||
"_elastic_agent_checks": Object {
|
||||
"cluster": Array [
|
||||
"monitor",
|
||||
],
|
||||
},
|
||||
"package-policy-no-output": Object {
|
||||
"indices": Array [
|
||||
Object {
|
||||
"names": Array [
|
||||
"logs-some-logs-defaultspace",
|
||||
],
|
||||
"privileges": Array [
|
||||
"auto_configure",
|
||||
"create_doc",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"default": Object {
|
||||
"_elastic_agent_checks": Object {
|
||||
"cluster": Array [
|
||||
"monitor",
|
||||
],
|
||||
},
|
||||
"_elastic_agent_monitoring": Object {
|
||||
"indices": Array [
|
||||
Object {
|
||||
"names": Array [],
|
||||
"privileges": Array [],
|
||||
},
|
||||
],
|
||||
},
|
||||
"package-policy-using-output": Object {
|
||||
"indices": Array [
|
||||
Object {
|
||||
"names": Array [
|
||||
"logs-some-logs-policyspace",
|
||||
],
|
||||
"privileges": Array [
|
||||
"auto_configure",
|
||||
"create_doc",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
"outputs": Object {
|
||||
"data-output-id": Object {
|
||||
"hosts": Array [
|
||||
"http://es-data.co:9201",
|
||||
],
|
||||
"preset": "balanced",
|
||||
"type": "elasticsearch",
|
||||
},
|
||||
"default": Object {
|
||||
"hosts": Array [
|
||||
"http://127.0.0.1:9201",
|
||||
],
|
||||
"preset": "balanced",
|
||||
"type": "elasticsearch",
|
||||
},
|
||||
},
|
||||
"revision": 1,
|
||||
"secret_references": Array [],
|
||||
"signed": Object {
|
||||
"data": "",
|
||||
"signature": "",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`getFullAgentPolicy should return the right outputs and permissions when package policies use their own outputs 1`] = `
|
||||
Object {
|
||||
"agent": Object {
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue