Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Manager] Fix agent ack after input format change #70335

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/agents/acks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ function getLatestConfigIfUpdated(agent: Agent, actions: AgentAction[]) {

function buildUpdateAgentConfig(agentId: string, config: FullAgentConfig) {
const packages = config.inputs.reduce<string[]>((acc, input) => {
if (input.package && input.package.name && acc.indexOf(input.package.name) < 0) {
return [input.package.name, ...acc];
const packageName = input.meta?.package?.name;
if (packageName && acc.indexOf(packageName) < 0) {
return [packageName, ...acc];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle cases where packages are removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebuild this array each time from the full config, it should work for package removed too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to add a test case for this if possible

}
return acc;
}, []);
Expand Down
31 changes: 23 additions & 8 deletions x-pack/test/api_integration/apis/fleet/agent_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function (providerContext: FtrProviderContext) {
});

it('should work', async () => {
// 1. Get enrollment token
// Get enrollment token
const { body: enrollmentApiKeysResponse } = await supertest
.get(`/api/ingest_manager/fleet/enrollment-api-keys`)
.expect(200);
Expand All @@ -40,15 +40,19 @@ export default function (providerContext: FtrProviderContext) {

expect(enrollmentApiKeyResponse.item).to.have.key('api_key');
const enrollmentAPIToken = enrollmentApiKeyResponse.item.api_key;
// 2. Enroll agent
// Enroll agent
const { body: enrollmentResponse } = await supertestWithoutAuth
.post(`/api/ingest_manager/fleet/agents/enroll`)
.set('kbn-xsrf', 'xxx')
.set('Authorization', `ApiKey ${enrollmentAPIToken}`)
.send({
type: 'PERMANENT',
metadata: {
local: {},
local: {
elastic: {
agent: { version: 'TODO' },
},
},
user_provided: {},
},
})
Expand All @@ -57,7 +61,7 @@ export default function (providerContext: FtrProviderContext) {

const agentAccessAPIKey = enrollmentResponse.item.access_api_key;

// 3. agent checkin
// Agent checkin
const { body: checkinApiResponse } = await supertestWithoutAuth
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
.set('kbn-xsrf', 'xx')
Expand All @@ -73,7 +77,7 @@ export default function (providerContext: FtrProviderContext) {
const configChangeAction = checkinApiResponse.actions[0];
const defaultOutputApiKey = configChangeAction.data.config.outputs.default.api_key;

// 4. ack actions
// Ack actions
const { body: ackApiResponse } = await supertestWithoutAuth
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/acks`)
.set('Authorization', `ApiKey ${agentAccessAPIKey}`)
Expand All @@ -95,7 +99,7 @@ export default function (providerContext: FtrProviderContext) {
.expect(200);
expect(ackApiResponse.success).to.eql(true);

// 4. second agent checkin
// Second agent checkin
const { body: secondCheckinApiResponse } = await supertestWithoutAuth
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
.set('kbn-xsrf', 'xx')
Expand All @@ -107,14 +111,25 @@ export default function (providerContext: FtrProviderContext) {
expect(secondCheckinApiResponse.success).to.eql(true);
expect(secondCheckinApiResponse.actions).length(0);

// 5. unenroll agent
// Get agent
const { body: getAgentApiResponse } = await supertest
.get(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}`)
.expect(200);

expect(getAgentApiResponse.success).to.eql(true);
expect(getAgentApiResponse.item.packages).to.contain(
'system',
"Agent should run the 'system' package"
);

// Unenroll agent
const { body: unenrollResponse } = await supertest
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/unenroll`)
.set('kbn-xsrf', 'xx')
.expect(200);
expect(unenrollResponse.success).to.eql(true);

// 6. Checkin after unenrollment
// Checkin after unenrollment
await supertestWithoutAuth
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
.set('kbn-xsrf', 'xx')
Expand Down