Skip to content

Commit

Permalink
[Fleet] Wire Fleet setup status to core Kibana status API (#120020)
Browse files Browse the repository at this point in the history
* Wire Fleet setup status to core Kibana status API

* Remove fake error from testing 🙃

* Apply suggestion for PR review

Co-authored-by: Josh Dover <[email protected]>

* Add error message to meta upon Fleet setup failure

* Mark fleet as available if setup fails - for now

* Fix failing API key tests

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Josh Dover <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2021
1 parent 80660f1 commit c7a06cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 36 additions & 1 deletion x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import type {
CoreSetup,
CoreStart,
Expand All @@ -16,13 +17,18 @@ import type {
SavedObjectsServiceStart,
HttpServiceSetup,
KibanaRequest,
ServiceStatus,
ElasticsearchClient,
} from 'kibana/server';
import type { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import type { TelemetryPluginSetup, TelemetryPluginStart } from 'src/plugins/telemetry/server';

import { DEFAULT_APP_CATEGORIES, SavedObjectsClient } from '../../../../src/core/server';
import {
DEFAULT_APP_CATEGORIES,
SavedObjectsClient,
ServiceStatusLevels,
} from '../../../../src/core/server';
import type { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
import type { LicensingPluginSetup, ILicense } from '../../licensing/server';
import type {
Expand Down Expand Up @@ -182,6 +188,7 @@ export class FleetPlugin
private securitySetup?: SecurityPluginSetup;
private encryptedSavedObjectsSetup?: EncryptedSavedObjectsPluginSetup;
private readonly telemetryEventsSender: TelemetryEventsSender;
private readonly fleetStatus$: BehaviorSubject<ServiceStatus>;

private agentService?: AgentService;

Expand All @@ -193,6 +200,11 @@ export class FleetPlugin
this.logger = this.initializerContext.logger.get();
this.configInitialValue = this.initializerContext.config.get();
this.telemetryEventsSender = new TelemetryEventsSender(this.logger.get('telemetry_events'));

this.fleetStatus$ = new BehaviorSubject<ServiceStatus>({
level: ServiceStatusLevels.unavailable,
summary: 'Fleet is unavailable',
});
}

public setup(core: CoreSetup, deps: FleetSetupDeps) {
Expand All @@ -203,6 +215,8 @@ export class FleetPlugin
this.securitySetup = deps.security;
const config = this.configInitialValue;

core.status.set(this.fleetStatus$.asObservable());

registerSavedObjects(core.savedObjects, deps.encryptedSavedObjects);
registerEncryptedSavedObjects(deps.encryptedSavedObjects);

Expand Down Expand Up @@ -357,13 +371,33 @@ export class FleetPlugin

const fleetSetupPromise = (async () => {
try {
this.fleetStatus$.next({
level: ServiceStatusLevels.degraded,
summary: 'Fleet is setting up',
});

await setupFleet(
new SavedObjectsClient(core.savedObjects.createInternalRepository()),
core.elasticsearch.client.asInternalUser
);

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

this.fleetStatus$.next({
// As long as Fleet has a dependency on EPR, we can't reliably set Kibana status to `unavailable` here.
// See https://github.com/elastic/kibana/issues/120237
level: ServiceStatusLevels.available,
summary: 'Fleet setup failed',
meta: {
error: error.message,
},
});
}
})();

Expand Down Expand Up @@ -400,6 +434,7 @@ export class FleetPlugin
appContextService.stop();
licenseService.stop();
this.telemetryEventsSender.stop();
this.fleetStatus$.complete();
}

private setupAgentService(internalEsClient: ElasticsearchClient): AgentService {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/test/functional/apps/api_keys/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await security.testUser.setRoles(['kibana_admin']);
await security.testUser.setRoles(['test_api_keys']);
await pageObjects.common.navigateToApp('apiKeys');

// Delete any API keys created outside of these tests
await pageObjects.apiKeys.bulkDeleteApiKeys();
});

afterEach(async () => {
Expand Down

0 comments on commit c7a06cd

Please sign in to comment.