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

[RAM][Maintenance Window] Maintenance window scoped query frontend changes #171949

Merged
merged 20 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ x-pack/test/alerting_api_integration/common/plugins/aad @elastic/response-ops
packages/kbn-ace @elastic/platform-deployment-management
x-pack/plugins/actions @elastic/response-ops
x-pack/test/alerting_api_integration/common/plugins/actions_simulators @elastic/response-ops
packages/kbn-actions-types @elastic/response-ops
src/plugins/advanced_settings @elastic/appex-sharedux @elastic/platform-deployment-management
x-pack/packages/ml/aiops_components @elastic/ml-ui
x-pack/plugins/aiops @elastic/ml-ui
Expand All @@ -19,6 +20,7 @@ x-pack/examples/alerting_example @elastic/response-ops
x-pack/test/functional_with_es_ssl/plugins/alerts @elastic/response-ops
x-pack/plugins/alerting @elastic/response-ops
x-pack/packages/kbn-alerting-state-types @elastic/response-ops
packages/kbn-alerting-types @elastic/response-ops
packages/kbn-alerts-as-data-utils @elastic/response-ops
x-pack/test/alerting_api_integration/common/plugins/alerts_restricted @elastic/response-ops
packages/kbn-alerts-ui-shared @elastic/response-ops
Expand Down Expand Up @@ -790,6 +792,7 @@ x-pack/plugins/transform @elastic/ml-ui
x-pack/plugins/translations @elastic/kibana-localization
x-pack/examples/triggers_actions_ui_example @elastic/response-ops
x-pack/plugins/triggers_actions_ui @elastic/response-ops
packages/kbn-triggers-actions-ui-types @elastic/response-ops
packages/kbn-ts-projects @elastic/kibana-operations
packages/kbn-ts-type-check-cli @elastic/kibana-operations
packages/kbn-typed-react-router-config @elastic/obs-knowledge-team @elastic/obs-ux-management-team
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"advancedSettings": "src/plugins/advanced_settings",
"alerts": "packages/kbn-alerts/src",
"alertsUIShared": "packages/kbn-alerts-ui-shared/src",
"alertingTypes": "packages/kbn-alerting-types",
"apmOss": "src/plugins/apm_oss",
"autocomplete": "packages/kbn-securitysolution-autocomplete/src",
"bfetch": "src/plugins/bfetch",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"@kbn/ace": "link:packages/kbn-ace",
"@kbn/actions-plugin": "link:x-pack/plugins/actions",
"@kbn/actions-simulators-plugin": "link:x-pack/test/alerting_api_integration/common/plugins/actions_simulators",
"@kbn/actions-types": "link:packages/kbn-actions-types",
"@kbn/advanced-settings-plugin": "link:src/plugins/advanced_settings",
"@kbn/aiops-components": "link:x-pack/packages/ml/aiops_components",
"@kbn/aiops-plugin": "link:x-pack/plugins/aiops",
Expand All @@ -142,6 +143,7 @@
"@kbn/alerting-fixture-plugin": "link:x-pack/test/functional_with_es_ssl/plugins/alerts",
"@kbn/alerting-plugin": "link:x-pack/plugins/alerting",
"@kbn/alerting-state-types": "link:x-pack/packages/kbn-alerting-state-types",
"@kbn/alerting-types": "link:packages/kbn-alerting-types",
"@kbn/alerts-as-data-utils": "link:packages/kbn-alerts-as-data-utils",
"@kbn/alerts-restricted-fixtures-plugin": "link:x-pack/test/alerting_api_integration/common/plugins/alerts_restricted",
"@kbn/alerts-ui-shared": "link:packages/kbn-alerts-ui-shared",
Expand Down Expand Up @@ -781,6 +783,7 @@
"@kbn/translations-plugin": "link:x-pack/plugins/translations",
"@kbn/triggers-actions-ui-example-plugin": "link:x-pack/examples/triggers_actions_ui_example",
"@kbn/triggers-actions-ui-plugin": "link:x-pack/plugins/triggers_actions_ui",
"@kbn/triggers-actions-ui-types": "link:packages/kbn-triggers-actions-ui-types",
"@kbn/typed-react-router-config": "link:packages/kbn-typed-react-router-config",
"@kbn/ui-actions-browser": "link:packages/kbn-ui-actions-browser",
"@kbn/ui-actions-enhanced-examples-plugin": "link:x-pack/examples/ui_actions_enhanced_examples",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-actions-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/actions-types

Empty package generated by @kbn/generate
9 changes: 9 additions & 0 deletions packages/kbn-actions-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './rewrite_request_case_types';
13 changes: 13 additions & 0 deletions packages/kbn-actions-types/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-actions-types'],
};
5 changes: 5 additions & 0 deletions packages/kbn-actions-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/actions-types",
"owner": "@elastic/response-ops"
}
6 changes: 6 additions & 0 deletions packages/kbn-actions-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/actions-types",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
51 changes: 51 additions & 0 deletions packages/kbn-actions-types/rewrite_request_case_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

type RenameActionToConnector<K extends string> = K extends `actionTypeId`
? `connectorTypeId`
: K extends `actionId`
? `connectorId`
: K;

export type AsApiContract<T> = {
[K in keyof T as CamelToSnake<RenameActionToConnector<Extract<K, string>>>]: K extends 'frequency'
? AsApiContract<T[K]>
: T[K];
};

export type RewriteRequestCase<T> = (requested: AsApiContract<T>) => T;
export type RewriteResponseCase<T> = (
responded: T
) => T extends Array<infer Item> ? Array<AsApiContract<Item>> : AsApiContract<T>;

/**
* This type maps Camel Case strings into their Snake Case version.
* This is achieved by checking each character and, if it is an uppercase character, it is mapped to an
* underscore followed by a lowercase one.
*
* The reason there are two ternaries is that, for perfformance reasons, TS limits its
* character parsing to ~15 characters.
* To get around this we use the second turnery to parse 2 characters at a time, which allows us to support
* strings that are 30 characters long.
*
* If you get the TS #2589 error ("Type instantiation is excessively deep and possibly infinite") then most
* likely you have a string that's longer than 30 characters.
* Address this by reducing the length if possible, otherwise, you'll need to add a 3rd ternary which
* parses 3 chars at a time :grimace:
*
* For more details see this PR comment: https://github.com/microsoft/TypeScript/pull/40336#issuecomment-686723087
*/
type CamelToSnake<T extends string> = string extends T
? string
: T extends `${infer C0}${infer C1}${infer R}`
? `${C0 extends Uppercase<C0> ? '_' : ''}${Lowercase<C0>}${C1 extends Uppercase<C1>
? '_'
: ''}${Lowercase<C1>}${CamelToSnake<R>}`
: T extends `${infer C0}${infer R}`
? `${C0 extends Uppercase<C0> ? '_' : ''}${Lowercase<C0>}${CamelToSnake<R>}`
: '';
19 changes: 19 additions & 0 deletions packages/kbn-actions-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
3 changes: 3 additions & 0 deletions packages/kbn-alerting-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/alerting-types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to add some explanation for future user?


Empty package generated by @kbn/generate
12 changes: 12 additions & 0 deletions packages/kbn-alerting-types/action_group_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export interface ActionGroup<ActionGroupIds extends string> {
id: ActionGroupIds;
name: string;
}
21 changes: 21 additions & 0 deletions packages/kbn-alerting-types/builtin_action_groups_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { ActionGroup } from './action_group_types';

export const RecoveredActionGroup: Readonly<ActionGroup<'recovered'>> = Object.freeze({
id: 'recovered',
name: i18n.translate('alertingTypes.builtinActionGroups.recovered', {
defaultMessage: 'Recovered',
}),
});

export type DefaultActionGroupId = 'default';

export type RecoveredActionGroupId = typeof RecoveredActionGroup['id'];
11 changes: 11 additions & 0 deletions packages/kbn-alerting-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './builtin_action_groups_types';
export * from './rule_type';
export * from './action_group_types';
13 changes: 13 additions & 0 deletions packages/kbn-alerting-types/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-alerting-types'],
};
5 changes: 5 additions & 0 deletions packages/kbn-alerting-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/alerting-types",
"owner": "@elastic/response-ops"
}
6 changes: 6 additions & 0 deletions packages/kbn-alerting-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/alerting-types",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
55 changes: 55 additions & 0 deletions packages/kbn-alerting-types/rule_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { LicenseType } from '@kbn/licensing-plugin/common/types';
import type { RecoveredActionGroupId, DefaultActionGroupId } from './builtin_action_groups_types';
import { ActionGroup } from './action_group_types';

interface ConsumerPrivileges {
read: boolean;
all: boolean;
}

export interface ActionVariable {
name: string;
description: string;
deprecated?: boolean;
useWithTripleBracesInTemplates?: boolean;
usesPublicBaseUrl?: boolean;
}

export interface RuleType<
ActionGroupIds extends Exclude<string, RecoveredActionGroupId> = DefaultActionGroupId,
RecoveryActionGroupId extends string = RecoveredActionGroupId
> {
id: string;
name: string;
actionGroups: Array<ActionGroup<ActionGroupIds>>;
recoveryActionGroup: ActionGroup<RecoveryActionGroupId>;
actionVariables: {
context: ActionVariable[];
state: ActionVariable[];
params: ActionVariable[];
};
defaultActionGroupId: ActionGroupIds;
category: string;
producer: string;
minimumLicenseRequired: LicenseType;
isExportable: boolean;
ruleTaskTimeout?: string;
defaultScheduleInterval?: string;
doesSetRecoveryContext?: boolean;
enabledInLicense: boolean;
authorizedConsumers: Record<string, ConsumerPrivileges>;
}

export type ActionGroupIdsOf<T> = T extends ActionGroup<infer groups>
? groups
: T extends Readonly<ActionGroup<infer groups>>
? groups
: never;
22 changes: 22 additions & 0 deletions packages/kbn-alerting-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/i18n",
"@kbn/licensing-plugin",
]
}
5 changes: 5 additions & 0 deletions packages/kbn-alerts-ui-shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export { AlertLifecycleStatusBadge } from './src/alert_lifecycle_status_badge';
export type { AlertLifecycleStatusBadgeProps } from './src/alert_lifecycle_status_badge';
export { MaintenanceWindowCallout } from './src/maintenance_window_callout';
export { AddMessageVariables } from './src/add_message_variables';

export * from './src/alerts_search_bar/hooks';
export * from './src/alerts_search_bar/apis';
export { AlertsSearchBar } from './src/alerts_search_bar';
export type { AlertsSearchBarProps } from './src/alerts_search_bar/types';
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
EuiToolTip,
EuiSelectableOption,
} from '@elastic/eui';
import { ActionVariable } from '@kbn/alerting-plugin/common';
import type { ActionVariable } from '@kbn/alerting-types';
import './add_message_variables.scss';
import { TruncatedText } from './truncated_text';
import * as i18n from './translations';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { HttpStart } from '@kbn/core/public';
import type { DataViewField } from '@kbn/data-views-plugin/common';
import { BASE_RAC_ALERTS_API_PATH, EMPTY_AAD_FIELDS } from '../constants';

export async function fetchAadFields({
http,
ruleTypeId,
}: {
http: HttpStart;
ruleTypeId?: string;
}): Promise<DataViewField[]> {
if (!ruleTypeId) return EMPTY_AAD_FIELDS;
const fields = await http.get<DataViewField[]>(`${BASE_RAC_ALERTS_API_PATH}/aad_fields`, {
query: { ruleTypeId },
});

return fields;
}
Loading
Loading