Skip to content

Commit 28582f7

Browse files
committed
[Fleet] Add retry logic to automatic agent upgrades
1 parent 2f0bad7 commit 28582f7

File tree

14 files changed

+285
-68
lines changed

14 files changed

+285
-68
lines changed

docs/settings/fleet-settings.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Hostnames used by {agent} for accessing {es}.
5757
`xpack.fleet.agents.elasticsearch.ca_sha256`::
5858
Hash pin used for certificate verification. The pin is a base64-encoded string of the SHA-256 fingerprint.
5959

60+
`xpack.fleet.autoUpgrades.retryDelays`::
61+
List of delays for retrying failed automatic agent upgrades. Overrides default exponential backoff strategy.
62+
6063
[role="child_attributes"]
6164
==== Preconfiguration settings (for advanced use cases)
6265

oas_docs/output/kibana.serverless.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18928,6 +18928,11 @@ paths:
1892818928
upgraded_at:
1892918929
nullable: true
1893018930
type: string
18931+
upgrade_attempts:
18932+
nullable: true
18933+
type: array
18934+
items:
18935+
type: string
1893118936
user_provided_metadata:
1893218937
additionalProperties: {}
1893318938
type: object
@@ -19383,6 +19388,11 @@ paths:
1938319388
upgraded_at:
1938419389
nullable: true
1938519390
type: string
19391+
upgrade_attempts:
19392+
nullable: true
19393+
type: array
19394+
items:
19395+
type: string
1938619396
user_provided_metadata:
1938719397
additionalProperties: {}
1938819398
type: object
@@ -19726,6 +19736,11 @@ paths:
1972619736
upgraded_at:
1972719737
nullable: true
1972819738
type: string
19739+
upgrade_attempts:
19740+
nullable: true
19741+
type: array
19742+
items:
19743+
type: string
1972919744
user_provided_metadata:
1973019745
additionalProperties: {}
1973119746
type: object

oas_docs/output/kibana.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21049,6 +21049,11 @@ paths:
2104921049
upgraded_at:
2105021050
nullable: true
2105121051
type: string
21052+
upgrade_attempts:
21053+
nullable: true
21054+
type: array
21055+
items:
21056+
type: string
2105221057
user_provided_metadata:
2105321058
additionalProperties: {}
2105421059
type: object
@@ -21501,6 +21506,11 @@ paths:
2150121506
upgraded_at:
2150221507
nullable: true
2150321508
type: string
21509+
upgrade_attempts:
21510+
nullable: true
21511+
type: array
21512+
items:
21513+
type: string
2150421514
user_provided_metadata:
2150521515
additionalProperties: {}
2150621516
type: object
@@ -21843,6 +21853,11 @@ paths:
2184321853
upgraded_at:
2184421854
nullable: true
2184521855
type: string
21856+
upgrade_attempts:
21857+
nullable: true
21858+
type: array
21859+
items:
21860+
type: string
2184621861
user_provided_metadata:
2184721862
additionalProperties: {}
2184821863
type: object

x-pack/platform/plugins/shared/fleet/common/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ export const FLEET_ENROLLMENT_API_PREFIX = 'fleet-enrollment-api-keys';
5858
export const REQUEST_DIAGNOSTICS_TIMEOUT_MS = 3 * 60 * 60 * 1000; // 3 hours;
5959

6060
export * from './mappings';
61+
62+
export const AUTO_UPGRADE_DEFAULT_RETRIES = ['30m', '1h', '2h', '4h', '8h', '16h', '24h'];

x-pack/platform/plugins/shared/fleet/common/constants/mappings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ export const AGENT_MAPPINGS = {
363363
},
364364
},
365365
},
366+
upgrade_attempts: {
367+
type: 'date',
368+
},
366369
// added to allow validation on status field
367370
status: {
368371
type: 'keyword',

x-pack/platform/plugins/shared/fleet/common/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export interface FleetConfigType {
8484
};
8585
};
8686
createArtifactsBulkBatchSize?: number;
87+
autoUpgrades: {
88+
retryDelays: string[];
89+
};
8790
}
8891

8992
// Calling Object.entries(PackagesGroupedByStatus) gave `status: string`

x-pack/platform/plugins/shared/fleet/common/types/models/agent.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ interface AgentBase {
9999
upgraded_at?: string | null;
100100
upgrade_started_at?: string | null;
101101
upgrade_details?: AgentUpgradeDetails;
102+
upgrade_attempts?: string[] | null;
102103
access_api_key_id?: string;
103104
default_api_key?: string;
104105
default_api_key_id?: string;
@@ -275,6 +276,10 @@ export interface FleetServerAgent {
275276
* Upgrade state of the Elastic Agent
276277
*/
277278
upgrade_details?: AgentUpgradeDetails;
279+
/**
280+
* List of timestamps of attempts of Elastic Agent automatic upgrades
281+
*/
282+
upgrade_attempts?: string[] | null;
278283
access_api_key_id?: string;
279284
agent?: FleetServerAgentMetadata;
280285
/**

x-pack/platform/plugins/shared/fleet/server/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { TypeOf } from '@kbn/config-schema';
1212
import type { PluginConfigDescriptor } from '@kbn/core/server';
1313

1414
import { isValidExperimentalValue } from '../common/experimental_features';
15+
import { AUTO_UPGRADE_DEFAULT_RETRIES } from '../common/constants';
1516

1617
import {
1718
PreconfiguredPackagesSchema,
@@ -282,6 +283,11 @@ export const config: PluginConfigDescriptor = {
282283
min: 400,
283284
})
284285
),
286+
autoUpgrades: schema.object({
287+
retryDelays: schema.arrayOf(schema.string(), {
288+
defaultValue: AUTO_UPGRADE_DEFAULT_RETRIES,
289+
}),
290+
}),
285291
},
286292
{
287293
validate: (configToValidate) => {

x-pack/platform/plugins/shared/fleet/server/services/agents/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function searchHitToAgent(
6969
upgraded_at: hit._source?.upgraded_at,
7070
upgrade_started_at: hit._source?.upgrade_started_at,
7171
upgrade_details: hit._source?.upgrade_details,
72+
upgrade_attempts: hit._source?.upgrade_attempts,
7273
access_api_key_id: hit._source?.access_api_key_id,
7374
default_api_key_id: hit._source?.default_api_key_id,
7475
policy_id: hit._source?.policy_id,

x-pack/platform/plugins/shared/fleet/server/services/agents/upgrade.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,22 @@ export async function sendUpgradeAgentsActions(
125125

126126
return await upgradeBatch(esClient, givenAgents, outgoingErrors, options, currentSpaceId);
127127
}
128+
129+
export async function sendAutomaticUpgradeAgentsActions(
130+
soClient: SavedObjectsClientContract,
131+
esClient: ElasticsearchClient,
132+
options: {
133+
agents: Agent[];
134+
version: string;
135+
upgradeDurationSeconds?: number;
136+
}
137+
): Promise<{ actionId: string }> {
138+
const currentSpaceId = getCurrentNamespace(soClient);
139+
return await upgradeBatch(
140+
esClient,
141+
options.agents,
142+
{},
143+
{ ...options, isAutomatic: true },
144+
currentSpaceId
145+
);
146+
}

0 commit comments

Comments
 (0)