mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Ingest Manager] Fix agent ack after input format change (#70335)
This commit is contained in:
parent
f3c393eaaf
commit
8903d3427e
3 changed files with 32 additions and 15 deletions
|
@ -139,9 +139,11 @@ describe('test agent acks services', () => {
|
||||||
name: 'system-1',
|
name: 'system-1',
|
||||||
type: 'logs',
|
type: 'logs',
|
||||||
use_output: 'default',
|
use_output: 'default',
|
||||||
package: {
|
meta: {
|
||||||
name: 'system',
|
package: {
|
||||||
version: '0.3.0',
|
name: 'system',
|
||||||
|
version: '0.3.0',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
dataset: {
|
dataset: {
|
||||||
namespace: 'default',
|
namespace: 'default',
|
||||||
|
@ -279,9 +281,11 @@ describe('test agent acks services', () => {
|
||||||
name: 'system-1',
|
name: 'system-1',
|
||||||
type: 'logs',
|
type: 'logs',
|
||||||
use_output: 'default',
|
use_output: 'default',
|
||||||
package: {
|
meta: {
|
||||||
name: 'system',
|
package: {
|
||||||
version: '0.3.0',
|
name: 'system',
|
||||||
|
version: '0.3.0',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
dataset: {
|
dataset: {
|
||||||
namespace: 'default',
|
namespace: 'default',
|
||||||
|
|
|
@ -92,8 +92,9 @@ function getLatestConfigIfUpdated(agent: Agent, actions: AgentAction[]) {
|
||||||
|
|
||||||
function buildUpdateAgentConfig(agentId: string, config: FullAgentConfig) {
|
function buildUpdateAgentConfig(agentId: string, config: FullAgentConfig) {
|
||||||
const packages = config.inputs.reduce<string[]>((acc, input) => {
|
const packages = config.inputs.reduce<string[]>((acc, input) => {
|
||||||
if (input.package && input.package.name && acc.indexOf(input.package.name) < 0) {
|
const packageName = input.meta?.package?.name;
|
||||||
return [input.package.name, ...acc];
|
if (packageName && acc.indexOf(packageName) < 0) {
|
||||||
|
return [packageName, ...acc];
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
@ -30,7 +30,8 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
it('should work', async () => {
|
it('should work', async () => {
|
||||||
const kibanaVersionAccessor = kibanaServer.version;
|
const kibanaVersionAccessor = kibanaServer.version;
|
||||||
const kibanaVersion = await kibanaVersionAccessor.get();
|
const kibanaVersion = await kibanaVersionAccessor.get();
|
||||||
// 1. Get enrollment token
|
|
||||||
|
// Get enrollment token
|
||||||
const { body: enrollmentApiKeysResponse } = await supertest
|
const { body: enrollmentApiKeysResponse } = await supertest
|
||||||
.get(`/api/ingest_manager/fleet/enrollment-api-keys`)
|
.get(`/api/ingest_manager/fleet/enrollment-api-keys`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
@ -44,7 +45,7 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
|
|
||||||
expect(enrollmentApiKeyResponse.item).to.have.key('api_key');
|
expect(enrollmentApiKeyResponse.item).to.have.key('api_key');
|
||||||
const enrollmentAPIToken = enrollmentApiKeyResponse.item.api_key;
|
const enrollmentAPIToken = enrollmentApiKeyResponse.item.api_key;
|
||||||
// 2. Enroll agent
|
// Enroll agent
|
||||||
const { body: enrollmentResponse } = await supertestWithoutAuth
|
const { body: enrollmentResponse } = await supertestWithoutAuth
|
||||||
.post(`/api/ingest_manager/fleet/agents/enroll`)
|
.post(`/api/ingest_manager/fleet/agents/enroll`)
|
||||||
.set('kbn-xsrf', 'xxx')
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
@ -63,7 +64,7 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
|
|
||||||
const agentAccessAPIKey = enrollmentResponse.item.access_api_key;
|
const agentAccessAPIKey = enrollmentResponse.item.access_api_key;
|
||||||
|
|
||||||
// 3. agent checkin
|
// Agent checkin
|
||||||
const { body: checkinApiResponse } = await supertestWithoutAuth
|
const { body: checkinApiResponse } = await supertestWithoutAuth
|
||||||
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
||||||
.set('kbn-xsrf', 'xx')
|
.set('kbn-xsrf', 'xx')
|
||||||
|
@ -79,7 +80,7 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
const configChangeAction = checkinApiResponse.actions[0];
|
const configChangeAction = checkinApiResponse.actions[0];
|
||||||
const defaultOutputApiKey = configChangeAction.data.config.outputs.default.api_key;
|
const defaultOutputApiKey = configChangeAction.data.config.outputs.default.api_key;
|
||||||
|
|
||||||
// 4. ack actions
|
// Ack actions
|
||||||
const { body: ackApiResponse } = await supertestWithoutAuth
|
const { body: ackApiResponse } = await supertestWithoutAuth
|
||||||
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/acks`)
|
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/acks`)
|
||||||
.set('Authorization', `ApiKey ${agentAccessAPIKey}`)
|
.set('Authorization', `ApiKey ${agentAccessAPIKey}`)
|
||||||
|
@ -101,7 +102,7 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(ackApiResponse.success).to.eql(true);
|
expect(ackApiResponse.success).to.eql(true);
|
||||||
|
|
||||||
// 4. second agent checkin
|
// Second agent checkin
|
||||||
const { body: secondCheckinApiResponse } = await supertestWithoutAuth
|
const { body: secondCheckinApiResponse } = await supertestWithoutAuth
|
||||||
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
||||||
.set('kbn-xsrf', 'xx')
|
.set('kbn-xsrf', 'xx')
|
||||||
|
@ -113,14 +114,25 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
expect(secondCheckinApiResponse.success).to.eql(true);
|
expect(secondCheckinApiResponse.success).to.eql(true);
|
||||||
expect(secondCheckinApiResponse.actions).length(0);
|
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
|
const { body: unenrollResponse } = await supertest
|
||||||
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/unenroll`)
|
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/unenroll`)
|
||||||
.set('kbn-xsrf', 'xx')
|
.set('kbn-xsrf', 'xx')
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(unenrollResponse.success).to.eql(true);
|
expect(unenrollResponse.success).to.eql(true);
|
||||||
|
|
||||||
// 6. Checkin after unenrollment
|
// Checkin after unenrollment
|
||||||
await supertestWithoutAuth
|
await supertestWithoutAuth
|
||||||
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
.post(`/api/ingest_manager/fleet/agents/${enrollmentResponse.item.id}/checkin`)
|
||||||
.set('kbn-xsrf', 'xx')
|
.set('kbn-xsrf', 'xx')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue