From d1b6e8be1f37ba4c271c0a49c904ba7b2c143223 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 7 Mar 2023 11:46:05 +0100 Subject: [PATCH] refactor types --- .../register_transform_health_rule_type.ts | 9 ++---- .../transform_health_service.ts | 28 ++++++------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index db4e03363efbd..9128c91c1f965 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -16,19 +16,14 @@ import type { import { 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 { PLUGIN, TRANSFORM_RULE_TYPE } from '../../../../common/constants'; +import { PLUGIN, type TransformHealth, TRANSFORM_RULE_TYPE } from '../../../../common/constants'; import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { transformHealthServiceProvider } from './transform_health_service'; -export interface TransformHealth { - status: 'green' | 'unknown' | 'yellow' | 'red'; - issues?: Array<{ issue: string; details?: string; count: number; first_occurrence?: number }>; -} - export interface BaseTransformAlertResponse { transform_id: string; description?: string; - health_status: TransformHealth['status']; + health_status: TransformHealth; issues?: Array<{ issue: string; details?: string; count: number; first_occurrence?: string }>; } diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index 72eb8981aadd6..5c218a40abb45 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -10,8 +10,8 @@ import { i18n } from '@kbn/i18n'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { keyBy, memoize, partition } from 'lodash'; import type { RulesClient } from '@kbn/alerting-plugin/server'; -import { type TransformGetTransformStatsTransformStats } from '@elastic/elasticsearch/lib/api/types'; import { FIELD_FORMAT_IDS, FieldFormatsRegistry } from '@kbn/field-formats-plugin/common'; +import { TransformStats } from '../../../../common/types/transform_stats'; import { TransformHealthRuleParams } from './schema'; import { ALL_TRANSFORMS_SELECTION, @@ -23,7 +23,6 @@ import { getResultTestConfig } from '../../../../common/utils/alerts'; import type { ErrorMessagesTransformResponse, TransformStateReportResponse, - TransformHealth, TransformHealthAlertContext, } from './register_transform_health_rule_type'; import type { TransformHealthAlertRule } from '../../../../common/types/alerting'; @@ -44,13 +43,6 @@ type Transform = estypes.TransformGetTransformTransformSummary & { type TransformWithAlertingRules = Transform & { alerting_rules: TransformHealthAlertRule[] }; -/** - * TODO update types in the es client - */ -type TransformGetTransformStats = TransformGetTransformStatsTransformStats & { - health: TransformHealth; -}; - export function transformHealthServiceProvider({ esClient, rulesClient, @@ -105,18 +97,16 @@ export function transformHealthServiceProvider({ return resultTransformIds; }; - const getTransformStats = memoize( - async (transformIds: string[]): Promise => { - return ( - await esClient.transform.getTransformStats({ - transform_id: transformIds.join(','), - }) - ).transforms as TransformGetTransformStats[]; - } - ); + const getTransformStats = memoize(async (transformIds: string[]): Promise => { + return ( + await esClient.transform.getTransformStats({ + transform_id: transformIds.join(','), + }) + ).transforms as TransformStats[]; + }); function baseTransformAlertResponseFormatter( - transformStats: TransformGetTransformStats + transformStats: TransformStats ): TransformStateReportResponse { const dateFormatter = fieldFormatsRegistry!.deserialize({ id: FIELD_FORMAT_IDS.DATE });