Skip to content

Commit

Permalink
[Infra UI] Avoid eager async imports in metric alert registrations (e…
Browse files Browse the repository at this point in the history
…lastic#123285)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx
#	x-pack/plugins/infra/public/alerting/inventory/components/expression_chart.tsx
#	x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx
#	x-pack/plugins/infra/public/alerting/inventory/index.ts
#	x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx
#	x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx
#	x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx
#	x-pack/plugins/infra/public/alerting/metric_threshold/index.ts
#	x-pack/plugins/infra/public/plugin.ts
#	x-pack/plugins/infra/server/features.ts
#	x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts
#	x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts
#	x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/lib/calculate_from_based_on_metric.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_anomaly/metric_anomaly_executor.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_alert.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts
#	x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts
#	x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts
#	x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts
  • Loading branch information
weltenwort committed Jan 31, 2022
1 parent 5b5dd93 commit aa1c069
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
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

0 comments on commit aa1c069

Please sign in to comment.