[Fleet] Do not use async method in plugin setup|start (#100033)

This commit is contained in:
Nicolas Chaulet 2021-05-13 14:08:33 -04:00 committed by GitHub
parent da048be1f4
commit f94bbc9343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 27 deletions

View file

@ -15,13 +15,6 @@ 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;
@ -29,8 +22,6 @@ export interface FleetConfigType {
fleet_server?: {
hosts?: string[];
};
agentPolicyRolloutRateLimitIntervalMs: number;
agentPolicyRolloutRateLimitRequestPerInterval: number;
};
agentPolicies?: PreconfiguredAgentPolicy[];
packages?: PreconfiguredPackage[];

View file

@ -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,
},
};
};

View file

@ -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',
};

View file

@ -6,7 +6,6 @@
*/
import type { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import type {
CoreSetup,
CoreStart,
@ -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'];
@ -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;
@ -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);
@ -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,

View file

@ -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 {
@ -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();
@ -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$);
}