-
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.
[Ingest Manager] add upgrade action (#77412)
* at agents/agent-id/upgrade endpoint * handle upgrade ack * let upgrade endpoint accept url and version * wrap action data in data prop * decrypt data of actions * type upgrade action and decrypt data in ack * error if trying to update to diff version of kibana * add some integration tests * untype * fix test * update integration test * reset upgraded_at when upgrading * use defaultIngestErrorHandler * use ack_data instead of data * copy data to ack_data
- Loading branch information
Showing
16 changed files
with
292 additions
and
11 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
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
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/ingest_manager/server/routes/agent/upgrade_handler.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,47 @@ | ||
/* | ||
* 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 { RequestHandler } from 'src/core/server'; | ||
import { TypeOf } from '@kbn/config-schema'; | ||
import { PostAgentUpgradeResponse } from '../../../common/types'; | ||
import { PostAgentUpgradeRequestSchema } from '../../types'; | ||
import * as AgentService from '../../services/agents'; | ||
import { appContextService } from '../../services'; | ||
import { defaultIngestErrorHandler } from '../../errors'; | ||
|
||
export const postAgentUpgradeHandler: RequestHandler< | ||
TypeOf<typeof PostAgentUpgradeRequestSchema.params>, | ||
undefined, | ||
TypeOf<typeof PostAgentUpgradeRequestSchema.body> | ||
> = async (context, request, response) => { | ||
const soClient = context.core.savedObjects.client; | ||
const { version, source_uri: sourceUri } = request.body; | ||
|
||
// temporarily only allow upgrading to the same version as the installed kibana version | ||
const kibanaVersion = appContextService.getKibanaVersion(); | ||
if (kibanaVersion !== version) { | ||
return response.customError({ | ||
statusCode: 400, | ||
body: { | ||
message: `cannot upgrade agent to ${version} because it is different than the installed kibana version ${kibanaVersion}`, | ||
}, | ||
}); | ||
} | ||
|
||
try { | ||
await AgentService.sendUpgradeAgentAction({ | ||
soClient, | ||
agentId: request.params.agentId, | ||
version, | ||
sourceUri, | ||
}); | ||
|
||
const body: PostAgentUpgradeResponse = {}; | ||
return response.ok({ body }); | ||
} catch (error) { | ||
return defaultIngestErrorHandler({ error, response }); | ||
} | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/ingest_manager/server/services/agents/upgrade.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,61 @@ | ||
/* | ||
* 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 { SavedObjectsClientContract } from 'src/core/server'; | ||
import { AgentSOAttributes, AgentAction, AgentActionSOAttributes } from '../../types'; | ||
import { AGENT_ACTION_SAVED_OBJECT_TYPE, AGENT_SAVED_OBJECT_TYPE } from '../../constants'; | ||
import { createAgentAction } from './actions'; | ||
|
||
export async function sendUpgradeAgentAction({ | ||
soClient, | ||
agentId, | ||
version, | ||
sourceUri, | ||
}: { | ||
soClient: SavedObjectsClientContract; | ||
agentId: string; | ||
version: string; | ||
sourceUri: string; | ||
}) { | ||
const now = new Date().toISOString(); | ||
const data = { | ||
version, | ||
source_uri: sourceUri, | ||
}; | ||
await createAgentAction(soClient, { | ||
agent_id: agentId, | ||
created_at: now, | ||
data, | ||
ack_data: data, | ||
type: 'UPGRADE', | ||
}); | ||
await soClient.update<AgentSOAttributes>(AGENT_SAVED_OBJECT_TYPE, agentId, { | ||
upgraded_at: undefined, | ||
upgrade_started_at: now, | ||
}); | ||
} | ||
|
||
export async function ackAgentUpgraded( | ||
soClient: SavedObjectsClientContract, | ||
agentAction: AgentAction | ||
) { | ||
const { | ||
attributes: { ack_data: ackData }, | ||
} = await soClient.get<AgentActionSOAttributes>(AGENT_ACTION_SAVED_OBJECT_TYPE, agentAction.id); | ||
if (!ackData) throw new Error('data missing from UPGRADE action'); | ||
const { version } = JSON.parse(ackData); | ||
if (!version) throw new Error('version missing from UPGRADE action'); | ||
await soClient.update<AgentSOAttributes>(AGENT_SAVED_OBJECT_TYPE, agentAction.agent_id, { | ||
upgraded_at: new Date().toISOString(), | ||
local_metadata: { | ||
elastic: { | ||
agent: { | ||
version, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} |
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
Oops, something went wrong.