mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[ML] Transforms: Add telemetry for transform health rule check type (#159652)
This commit is contained in:
parent
1bb316d97f
commit
a1f55b8420
6 changed files with 180 additions and 3 deletions
|
@ -14426,6 +14426,40 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"transform": {
|
||||
"properties": {
|
||||
"alertRules": {
|
||||
"properties": {
|
||||
"transform_health": {
|
||||
"properties": {
|
||||
"count_by_check_type": {
|
||||
"properties": {
|
||||
"notStarted": {
|
||||
"type": "long",
|
||||
"_meta": {
|
||||
"description": "total number of alerting rules performing the not started health check"
|
||||
}
|
||||
},
|
||||
"errorMessages": {
|
||||
"type": "long",
|
||||
"_meta": {
|
||||
"description": "total number of alerting rules performing the error message health check"
|
||||
}
|
||||
},
|
||||
"healthCheck": {
|
||||
"type": "long",
|
||||
"_meta": {
|
||||
"description": "total number of alerting rules performing the health check with the stats API"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"upgrade-assistant-telemetry": {
|
||||
"properties": {
|
||||
"features": {
|
||||
|
|
|
@ -13,9 +13,9 @@ import type {
|
|||
AlertInstanceState,
|
||||
RuleTypeState,
|
||||
} from '@kbn/alerting-plugin/common';
|
||||
import { RuleType } from '@kbn/alerting-plugin/server';
|
||||
import type { RuleType } from '@kbn/alerting-plugin/server';
|
||||
import type { PluginSetupContract as AlertingSetup } from '@kbn/alerting-plugin/server';
|
||||
import { FieldFormatsStart } from '@kbn/field-formats-plugin/server';
|
||||
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/server';
|
||||
import { PLUGIN, type TransformHealth, TRANSFORM_RULE_TYPE } from '../../../../common/constants';
|
||||
import { transformHealthRuleParams, TransformHealthRuleParams } from './schema';
|
||||
import { transformHealthServiceProvider } from './transform_health_service';
|
||||
|
|
|
@ -10,6 +10,7 @@ import { CoreSetup, CoreStart, Plugin, Logger, PluginInitializerContext } from '
|
|||
|
||||
import { LicenseType } from '@kbn/licensing-plugin/common/types';
|
||||
|
||||
import { registerCollector } from './usage';
|
||||
import { setupCapabilities } from './capabilities';
|
||||
import { PluginSetupDependencies, PluginStartDependencies } from './types';
|
||||
import { registerRoutes } from './routes';
|
||||
|
@ -38,7 +39,13 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> {
|
|||
|
||||
setup(
|
||||
coreSetup: CoreSetup<PluginStartDependencies>,
|
||||
{ licensing, features, alerting, security: securitySetup }: PluginSetupDependencies
|
||||
{
|
||||
licensing,
|
||||
features,
|
||||
alerting,
|
||||
security: securitySetup,
|
||||
usageCollection,
|
||||
}: PluginSetupDependencies
|
||||
): {} {
|
||||
const { http, getStartServices } = coreSetup;
|
||||
|
||||
|
@ -77,6 +84,12 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> {
|
|||
coreStart,
|
||||
security: securityStart,
|
||||
});
|
||||
|
||||
const alertIndex = coreStart.savedObjects.getIndexForType('alert');
|
||||
|
||||
if (usageCollection) {
|
||||
registerCollector(usageCollection, alertIndex);
|
||||
}
|
||||
});
|
||||
|
||||
if (alerting) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import type { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-p
|
|||
import type { AlertingPlugin } from '@kbn/alerting-plugin/server';
|
||||
import type { FieldFormatsSetup, FieldFormatsStart } from '@kbn/field-formats-plugin/server';
|
||||
import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server';
|
||||
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
||||
import type { License } from './services';
|
||||
|
||||
export interface PluginSetupDependencies {
|
||||
|
@ -20,6 +21,7 @@ export interface PluginSetupDependencies {
|
|||
alerting?: AlertingPlugin['setup'];
|
||||
fieldFormats: FieldFormatsSetup;
|
||||
security?: SecurityPluginSetup;
|
||||
usageCollection?: UsageCollectionSetup;
|
||||
}
|
||||
|
||||
export interface PluginStartDependencies {
|
||||
|
|
120
x-pack/plugins/transform/server/usage/collector.ts
Normal file
120
x-pack/plugins/transform/server/usage/collector.ts
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
||||
import { getResultTestConfig } from '../../common/utils/alerts';
|
||||
import { TransformHealthRuleParams } from '../../common/types/alerting';
|
||||
import { TRANSFORM_RULE_TYPE } from '../../common';
|
||||
|
||||
export interface TransformAlertsUsageData {
|
||||
alertRules: {
|
||||
transform_health: {
|
||||
count_by_check_type: {
|
||||
notStarted: number;
|
||||
errorMessages: number;
|
||||
healthCheck: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function registerCollector(usageCollection: UsageCollectionSetup, alertIndex: string) {
|
||||
const collector = usageCollection.makeUsageCollector<TransformAlertsUsageData>({
|
||||
type: 'transform',
|
||||
schema: {
|
||||
alertRules: {
|
||||
transform_health: {
|
||||
count_by_check_type: {
|
||||
notStarted: {
|
||||
type: 'long',
|
||||
_meta: {
|
||||
description:
|
||||
'total number of alerting rules performing the not started health check',
|
||||
},
|
||||
},
|
||||
errorMessages: {
|
||||
type: 'long',
|
||||
_meta: {
|
||||
description:
|
||||
'total number of alerting rules performing the error message health check',
|
||||
},
|
||||
},
|
||||
healthCheck: {
|
||||
type: 'long',
|
||||
_meta: {
|
||||
description:
|
||||
'total number of alerting rules performing the health check with the stats API',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
isReady: () => true,
|
||||
fetch: async ({ esClient }) => {
|
||||
const transformHealthRuleInstances = await esClient.search<{
|
||||
alert: {
|
||||
params: TransformHealthRuleParams;
|
||||
};
|
||||
}>(
|
||||
{
|
||||
index: alertIndex,
|
||||
size: 10000,
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{ term: { type: 'alert' } },
|
||||
{
|
||||
term: {
|
||||
'alert.alertTypeId': TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{ maxRetries: 0 }
|
||||
);
|
||||
|
||||
const resultsByCheckType = transformHealthRuleInstances.hits.hits.reduce(
|
||||
(acc, curr) => {
|
||||
const doc = curr._source;
|
||||
if (!doc) return acc;
|
||||
|
||||
const {
|
||||
alert: {
|
||||
params: { testsConfig },
|
||||
},
|
||||
} = doc;
|
||||
|
||||
const resultConfig = getResultTestConfig(testsConfig);
|
||||
|
||||
acc.notStarted += resultConfig?.notStarted?.enabled ? 1 : 0;
|
||||
acc.errorMessages += resultConfig?.errorMessages?.enabled ? 1 : 0;
|
||||
acc.healthCheck += resultConfig?.healthCheck?.enabled ? 1 : 0;
|
||||
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
notStarted: 0,
|
||||
errorMessages: 0,
|
||||
healthCheck: 0,
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
alertRules: {
|
||||
[TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH]: {
|
||||
count_by_check_type: resultsByCheckType,
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
usageCollection.registerCollector(collector);
|
||||
}
|
8
x-pack/plugins/transform/server/usage/index.ts
Normal file
8
x-pack/plugins/transform/server/usage/index.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
export { registerCollector } from './collector';
|
Loading…
Add table
Add a link
Reference in a new issue