Skip to content

Commit 2d4b943

Browse files
committed
[Ingest Manager] Fix agent policy bump revision to create only one POLICY_CHANGE action (#80081)
1 parent 71812f7 commit 2d4b943

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { savedObjectsClientMock } from 'src/core/server/mocks';
88
import { agentPolicyService } from './agent_policy';
9+
import { agentPolicyUpdateEventHandler } from './agent_policy_update';
910
import { Output } from '../types';
1011

1112
function getSavedObjectMock(agentPolicyAttributes: any) {
@@ -59,7 +60,42 @@ jest.mock('./output', () => {
5960
};
6061
});
6162

63+
jest.mock('./agent_policy_update');
64+
65+
function getAgentPolicyUpdateMock() {
66+
return (agentPolicyUpdateEventHandler as unknown) as jest.Mock<
67+
typeof agentPolicyUpdateEventHandler
68+
>;
69+
}
70+
6271
describe('agent policy', () => {
72+
beforeEach(() => {
73+
getAgentPolicyUpdateMock().mockClear();
74+
});
75+
describe('bumpRevision', () => {
76+
it('should call agentPolicyUpdateEventHandler with updated event once', async () => {
77+
const soClient = getSavedObjectMock({
78+
revision: 1,
79+
monitoring_enabled: ['metrics'],
80+
});
81+
await agentPolicyService.bumpRevision(soClient, 'agent-policy');
82+
83+
expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1);
84+
});
85+
});
86+
87+
describe('bumpAllAgentPolicies', () => {
88+
it('should call agentPolicyUpdateEventHandler with updated event once', async () => {
89+
const soClient = getSavedObjectMock({
90+
revision: 1,
91+
monitoring_enabled: ['metrics'],
92+
});
93+
await agentPolicyService.bumpAllAgentPolicies(soClient);
94+
95+
expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1);
96+
});
97+
});
98+
6399
describe('getFullAgentPolicy', () => {
64100
it('should return a policy without monitoring if monitoring is not enabled', async () => {
65101
const soClient = getSavedObjectMock({

x-pack/plugins/ingest_manager/server/services/agent_policy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ class AgentPolicyService {
297297
): Promise<AgentPolicy> {
298298
const res = await this._update(soClient, id, {}, options?.user);
299299

300-
await this.triggerAgentPolicyUpdatedEvent(soClient, 'updated', id);
301-
302300
return res;
303301
}
304302
public async bumpAllAgentPolicies(

0 commit comments

Comments
 (0)