Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -17675,6 +17675,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down Expand Up @@ -19722,6 +19729,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down Expand Up @@ -20206,6 +20220,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down
21 changes: 21 additions & 0 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -17675,6 +17675,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down Expand Up @@ -19722,6 +19729,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down Expand Up @@ -20206,6 +20220,13 @@
"nullable": true,
"type": "array"
},
"upgrade_attempts": {
"items": {
"type": "string"
},
"nullable": true,
"type": "array"
},
"upgrade_details": {
"additionalProperties": false,
"nullable": true,
Expand Down
15 changes: 15 additions & 0 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18992,6 +18992,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down Expand Up @@ -19447,6 +19452,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down Expand Up @@ -19790,6 +19800,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down
15 changes: 15 additions & 0 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21113,6 +21113,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down Expand Up @@ -21565,6 +21570,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down Expand Up @@ -21907,6 +21917,11 @@ paths:
type: string
nullable: true
type: array
upgrade_attempts:
items:
type: string
nullable: true
type: array
upgrade_details:
additionalProperties: false
nullable: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ export const FLEET_ENROLLMENT_API_PREFIX = 'fleet-enrollment-api-keys';
export const REQUEST_DIAGNOSTICS_TIMEOUT_MS = 3 * 60 * 60 * 1000; // 3 hours;

export * from './mappings';

export const AUTO_UPGRADE_DEFAULT_RETRIES = ['30m', '1h', '2h', '4h', '8h', '16h', '24h'];
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ export const AGENT_MAPPINGS = {
},
},
},
upgrade_attempts: {
type: 'date',
},
// added to allow validation on status field
status: {
type: 'keyword',
Expand Down
3 changes: 3 additions & 0 deletions x-pack/platform/plugins/shared/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export interface FleetConfigType {
};
};
createArtifactsBulkBatchSize?: number;
autoUpgrades?: {
retryDelays?: string[];
};
}

// Calling Object.entries(PackagesGroupedByStatus) gave `status: string`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ interface AgentBase {
upgraded_at?: string | null;
upgrade_started_at?: string | null;
upgrade_details?: AgentUpgradeDetails;
upgrade_attempts?: string[] | null;
access_api_key_id?: string;
default_api_key?: string;
default_api_key_id?: string;
Expand Down Expand Up @@ -275,6 +276,10 @@ export interface FleetServerAgent {
* Upgrade state of the Elastic Agent
*/
upgrade_details?: AgentUpgradeDetails;
/**
* List of timestamps of attempts of Elastic Agent automatic upgrades
*/
upgrade_attempts?: string[] | null;
access_api_key_id?: string;
agent?: FleetServerAgentMetadata;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('SearchBar', () => {

describe('getFieldSpecs', () => {
it('returns fieldSpecs for Fleet agents', () => {
expect(getFieldSpecs(AGENTS_INDEX, AGENTS_PREFIX)).toHaveLength(73);
expect(getFieldSpecs(AGENTS_INDEX, AGENTS_PREFIX)).toHaveLength(74);
});

it('returns fieldSpecs for Fleet enrollment tokens', () => {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/platform/plugins/shared/fleet/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ export const config: PluginConfigDescriptor = {
min: 400,
})
),
autoUpgrades: schema.maybe(
schema.object({
retryDelays: schema.maybe(schema.arrayOf(schema.string())),
})
),
},
{
validate: (configToValidate) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function searchHitToAgent(
upgraded_at: hit._source?.upgraded_at,
upgrade_started_at: hit._source?.upgrade_started_at,
upgrade_details: hit._source?.upgrade_details,
upgrade_attempts: hit._source?.upgrade_attempts,
access_api_key_id: hit._source?.access_api_key_id,
default_api_key_id: hit._source?.default_api_key_id,
policy_id: hit._source?.policy_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,22 @@ export async function sendUpgradeAgentsActions(

return await upgradeBatch(esClient, givenAgents, outgoingErrors, options, currentSpaceId);
}

export async function sendAutomaticUpgradeAgentsActions(
soClient: SavedObjectsClientContract,
esClient: ElasticsearchClient,
options: {
agents: Agent[];
version: string;
upgradeDurationSeconds?: number;
}
): Promise<{ actionId: string }> {
const currentSpaceId = getCurrentNamespace(soClient);
return await upgradeBatch(
esClient,
options.agents,
{},
{ ...options, isAutomatic: true },
currentSpaceId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import type { ElasticsearchClient } from '@kbn/core/server';

import { v4 as uuidv4 } from 'uuid';
import moment from 'moment';
import semverGte from 'semver/functions/gte';

import {
getRecentUpgradeInfoForAgent,
getNotUpgradeableMessage,
isAgentUpgradeableToVersion,
AGENT_UPGARDE_DETAILS_SUPPORTED_VERSION,
} from '../../../common/services';

import type { Agent } from '../../types';
Expand Down Expand Up @@ -168,6 +170,10 @@ export async function upgradeBatch(
data: {
upgraded_at: null,
upgrade_started_at: now,
...(options.isAutomatic &&
semverGte(agent.agent?.version ?? '0.0.0', AGENT_UPGARDE_DETAILS_SUPPORTED_VERSION)
? { upgrade_attempts: [now, ...(agent.upgrade_attempts ?? [])] }
: {}),
},
})),
errors
Expand Down
Loading
Loading