Skip to content

Commit

Permalink
[kbn/rule-data-utils] add submodules and require public use them (#11…
Browse files Browse the repository at this point in the history
…7963)

* [kbn/rule-data-utils] add submodules and require public use them

* fix lint errors

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and dmlemeshko committed Nov 29, 2021
1 parent 6907031 commit 8bde6cf
Show file tree
Hide file tree
Showing 51 changed files with 146 additions and 253 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ module.exports = {
name: 'semver',
message: 'Please use "semver/*/{function}" instead',
},
{
name: '@kbn/rule-data-utils',
message: `Import directly from @kbn/rule-data-utils/* submodules in public/common code`,
},
],
},
],
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-rule-data-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ filegroup(

NPM_MODULE_EXTRA_FILES = [
"package.json",
"alerts_as_data_rbac/package.json",
"alerts_as_data_severity/package.json",
"alerts_as_data_status/package.json",
"technical_field_names/package.json",
]

RUNTIME_DEPS = [
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-rule-data-utils/alerts_as_data_rbac/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/alerts_as_data_rbac",
"types": "../target_types/alerts_as_data_rbac"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/alerts_as_data_severity",
"types": "../target_types/alerts_as_data_severity"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/alerts_as_data_status",
"types": "../target_types/alerts_as_data_status"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/technical_field_names",
"types": "../target_types/technical_field_names"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@
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 as ALERT_SEVERITY_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_SEVERITY as ALERT_SEVERITY_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_SEVERITY,
} from '@kbn/rule-data-utils/technical_field_names';
import type { ObservabilityRuleTypeRegistry } from '../../../../observability/public';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import {
Expand All @@ -34,12 +28,6 @@ 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: typeof ALERT_SEVERITY_TYPED = ALERT_SEVERITY_NON_TYPED;

const format = ({
pathname,
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
} from '@elastic/charts';
import { EuiTitle } from '@elastic/eui';
import React, { Suspense, useState } from 'react';
import type { ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { ALERT_RULE_TYPE_ID } from '@kbn/rule-data-utils/technical_field_names';
import { i18n } from '@kbn/i18n';
import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';
Expand All @@ -32,9 +30,6 @@ import { LazyAlertsFlyout } from '../../../../../../observability/public';
import { useLegacyUrlParams } from '../../../../context/url_params_context/use_url_params';
import { getTimeZone } from '../../../shared/charts/helper/timezone';

const ALERT_RULE_TYPE_ID: typeof ALERT_RULE_TYPE_ID_TYPED =
ALERT_RULE_TYPE_ID_NON_TYPED;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
ALERT_SEVERITY,
ALERT_START,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
ALERT_UUID,
SPACE_IDS,
ALERT_RULE_UUID,
ALERT_RULE_NAME,
ALERT_RULE_CATEGORY,
} from '@kbn/rule-data-utils';
} from '@kbn/rule-data-utils/technical_field_names';
import { ALERT_STATUS_ACTIVE } from '@kbn/rule-data-utils/alerts_as_data_status';
import { ValuesType } from 'utility-types';
import { EuiTheme } from '../../../../../../../../src/plugins/kibana_react/common';
import { ObservabilityRuleTypeRegistry } from '../../../../../../observability/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@ import {
} from '@elastic/charts';
import { EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type {
ALERT_DURATION as ALERT_DURATION_TYPED,
ALERT_SEVERITY as ALERT_SEVERITY_TYPED,
ALERT_START as ALERT_START_TYPED,
ALERT_UUID as ALERT_UUID_TYPED,
ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_DURATION as ALERT_DURATION_NON_TYPED,
ALERT_SEVERITY as ALERT_SEVERITY_NON_TYPED,
ALERT_START as ALERT_START_NON_TYPED,
ALERT_UUID as ALERT_UUID_NON_TYPED,
ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_NON_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_DURATION,
ALERT_SEVERITY,
ALERT_START,
ALERT_UUID,
ALERT_RULE_TYPE_ID,
ALERT_RULE_NAME,
} from '@kbn/rule-data-utils/technical_field_names';
import React, { Dispatch, SetStateAction } from 'react';
import { EuiTheme } from 'src/plugins/kibana_react/common';
import { ValuesType } from 'utility-types';
Expand All @@ -37,14 +28,6 @@ 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: typeof ALERT_SEVERITY_TYPED = ALERT_SEVERITY_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 ALERT_RULE_TYPE_ID: typeof ALERT_RULE_TYPE_ID_TYPED =
ALERT_RULE_TYPE_ID_NON_TYPED;
const ALERT_RULE_NAME: typeof ALERT_RULE_NAME_TYPED = ALERT_RULE_NAME_NON_TYPED;

type Alert = ValuesType<
APIReturnType<'GET /internal/apm/services/{serviceName}/alerts'>['alerts']
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiSelect, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useHistory } from 'react-router-dom';
import type { ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_TYPED } from '@kbn/rule-data-utils';
// @ts-expect-error
import { ALERT_RULE_TYPE_ID as ALERT_RULE_TYPE_ID_NON_TYPED } from '@kbn/rule-data-utils/target_node/technical_field_names';
import { ALERT_RULE_TYPE_ID } from '@kbn/rule-data-utils/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 @@ -29,9 +27,6 @@ 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 ALERT_RULE_TYPE_ID: typeof ALERT_RULE_TYPE_ID_TYPED =
ALERT_RULE_TYPE_ID_NON_TYPED;

interface Props {
height?: number;
kuery: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ALERT_SEVERITY,
ALERT_START,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
ALERT_UUID,
TIMESTAMP,
ALERT_RULE_UUID,
Expand All @@ -23,7 +22,8 @@ import {
ALERT_RULE_CONSUMER,
ALERT_RULE_PRODUCER,
SPACE_IDS,
} from '@kbn/rule-data-utils';
} from '@kbn/rule-data-utils/technical_field_names';
import { ALERT_STATUS_ACTIVE } from '@kbn/rule-data-utils/alerts_as_data_status';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@

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,
ALERT_REASON as ALERT_REASON_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_REASON,
} from '@kbn/rule-data-utils/technical_field_names';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import {
ENVIRONMENT_NOT_DEFINED,
Expand All @@ -43,12 +37,6 @@ import { alertingEsClient } from './alerting_es_client';
import { RegisterRuleDependencies } from './register_apm_alerts';
import { termQuery } from '../../../../observability/server';

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_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_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 @@ -7,17 +7,11 @@

import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { schema } from '@kbn/config-schema';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
ALERT_REASON as ALERT_REASON_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_REASON,
} from '@kbn/rule-data-utils/technical_field_names';
import { take } from 'rxjs/operators';
import { asDuration } from '../../../../observability/common/utils/formatters';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
Expand Down Expand Up @@ -49,12 +43,6 @@ 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 ALERT_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_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,19 +9,12 @@ import { schema } from '@kbn/config-schema';
import { compact } from 'lodash';
import { ESSearchResponse } from 'src/core/types/elasticsearch';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
ALERT_SEVERITY as ALERT_SEVERITY_TYPED,
ALERT_REASON as ALERT_REASON_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_SEVERITY as ALERT_SEVERITY_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_SEVERITY,
ALERT_REASON,
} from '@kbn/rule-data-utils/technical_field_names';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import { ProcessorEvent } from '../../../common/processor_event';
import { getSeverity } from '../../../common/anomaly_detection';
Expand All @@ -48,13 +41,6 @@ import {
} from '../../../common/environment_filter_values';
import { termQuery } from '../../../../observability/server';

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: typeof ALERT_SEVERITY_TYPED = ALERT_SEVERITY_NON_TYPED;
const ALERT_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_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,17 +7,11 @@

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,
ALERT_REASON as ALERT_REASON_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_NON_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
ALERT_EVALUATION_THRESHOLD,
ALERT_EVALUATION_VALUE,
ALERT_REASON,
} from '@kbn/rule-data-utils/technical_field_names';
import {
ENVIRONMENT_NOT_DEFINED,
getEnvironmentEsField,
Expand Down Expand Up @@ -50,12 +44,6 @@ import { getDocumentTypeFilterForTransactions } from '../helpers/transactions';
import { asPercent } from '../../../../observability/common/utils/formatters';
import { termQuery } from '../../../../observability/server';

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_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_NON_TYPED;

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

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 { EVENT_KIND } from '@kbn/rule-data-utils/technical_field_names';
import { IRuleDataClient } from '../../../../rule_registry/server';
import {
SERVICE_NAME,
Expand All @@ -16,8 +14,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EuiCommentList,
EuiCommentProps,
} from '@elastic/eui';
import { ALERT_RULE_NAME, ALERT_RULE_UUID } from '@kbn/rule-data-utils';
import { ALERT_RULE_NAME, ALERT_RULE_UUID } from '@kbn/rule-data-utils/technical_field_names';

import classNames from 'classnames';
import { get, isEmpty } from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { ALERT_REASON, ALERT_RULE_PARAMS, TIMESTAMP } from '@kbn/rule-data-utils';
import {
ALERT_REASON,
ALERT_RULE_PARAMS,
TIMESTAMP,
} from '@kbn/rule-data-utils/technical_field_names';
import { encode } from 'rison-node';
import { stringify } from 'query-string';
import { ObservabilityRuleTypeFormatter } from '../../../../observability/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ALERT_REASON, ALERT_START } from '@kbn/rule-data-utils';
import { ALERT_REASON, ALERT_START } from '@kbn/rule-data-utils/technical_field_names';
import { modifyUrl } from '@kbn/std';
import { ObservabilityRuleTypeFormatter } from '../../../../observability/public';

Expand Down
Loading

0 comments on commit 8bde6cf

Please sign in to comment.