Skip to content

Commit

Permalink
[Fleet] Do not use async method in plugin setup|start (#100033) (#100062
Browse files Browse the repository at this point in the history
)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
  • Loading branch information
kibanamachine and nchaulet authored May 13, 2021
1 parent 2a85ef7 commit dbdd1d6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
9 changes: 0 additions & 9 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ export interface FleetConfigType {
registryProxyUrl?: string;
agents: {
enabled: boolean;
tlsCheckDisabled: boolean;
pollingRequestTimeout: number;
maxConcurrentConnections: number;
kibana: {
host?: string[] | string;
ca_sha256?: string;
};
elasticsearch: {
host?: string;
ca_sha256?: string;
};
fleet_server?: {
hosts?: string[];
};
agentPolicyRolloutRateLimitIntervalMs: number;
agentPolicyRolloutRateLimitRequestPerInterval: number;
};
agentPolicies?: PreconfiguredAgentPolicy[];
packages?: PreconfiguredPackage[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ export const createConfigurationMock = (): FleetConfigType => {
registryProxyUrl: '',
agents: {
enabled: true,
tlsCheckDisabled: true,
pollingRequestTimeout: 1000,
maxConcurrentConnections: 100,
kibana: {
host: '',
ca_sha256: '',
},
elasticsearch: {
host: '',
ca_sha256: '',
},
agentPolicyRolloutRateLimitIntervalMs: 100,
agentPolicyRolloutRateLimitRequestPerInterval: 1000,
},
};
};
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const createAppContextStartContractMock = (): FleetAppContext => {
security: securityMock.createStart(),
logger: loggingSystemMock.create().get(),
isProductionMode: true,
configInitialValue: {
agents: { enabled: true, elasticsearch: {} },
enabled: true,
},
kibanaVersion: '8.0.0',
kibanaBranch: 'master',
};
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import type {
CoreSetup,
CoreStart,
Expand Down Expand Up @@ -110,6 +109,7 @@ export interface FleetAppContext {
encryptedSavedObjectsSetup?: EncryptedSavedObjectsPluginSetup;
security?: SecurityPluginStart;
config$?: Observable<FleetConfigType>;
configInitialValue: FleetConfigType;
savedObjects: SavedObjectsServiceStart;
isProductionMode: PluginInitializerContext['env']['mode']['prod'];
kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
Expand Down Expand Up @@ -189,6 +189,7 @@ export class FleetPlugin
implements AsyncPlugin<FleetSetupContract, FleetStartContract, FleetSetupDeps, FleetStartDeps> {
private licensing$!: Observable<ILicense>;
private config$: Observable<FleetConfigType>;
private configInitialValue: FleetConfigType;
private cloud: CloudSetup | undefined;
private logger: Logger | undefined;

Expand All @@ -204,15 +205,15 @@ export class FleetPlugin
this.kibanaVersion = this.initializerContext.env.packageInfo.version;
this.kibanaBranch = this.initializerContext.env.packageInfo.branch;
this.logger = this.initializerContext.logger.get();
this.configInitialValue = this.initializerContext.config.get();
}

public async setup(core: CoreSetup, deps: FleetSetupDeps) {
public setup(core: CoreSetup, deps: FleetSetupDeps) {
this.httpSetup = core.http;
this.licensing$ = deps.licensing.license$;
this.encryptedSavedObjectsSetup = deps.encryptedSavedObjects;
this.cloud = deps.cloud;

const config = await this.config$.pipe(first()).toPromise();
const config = this.configInitialValue;

registerSavedObjects(core.savedObjects, deps.encryptedSavedObjects);
registerEncryptedSavedObjects(deps.encryptedSavedObjects);
Expand Down Expand Up @@ -279,13 +280,14 @@ export class FleetPlugin
}
}

public async start(core: CoreStart, plugins: FleetStartDeps): Promise<FleetStartContract> {
await appContextService.start({
public start(core: CoreStart, plugins: FleetStartDeps): FleetStartContract {
appContextService.start({
elasticsearch: core.elasticsearch,
data: plugins.data,
encryptedSavedObjectsStart: plugins.encryptedSavedObjects,
encryptedSavedObjectsSetup: this.encryptedSavedObjectsSetup,
security: plugins.security,
configInitialValue: this.configInitialValue,
config$: this.config$,
savedObjects: core.savedObjects,
isProductionMode: this.isProductionMode,
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/fleet/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { first } from 'rxjs/operators';
import { kibanaPackageJson } from '@kbn/utils';
import type { KibanaRequest } from 'src/core/server';
import type {
Expand Down Expand Up @@ -44,7 +43,7 @@ class AppContextService {
private httpSetup?: HttpServiceSetup;
private externalCallbacks: ExternalCallbacksStorage = new Map();

public async start(appContext: FleetAppContext) {
public start(appContext: FleetAppContext) {
this.data = appContext.data;
this.esClient = appContext.elasticsearch.client.asInternalUser;
this.encryptedSavedObjects = appContext.encryptedSavedObjectsStart?.getClient();
Expand All @@ -60,7 +59,7 @@ class AppContextService {

if (appContext.config$) {
this.config$ = appContext.config$;
const initialValue = await this.config$.pipe(first()).toPromise();
const initialValue = appContext.configInitialValue;
this.configSubject$ = new BehaviorSubject(initialValue);
this.config$.subscribe(this.configSubject$);
}
Expand Down

0 comments on commit dbdd1d6

Please sign in to comment.