-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Add config revision to fleet agents (#60292)
- Loading branch information
Showing
8 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
x-pack/plugins/ingest_manager/server/services/agents/checkin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { shouldCreateConfigAction } from './checkin'; | ||
import { Agent } from '../../types'; | ||
|
||
function getAgent(data: Partial<Agent>) { | ||
return { actions: [], ...data } as Agent; | ||
} | ||
|
||
describe('Agent checkin service', () => { | ||
describe('shouldCreateConfigAction', () => { | ||
it('should return false if the agent do not have an assigned config', () => { | ||
const res = shouldCreateConfigAction(getAgent({})); | ||
|
||
expect(res).toBeFalsy(); | ||
}); | ||
|
||
it('should return true if this is agent first checkin', () => { | ||
const res = shouldCreateConfigAction(getAgent({ config_id: 'config1' })); | ||
|
||
expect(res).toBeTruthy(); | ||
}); | ||
|
||
it('should return false agent is already running latest revision', () => { | ||
const res = shouldCreateConfigAction( | ||
getAgent({ | ||
config_id: 'config1', | ||
last_checkin: '2018-01-02T00:00:00', | ||
config_revision: 1, | ||
config_newest_revision: 1, | ||
}) | ||
); | ||
|
||
expect(res).toBeFalsy(); | ||
}); | ||
|
||
it('should return false agent has already latest revision config change action', () => { | ||
const res = shouldCreateConfigAction( | ||
getAgent({ | ||
config_id: 'config1', | ||
last_checkin: '2018-01-02T00:00:00', | ||
config_revision: 1, | ||
config_newest_revision: 2, | ||
actions: [ | ||
{ | ||
id: 'action1', | ||
type: 'CONFIG_CHANGE', | ||
created_at: new Date().toISOString(), | ||
data: JSON.stringify({ | ||
config: { | ||
id: 'config1', | ||
revision: 2, | ||
}, | ||
}), | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
expect(res).toBeFalsy(); | ||
}); | ||
|
||
it('should return true agent has unrelated config change actions', () => { | ||
const res = shouldCreateConfigAction( | ||
getAgent({ | ||
config_id: 'config1', | ||
last_checkin: '2018-01-02T00:00:00', | ||
config_revision: 1, | ||
config_newest_revision: 2, | ||
actions: [ | ||
{ | ||
id: 'action1', | ||
type: 'CONFIG_CHANGE', | ||
created_at: new Date().toISOString(), | ||
data: JSON.stringify({ | ||
config: { | ||
id: 'config2', | ||
revision: 2, | ||
}, | ||
}), | ||
}, | ||
{ | ||
id: 'action1', | ||
type: 'CONFIG_CHANGE', | ||
created_at: new Date().toISOString(), | ||
data: JSON.stringify({ | ||
config: { | ||
id: 'config1', | ||
revision: 1, | ||
}, | ||
}), | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
expect(res).toBeTruthy(); | ||
}); | ||
|
||
it('should return true if this agent has a new revision', () => { | ||
const res = shouldCreateConfigAction( | ||
getAgent({ | ||
config_id: 'config1', | ||
last_checkin: '2018-01-02T00:00:00', | ||
config_revision: 1, | ||
config_newest_revision: 2, | ||
}) | ||
); | ||
|
||
expect(res).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters