Skip to content

Commit

Permalink
Merge branch 'backport/7.14/pr-108189' of github.com:mistic/kibana in…
Browse files Browse the repository at this point in the history
…to backport/7.14/pr-108189
  • Loading branch information
mistic committed Aug 12, 2021
2 parents bf3ed80 + 6ed36d3 commit 52d0095
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 67 deletions.
3 changes: 3 additions & 0 deletions packages/kbn-rule-data-utils/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@kbn/babel-preset/node_preset"]
}
24 changes: 17 additions & 7 deletions packages/kbn-rule-data-utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
load("//src/dev/bazel:index.bzl", "jsts_transpiler")

PKG_BASE_NAME = "kbn-rule-data-utils"
PKG_REQUIRE_NAME = "@kbn/rule-data-utils"
Expand All @@ -21,17 +22,25 @@ NPM_MODULE_EXTRA_FILES = [
"package.json",
]

SRC_DEPS = [
RUNTIME_DEPS = [
"@npm//@elastic/elasticsearch",
"@npm//tslib",
"@npm//utility-types",
]

TYPES_DEPS = [
"@npm//@elastic/elasticsearch",
"@npm//tslib",
"@npm//utility-types",
"@npm//@types/jest",
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
Expand All @@ -42,14 +51,15 @@ ts_config(
)

ts_project(
name = "tsc",
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
emit_declaration_only = True,
incremental = False,
out_dir = "target_types",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
Expand All @@ -58,7 +68,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":tsc"],
deps = RUNTIME_DEPS + [":target_node", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-rule-data-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kbn/rule-data-utils",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"main": "./target_node/index.js",
"types": "./target_types/index.d.ts",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"private": true,
Expand Down
11 changes: 6 additions & 5 deletions packages/kbn-rule-data-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": true,
"outDir": "./target",
"stripInternal": false,
"declaration": true,
"declarationMap": true,
"rootDir": "./src",
"emitDeclarationOnly": true,
"incremental": false,
"outDir": "./target_types",
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-rule-data-utils/src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"./src/**/*.ts"
"src/**/*.ts"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
import { i18n } from '@kbn/i18n';
import { lazy } from 'react';
import { stringify } from 'querystring';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_SEVERITY_LEVEL,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import type { ObservabilityRuleTypeRegistry } from '../../../../observability/public';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { AlertType } from '../../../common/alert_types';
Expand All @@ -22,6 +28,10 @@ const SERVICE_ENVIRONMENT = 'service.environment';
const SERVICE_NAME = 'service.name';
const TRANSACTION_TYPE = 'transaction.type';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;
const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;

const format = ({
pathname,
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {
import { EuiTitle } from '@elastic/eui';
import d3 from 'd3';
import React, { Suspense, useState } from 'react';
import { RULE_ID } from '@kbn/rule-data-utils/target/technical_field_names';
import type { RULE_ID as RULE_ID_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { RULE_ID as RULE_ID_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';
import { asRelativeDateTimeRange } from '../../../../../common/utils/formatters';
Expand All @@ -29,6 +31,8 @@ import { getAlertAnnotations } from '../../../shared/charts/helper/get_alert_ann
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { LazyAlertsFlyout } from '../../../../../../observability/public';

const RULE_ID: typeof RULE_ID_TYPED = RULE_ID_NON_TYPED;

type ErrorDistributionAPIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/errors/distribution'>;

interface FormattedBucket {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
* 2.0.
*/

import { ALERT_SEVERITY_LEVEL } from '@kbn/rule-data-utils/target/technical_field_names';
import type { ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { ValuesType } from 'utility-types';
import { EuiTheme } from '../../../../../../../../src/plugins/kibana_react/common';
import { ObservabilityRuleTypeRegistry } from '../../../../../../observability/public';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';
import { getAlertAnnotations } from './get_alert_annotations';

const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;

type Alert = ValuesType<
APIReturnType<'GET /api/apm/services/{serviceName}/alerts'>['alerts']
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ import {
} from '@elastic/charts';
import { EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type {
ALERT_DURATION as ALERT_DURATION_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_START as ALERT_START_TYPED,
ALERT_UUID as ALERT_UUID_TYPED,
RULE_ID as RULE_ID_TYPED,
RULE_NAME as RULE_NAME_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_DURATION,
ALERT_SEVERITY_LEVEL,
ALERT_START,
ALERT_UUID,
RULE_ID,
RULE_NAME,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_DURATION as ALERT_DURATION_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
ALERT_START as ALERT_START_NON_TYPED,
ALERT_UUID as ALERT_UUID_NON_TYPED,
RULE_ID as RULE_ID_NON_TYPED,
RULE_NAME as RULE_NAME_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import React, { Dispatch, SetStateAction } from 'react';
import { EuiTheme } from 'src/plugins/kibana_react/common';
import { ValuesType } from 'utility-types';
Expand All @@ -28,6 +37,13 @@ import { parseTechnicalFields } from '../../../../../../rule_registry/common';
import { asDuration, asPercent } from '../../../../../common/utils/formatters';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';

const ALERT_DURATION: typeof ALERT_DURATION_TYPED = ALERT_DURATION_NON_TYPED;
const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;
const ALERT_START: typeof ALERT_START_TYPED = ALERT_START_NON_TYPED;
const ALERT_UUID: typeof ALERT_UUID_TYPED = ALERT_UUID_NON_TYPED;
const RULE_ID: typeof RULE_ID_TYPED = RULE_ID_NON_TYPED;
const RULE_NAME: typeof RULE_NAME_TYPED = RULE_NAME_NON_TYPED;

type Alert = ValuesType<
APIReturnType<'GET /api/apm/services/{serviceName}/alerts'>['alerts']
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { EuiFlexGroup, EuiFlexItem, EuiSelect, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useHistory } from 'react-router-dom';
import { RULE_ID } from '@kbn/rule-data-utils/target/technical_field_names';
import type { RULE_ID as RULE_ID_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { RULE_ID as RULE_ID_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { AlertType } from '../../../../../common/alert_types';
import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context';
import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types';
Expand All @@ -27,6 +29,8 @@ import { MLHeader } from '../../../shared/charts/transaction_charts/ml_header';
import * as urlHelpers from '../../../shared/Links/url_helpers';
import { getComparisonChartTheme } from '../../time_comparison/get_time_range_comparison';

const RULE_ID: typeof RULE_ID_TYPED = RULE_ID_NON_TYPED;

interface Props {
height?: number;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

import { schema } from '@kbn/config-schema';
import { take } from 'rxjs/operators';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import {
ENVIRONMENT_NOT_DEFINED,
Expand All @@ -30,6 +35,9 @@ import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
import { RegisterRuleDependencies } from './register_apm_alerts';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;

const paramsSchema = schema.object({
windowSize: schema.number(),
windowUnit: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import { schema } from '@kbn/config-schema';
import { take } from 'rxjs/operators';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import {
getEnvironmentLabel,
Expand All @@ -32,6 +37,9 @@ import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
import { RegisterRuleDependencies } from './register_apm_alerts';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;

const paramsSchema = schema.object({
serviceName: schema.string(),
transactionType: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import { schema } from '@kbn/config-schema';
import { compact } from 'lodash';
import { ESSearchResponse } from 'src/core/types/elasticsearch';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_SEVERITY_VALUE as ALERT_SEVERITY_VALUE_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_SEVERITY_LEVEL,
ALERT_SEVERITY_VALUE,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
ALERT_SEVERITY_VALUE as ALERT_SEVERITY_VALUE_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import { ProcessorEvent } from '../../../common/processor_event';
import { getSeverity } from '../../../common/anomaly_detection';
Expand All @@ -39,6 +46,11 @@ import {
getEnvironmentLabel,
} from '../../../common/environment_filter_values';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;
const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;
const ALERT_SEVERITY_VALUE: typeof ALERT_SEVERITY_VALUE_TYPED = ALERT_SEVERITY_VALUE_NON_TYPED;

const paramsSchema = schema.object({
serviceName: schema.maybe(schema.string()),
transactionType: schema.maybe(schema.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

import { schema } from '@kbn/config-schema';
import { take } from 'rxjs/operators';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
} from '@kbn/rule-data-utils/target/technical_field_names';
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import {
ENVIRONMENT_NOT_DEFINED,
getEnvironmentEsField,
Expand All @@ -34,6 +39,9 @@ import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
import { RegisterRuleDependencies } from './register_apm_alerts';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;

const paramsSchema = schema.object({
windowSize: schema.number(),
windowUnit: schema.string(),
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/apm/server/lib/services/get_service_alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* 2.0.
*/

import { EVENT_KIND } from '@kbn/rule-data-utils/target/technical_field_names';
import type { EVENT_KIND as EVENT_KIND_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { EVENT_KIND as EVENT_KIND_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { RuleDataClient } from '../../../../rule_registry/server';
import {
SERVICE_NAME,
Expand All @@ -14,6 +16,8 @@ import {
import { rangeQuery } from '../../../../observability/server';
import { environmentQuery } from '../../../common/utils/environment_query';

const EVENT_KIND: typeof EVENT_KIND_TYPED = EVENT_KIND_NON_TYPED;

export async function getServiceAlerts({
ruleDataClient,
start,
Expand Down
Loading

0 comments on commit 52d0095

Please sign in to comment.