Skip to content

Commit

Permalink
[Alerting] Add telemetry to task manager health API to determine what…
Browse files Browse the repository at this point in the history
… users are accessing it (#119349)
  • Loading branch information
ymao1 authored Nov 24, 2021
1 parent 90bebce commit 6eae6b8
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ describe('features', () => {
actions.version,
...(expectDecryptedTelemetry ? [actions.api.get('decryptedTelemetry')] : []),
...(expectGetFeatures ? [actions.api.get('features')] : []),
...(expectGetFeatures ? [actions.api.get('taskManager')] : []),
...(expectManageSpaces
? [
actions.space.manage,
Expand Down Expand Up @@ -492,6 +493,7 @@ describe('features', () => {
actions.version,
...(expectDecryptedTelemetry ? [actions.api.get('decryptedTelemetry')] : []),
...(expectGetFeatures ? [actions.api.get('features')] : []),
...(expectGetFeatures ? [actions.api.get('taskManager')] : []),
...(expectManageSpaces
? [
actions.space.manage,
Expand Down Expand Up @@ -558,6 +560,7 @@ describe('features', () => {
actions.version,
...(expectDecryptedTelemetry ? [actions.api.get('decryptedTelemetry')] : []),
...(expectGetFeatures ? [actions.api.get('features')] : []),
...(expectGetFeatures ? [actions.api.get('taskManager')] : []),
...(expectManageSpaces
? [
actions.space.manage,
Expand Down Expand Up @@ -625,6 +628,7 @@ describe('features', () => {
actions.version,
...(expectDecryptedTelemetry ? [actions.api.get('decryptedTelemetry')] : []),
...(expectGetFeatures ? [actions.api.get('features')] : []),
...(expectGetFeatures ? [actions.api.get('taskManager')] : []),
...(expectManageSpaces
? [
actions.space.manage,
Expand Down Expand Up @@ -893,6 +897,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1059,6 +1064,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1292,6 +1298,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1431,6 +1438,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1613,6 +1621,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1749,6 +1758,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -1980,6 +1990,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down Expand Up @@ -2245,6 +2256,7 @@ describe('subFeatures', () => {
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function privilegesFactory(
actions.version,
actions.api.get('decryptedTelemetry'),
actions.api.get('features'),
actions.api.get('taskManager'),
actions.space.manage,
actions.ui.get('spaces', 'manage'),
actions.ui.get('management', 'kibana', 'spaces'),
Expand Down
25 changes: 19 additions & 6 deletions x-pack/plugins/task_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export class TaskManagerPlugin
private middleware: Middleware = createInitialMiddleware();
private elasticsearchAndSOAvailability$?: Observable<boolean>;
private monitoringStats$ = new Subject<MonitoringStats>();
private readonly kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];

constructor(private readonly initContext: PluginInitializerContext) {
this.initContext = initContext;
this.logger = initContext.logger.get();
this.config = initContext.config.get<TaskManagerConfig>();
this.definitions = new TaskTypeDictionary(this.logger);
this.kibanaVersion = initContext.env.packageInfo.version;
}

public setup(
Expand All @@ -92,15 +94,26 @@ export class TaskManagerPlugin
this.logger.info(`TaskManager is identified by the Kibana UUID: ${this.taskManagerId}`);
}

const startServicesPromise = core.getStartServices().then(([coreServices]) => ({
elasticsearch: coreServices.elasticsearch,
}));

const usageCounter = plugins.usageCollection?.createUsageCounter(`taskManager`);

// Routes
const router = core.http.createRouter();
const { serviceStatus$, monitoredHealth$ } = healthRoute(
const { serviceStatus$, monitoredHealth$ } = healthRoute({
router,
this.monitoringStats$,
this.logger,
this.taskManagerId,
this.config!
);
monitoringStats$: this.monitoringStats$,
logger: this.logger,
taskManagerId: this.taskManagerId,
config: this.config!,
usageCounter,
kibanaVersion: this.kibanaVersion,
kibanaIndexName: core.savedObjects.getKibanaIndex(),
getClusterClient: () =>
startServicesPromise.then(({ elasticsearch }) => elasticsearch.client),
});

core.status.derivedStatus$.subscribe((status) =>
this.logger.debug(`status core.status.derivedStatus now set to ${status.level}`)
Expand Down
Loading

0 comments on commit 6eae6b8

Please sign in to comment.