Skip to content

Commit

Permalink
Merge branch 'main' into feature-fleet-space-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 13, 2024
2 parents adfe22c + ca98a8b commit 2e3453e
Show file tree
Hide file tree
Showing 144 changed files with 2,394 additions and 813 deletions.
6 changes: 3 additions & 3 deletions .buildkite/pipelines/esql_grammar_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ steps:
provider: gcp
machineType: n2-standard-2
preemptible: true
- command: .buildkite/scripts/steps/esql_generate_function_definitions.sh
label: Generate Function Definitions
timeout_in_minutes: 10
- command: .buildkite/scripts/steps/esql_generate_function_metadata.sh
label: Generate Function Metadata
timeout_in_minutes: 15
agents:
image: family/kibana-ubuntu-2004
imageProject: elastic-images-prod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

VALIDATION_PACKAGE_DIR="packages/kbn-esql-validation-autocomplete"
EDITOR_PACKAGE_DIR="packages/kbn-text-based-editor"
GIT_SCOPE="$VALIDATION_PACKAGE_DIR/**/* $EDITOR_PACKAGE_DIR/**/*"

report_main_step () {
echo "--- $1"
}
Expand All @@ -19,7 +23,7 @@ main () {

.buildkite/scripts/bootstrap.sh

cd "$KIBANA_DIR/packages/kbn-esql-validation-autocomplete"
cd "$KIBANA_DIR/$VALIDATION_PACKAGE_DIR"

report_main_step "Generate function definitions"

Expand All @@ -29,9 +33,21 @@ main () {

yarn make:tests

report_main_step "Generate inline function docs"

cd "$KIBANA_DIR/$EDITOR_PACKAGE_DIR"

yarn make:docs $PARENT_DIR/elasticsearch

report_main_step "Run i18n check"

cd "$KIBANA_DIR"

node scripts/i18n_check.js --fix

# Check for differences
set +e
git diff --exit-code --quiet .
git diff --exit-code --quiet $GIT_SCOPE
if [ $? -eq 0 ]; then
echo "No differences found. Our work is done here."
exit
Expand All @@ -44,8 +60,8 @@ main () {
git config --global user.name "$KIBANA_MACHINE_USERNAME"
git config --global user.email '[email protected]'

PR_TITLE='[ES|QL] Update function definitions'
PR_BODY='This PR updates the function definitions based on the latest metadata from Elasticsearch.'
PR_TITLE='[ES|QL] Update function metadata'
PR_BODY='This PR updates the function definitions and inline docs based on the latest metadata from Elasticsearch.'

# Check if a PR already exists
pr_search_result=$(gh pr list --search "$PR_TITLE" --state open --author "$KIBANA_MACHINE_USERNAME" --limit 1 --json title -q ".[].title")
Expand All @@ -58,12 +74,12 @@ main () {
echo "No existing PR found. Committing changes."

# Make a commit
BRANCH_NAME="esql_generate_function_definitions_$(date +%s)"
BRANCH_NAME="esql_generate_function_metadata_$(date +%s)"

git checkout -b "$BRANCH_NAME"

git add ./**/*
git commit -m "Update function definitions"
git add $GIT_SCOPE
git commit -m "Update function metadata"

report_main_step "Changes committed. Creating pull request."

Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ x-pack/test/observability_ai_assistant_functional @elastic/obs-ai-assistant
/WORKSPACE.bazel @elastic/kibana-operations
/.buildkite/ @elastic/kibana-operations
/.buildkite/scripts/steps/esql_grammar_sync.sh @elastic/kibana-esql
/.buildkite/scripts/steps/esql_generate_function_definitions.sh @elastic/kibana-esql
/.buildkite/scripts/steps/esql_generate_function_metadata.sh @elastic/kibana-esql
/.buildkite/pipelines/esql_grammar_sync.yml @elastic/kibana-esql
/kbn_pm/ @elastic/kibana-operations
/x-pack/dev-tools @elastic/kibana-operations
Expand Down
34 changes: 34 additions & 0 deletions packages/kbn-alerting-types/alerting_framework_health_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 enum HealthStatus {
OK = 'ok',
Warning = 'warn',
Error = 'error',
}

export interface AlertsHealth {
decryptionHealth: {
status: HealthStatus;
timestamp: string;
};
executionHealth: {
status: HealthStatus;
timestamp: string;
};
readHealth: {
status: HealthStatus;
timestamp: string;
};
}

export interface AlertingFrameworkHealth {
isSufficientlySecure: boolean;
hasPermanentEncryptionKey: boolean;
alertingFrameworkHealth: AlertsHealth;
}
1 change: 1 addition & 0 deletions packages/kbn-alerting-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export * from './alert_type';
export * from './rule_notify_when_type';
export * from './r_rule_types';
export * from './rule_types';
export * from './alerting_framework_health_types';
export * from './action_variable';
13 changes: 12 additions & 1 deletion packages/kbn-alerting-types/rule_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
* Side Public License, v 1.
*/

import type { SavedObjectAttributes } from '@kbn/core/server';
import type {
SavedObjectAttribute,
SavedObjectAttributes,
SavedObjectsResolveResponse,
} from '@kbn/core/server';
import type { Filter } from '@kbn/es-query';
import type { RuleNotifyWhenType, RRuleParams } from '.';

export type RuleTypeParams = Record<string, unknown>;
export type RuleActionParams = SavedObjectAttributes;
export type RuleActionParam = SavedObjectAttribute;

export const ISO_WEEKDAYS = [1, 2, 3, 4, 5, 6, 7] as const;
export type IsoWeekday = typeof ISO_WEEKDAYS[number];
Expand Down Expand Up @@ -239,3 +244,9 @@ export type SanitizedRule<Params extends RuleTypeParams = never> = Omit<
Rule<Params>,
'apiKey' | 'actions'
> & { actions: SanitizedRuleAction[] };

export type ResolvedSanitizedRule<Params extends RuleTypeParams = never> = SanitizedRule<Params> &
Omit<SavedObjectsResolveResponse, 'saved_object'> & {
outcome: string;
alias_target_id?: string;
};
2 changes: 1 addition & 1 deletion packages/kbn-alerts-ui-shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export type { AlertsSearchBarProps } from './src/alerts_search_bar/types';

export * from './src/alert_fields_table';
export * from './src/alert_filter_controls/types';
export * from './src/common/hooks';
export * from './src/common/types';
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 { httpServiceMock } from '@kbn/core/public/mocks';
import { RuleUpdates } from '../../../types';
import { createRule } from './create';
import { RuleTypeParams } from '../../types';
import { createRule } from './create_rule';
import { CreateRuleBody } from './types';

const http = httpServiceMock.createStartContract();

Expand Down Expand Up @@ -62,10 +64,7 @@ describe('createRule', () => {
},
};

const ruleToCreate: Omit<
RuleUpdates,
'createdBy' | 'updatedBy' | 'muteAll' | 'mutedInstanceIds' | 'executionStatus'
> = {
const ruleToCreate: CreateRuleBody<RuleTypeParams> = {
params: {
aggType: 'count',
termSize: 5,
Expand Down Expand Up @@ -106,17 +105,14 @@ describe('createRule', () => {
actionTypeId: '.system-action',
},
],
createdAt: new Date('2021-04-01T21:33:13.247Z'),
updatedAt: new Date('2021-04-01T21:33:13.247Z'),
apiKeyOwner: '',
revision: 0,
notifyWhen: 'onActionGroupChange',
alertDelay: {
active: 10,
},
};
http.post.mockResolvedValueOnce(resolvedValue);

const result = await createRule({ http, rule: ruleToCreate });
const result = await createRule({ http, rule: ruleToCreate as CreateRuleBody });
expect(result).toEqual({
actions: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { HttpSetup } from '@kbn/core/public';
import type { AsApiContract } from '@kbn/actions-types';
import type { Rule } from '../../types';
import { CreateRuleBody, transformCreateRuleBody } from '.';
import { BASE_ALERTING_API_PATH } from '../../constants';
import { transformRule } from '../../transformations';

export async function createRule({
http,
rule,
}: {
http: HttpSetup;
rule: CreateRuleBody;
}): Promise<Rule> {
const res = await http.post<AsApiContract<Rule>>(`${BASE_ALERTING_API_PATH}/rule`, {
body: JSON.stringify(transformCreateRuleBody(rule)),
});
return transformRule(res);
}
11 changes: 11 additions & 0 deletions packages/kbn-alerts-ui-shared/src/common/apis/create_rule/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 './types';
export * from './create_rule';
export * from './transform_create_rule_body';
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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 { transformCreateRuleBody } from './transform_create_rule_body';
import type { RuleTypeParams } from '../../types';
import type { CreateRuleBody } from './types';

const ruleToCreate: CreateRuleBody<RuleTypeParams> = {
params: {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000],
index: ['.kibana'],
timeField: 'alert.executionStatus.lastExecutionDate',
},
consumer: 'alerts',
schedule: { interval: '1m' },
tags: [],
name: 'test',
enabled: true,
throttle: null,
ruleTypeId: '.index-threshold',
actions: [
{
group: 'threshold met',
id: '83d4d860-9316-11eb-a145-93ab369a4461',
params: {
level: 'info',
message: 'test-message',
},
actionTypeId: '.server-log',
frequency: {
notifyWhen: 'onActionGroupChange',
throttle: null,
summary: false,
},
useAlertDataForTemplate: true,
},
{
id: '.test-system-action',
params: {},
actionTypeId: '.system-action',
},
],
notifyWhen: 'onActionGroupChange',
alertDelay: {
active: 10,
},
};

describe('transformCreateRuleBody', () => {
test('should transform create rule body', () => {
expect(transformCreateRuleBody(ruleToCreate)).toEqual({
params: {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000],
index: ['.kibana'],
timeField: 'alert.executionStatus.lastExecutionDate',
},
consumer: 'alerts',
schedule: { interval: '1m' },
tags: [],
name: 'test',
enabled: true,
throttle: null,
notifyWhen: 'onActionGroupChange',
rule_type_id: '.index-threshold',
actions: [
{
group: 'threshold met',
id: '83d4d860-9316-11eb-a145-93ab369a4461',
params: {
level: 'info',
message: 'test-message',
},
frequency: {
notify_when: 'onActionGroupChange',
summary: false,
throttle: null,
},
use_alert_data_for_template: true,
},
{ id: '.test-system-action', params: {} },
],

alert_delay: { active: 10 },
});
});
});
Loading

0 comments on commit 2e3453e

Please sign in to comment.