Skip to content

Commit

Permalink
[8.13][Fleet] Backport output health fix (using output id instead of …
Browse files Browse the repository at this point in the history
…"default" for non-elasticsearch outputs) (#179406)

## Summary

Backport #178857 and
#179218 to 8.13
Closes #177927
  • Loading branch information
juliaElastic authored Mar 26, 2024
1 parent 4b22c83 commit 55144fa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ jest.mock('../output', () => {
type: 'elasticsearch',
hosts: ['http://127.0.0.1:9201'],
},
'test-remote-id': {
id: 'test-remote-id',
is_default: true,
is_default_monitoring: true,
name: 'default',
// @ts-ignore
type: 'remote_elasticsearch',
hosts: ['http://127.0.0.1:9201'],
},
};
return {
outputService: {
Expand Down Expand Up @@ -375,6 +384,23 @@ describe('getFullAgentPolicy', () => {
expect(agentPolicy?.outputs.default).toBeDefined();
});

it('should use output id as the default policy id when remote elasticsearch', async () => {
mockAgentPolicy({
id: 'policy',
status: 'active',
package_policies: [],
is_managed: false,
namespace: 'default',
revision: 1,
data_output_id: 'test-remote-id',
monitoring_output_id: 'test-remote-id',
});

const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');

expect(agentPolicy?.outputs['test-remote-id']).toBeDefined();
});

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 @@ -31,8 +31,12 @@ import type {
PackageInfo,
} from '../../../common/types';
import { agentPolicyService } from '../agent_policy';
import { dataTypes, kafkaCompressionType, outputType } from '../../../common/constants';
import { DEFAULT_OUTPUT } from '../../constants';
import {
dataTypes,
DEFAULT_OUTPUT,
kafkaCompressionType,
outputType,
} from '../../../common/constants';

import { getPackageInfo } from '../epm/packages';
import { pkgToPkgKey, splitPkgKey } from '../epm/registry';
Expand Down Expand Up @@ -494,10 +498,9 @@ export function transformOutputToFullPolicyOutput(
* we use "default" for the default policy to avoid breaking changes
*/
function getOutputIdForAgentPolicy(output: Output) {
if (output.is_default) {
if (output.is_default && output.type === outputType.Elasticsearch) {
return DEFAULT_OUTPUT.name;
}

return output.id;
}

Expand Down

0 comments on commit 55144fa

Please sign in to comment.