Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.17] [Infra UI] Avoid eager async imports in metric alert registrations (#123285) #124177

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions x-pack/plugins/infra/common/alerting/metrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ export interface InventoryMetricThresholdParams {
sourceId?: string;
alertOnNoData?: boolean;
}

export const QUERY_INVALID: unique symbol = Symbol('QUERY_INVALID');

export type FilterQuery = string | typeof QUERY_INVALID;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
IErrorObject,
AlertTypeParamsExpressionProps,
} from '../../../../../triggers_actions_ui/public';
import { FilterQuery, QUERY_INVALID } from '../../../../common/alerting/metrics';
import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar';
import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http';
import { sqsMetricTypes } from '../../../../common/inventory_models/aws_sqs/toolbar_items';
Expand Down Expand Up @@ -70,7 +71,6 @@ import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';

import { ExpressionChart } from './expression_chart';
const FILTER_TYPING_DEBOUNCE_MS = 500;
export const QUERY_INVALID = Symbol('QUERY_INVALID');

export interface AlertContextMeta {
options?: Partial<InfraWaffleMapOptions>;
Expand All @@ -85,7 +85,7 @@ type Props = Omit<
{
criteria: Criteria;
nodeType: InventoryItemType;
filterQuery?: string | symbol;
filterQuery?: FilterQuery;
filterQueryText?: string;
sourceId: string;
alertOnNoData?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
} from '../../../../server/lib/alerting/inventory_metric_threshold/types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ValidationResult } from '../../../../../triggers_actions_ui/public/types';
import { QUERY_INVALID } from './expression';
import { FilterQuery, QUERY_INVALID } from '../../../../common/alerting/metrics';

export function validateMetricThreshold({
criteria,
filterQuery,
}: {
criteria: InventoryMetricConditions[];
filterQuery?: string | symbol;
filterQuery?: FilterQuery;
}): ValidationResult {
const validationResult = { errors: {} };
const errors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { Comparator, Aggregators } from '../../../../common/alerting/metrics';
import { Aggregators, Comparator, QUERY_INVALID } from '../../../../common/alerting/metrics';
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
import {
IErrorObject,
Expand All @@ -42,7 +42,6 @@ import { ExpressionChart } from './expression_chart';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';

const FILTER_TYPING_DEBOUNCE_MS = 500;
export const QUERY_INVALID = Symbol('QUERY_INVALID');

type Props = Omit<
AlertTypeParamsExpressionProps<AlertTypeParams & AlertParams, AlertContextMeta>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
} from '../../../../server/lib/alerting/metric_threshold/types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ValidationResult } from '../../../../../triggers_actions_ui/public/types';
import { QUERY_INVALID } from './expression';
import { FilterQuery, QUERY_INVALID } from '../../../../common/alerting/metrics';

export function validateMetricThreshold({
criteria,
filterQuery,
}: {
criteria: MetricExpressionParams[];
filterQuery?: string | symbol;
filterQuery?: FilterQuery;
}): ValidationResult {
const validationResult = { errors: {} };
const errors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../server/lib/alerting/metric_threshold/types';
import { MetricsExplorerOptions } from '../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options';
import { FilterQuery } from '../../../common/alerting/metrics';
import { MetricsExplorerSeries } from '../../../common/http_api/metrics_explorer';

export interface AlertContextMeta {
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface ExpressionChartData {
export interface AlertParams {
criteria: MetricExpression[];
groupBy?: string | string[];
filterQuery?: string | symbol;
filterQuery?: FilterQuery;
sourceId: string;
filterQueryText?: string;
alertOnNoData?: boolean;
Expand Down
9 changes: 4 additions & 5 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { AppMountParameters, PluginInitializerContext } from 'kibana/public';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';
import { createInventoryMetricAlertType } from './alerting/inventory';
import { createLogThresholdAlertType } from './alerting/log_threshold';
import { createMetricThresholdAlertType } from './alerting/metric_threshold';
import { LOG_STREAM_EMBEDDABLE } from './components/log_stream/log_stream_embeddable';
import { LogStreamEmbeddableFactoryDefinition } from './components/log_stream/log_stream_embeddable_factory';
import { createMetricsFetchData, createMetricsHasData } from './metrics_overview_fetchers';
Expand All @@ -26,15 +29,11 @@ import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_
export class Plugin implements InfraClientPluginClass {
constructor(_context: PluginInitializerContext) {}

async setup(core: InfraClientCoreSetup, pluginsSetup: InfraClientSetupDeps) {
setup(core: InfraClientCoreSetup, pluginsSetup: InfraClientSetupDeps) {
if (pluginsSetup.home) {
registerFeatures(pluginsSetup.home);
}

const { createInventoryMetricAlertType } = await import('./alerting/inventory');
const { createLogThresholdAlertType } = await import('./alerting/log_threshold');
const { createMetricThresholdAlertType } = await import('./alerting/metric_threshold');

pluginsSetup.observability.observabilityRuleTypeRegistry.register(
createInventoryMetricAlertType()
);
Expand Down