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
1 change: 1 addition & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ xpack.fleet.internal.disableILMPolicies: true
xpack.fleet.internal.disableProxies: true
xpack.fleet.internal.activeAgentsSoftLimit: 25000
xpack.fleet.internal.onlyAllowAgentUpgradeToKnownVersions: true
xpack.fleet.internal.retrySetupOnBoot: true

# Cloud links
xpack.cloud.base_url: 'https://cloud.elastic.co'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@
"email-addresses": "^5.0.0",
"execa": "^5.1.1",
"expiry-js": "0.1.7",
"exponential-backoff": "^3.1.1",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kibana already has this dependency as a transitive dep, thought it made sense to just use it again here.

"extract-zip": "^2.0.1",
"fast-deep-equal": "^3.1.1",
"fflate": "^0.6.9",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface FleetConfigType {
fleetServerStandalone: boolean;
onlyAllowAgentUpgradeToKnownVersions: boolean;
activeAgentsSoftLimit?: number;
retrySetupOnBoot: boolean;
registry: {
kibanaVersionCheckEnabled: boolean;
capabilities: string[];
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export const config: PluginConfigDescriptor = {
min: 0,
})
),
retrySetupOnBoot: schema.boolean({ defaultValue: false }),
registry: schema.object(
{
kibanaVersionCheckEnabled: schema.boolean({ defaultValue: true }),
Expand Down
40 changes: 35 additions & 5 deletions x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { backOff } from 'exponential-backoff';
import type { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { take, filter } from 'rxjs/operators';
Expand Down Expand Up @@ -532,18 +533,47 @@ export class FleetPlugin
)
.toPromise();

await setupFleet(
new SavedObjectsClient(core.savedObjects.createInternalRepository()),
core.elasticsearch.client.asInternalUser
// Retry Fleet setup w/ backoff
await backOff(
async () => {
await setupFleet(
new SavedObjectsClient(core.savedObjects.createInternalRepository()),
core.elasticsearch.client.asInternalUser
);
},
{
// We only retry when this feature flag is enabled
numOfAttempts: this.configInitialValue.internal?.retrySetupOnBoot ? Infinity : 1,
// 250ms initial backoff
startingDelay: 250,
// 5m max backoff
maxDelay: 60000 * 5,
timeMultiple: 2,
// avoid HA contention with other Kibana instances
jitter: 'full',
retry: (error: any, attemptCount: number) => {
const summary = `Fleet setup attempt ${attemptCount} failed, will retry after backoff`;
logger.debug(summary, { error: { message: error } });

this.fleetStatus$.next({
level: ServiceStatusLevels.available,
summary,
meta: {
attemptCount,
error,
},
});
return true;
},
}
);

this.fleetStatus$.next({
level: ServiceStatusLevels.available,
summary: 'Fleet is available',
});
} catch (error) {
logger.warn('Fleet setup failed');
logger.warn(error);
logger.warn('Fleet setup failed', { error: { message: error } });

this.fleetStatus$.next({
// As long as Fleet has a dependency on EPR, we can't reliably set Kibana status to `unavailable` here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe('_installPackage', () => {
disableProxies: false,
fleetServerStandalone: false,
onlyAllowAgentUpgradeToKnownVersions: false,
retrySetupOnBoot: false,
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
Expand Down Expand Up @@ -192,6 +193,7 @@ describe('_installPackage', () => {
disableILMPolicies: false,
fleetServerStandalone: false,
onlyAllowAgentUpgradeToKnownVersions: false,
retrySetupOnBoot: false,
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
Expand Down Expand Up @@ -265,6 +267,7 @@ describe('_installPackage', () => {
disableProxies: false,
fleetServerStandalone: false,
onlyAllowAgentUpgradeToKnownVersions: false,
retrySetupOnBoot: false,
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
Expand Down