Skip to content

Commit

Permalink
refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 7, 2023
1 parent e5afe62 commit d1b6e8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -105,18 +97,16 @@ export function transformHealthServiceProvider({
return resultTransformIds;
};

const getTransformStats = memoize(
async (transformIds: string[]): Promise<TransformGetTransformStats[]> => {
return (
await esClient.transform.getTransformStats({
transform_id: transformIds.join(','),
})
).transforms as TransformGetTransformStats[];
}
);
const getTransformStats = memoize(async (transformIds: string[]): Promise<TransformStats[]> => {
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 });

Expand Down

0 comments on commit d1b6e8b

Please sign in to comment.