Skip to content

Commit

Permalink
Merge branch 'main' into 31-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Nov 23, 2023
2 parents 03e6f6e + 17ed074 commit dd44fa8
Show file tree
Hide file tree
Showing 53 changed files with 1,341 additions and 617 deletions.
4 changes: 2 additions & 2 deletions .buildkite/pipeline-utils/ci-stats/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class CiStatsClient {
headers: this.defaultHeaders,
});
} catch (error) {
console.error('CI Stats request error:', error);
console.error('CI Stats request error:', error?.response?.data?.message);

if (attempt < maxAttempts) {
const sec = attempt * 3;
Expand All @@ -210,7 +210,7 @@ export class CiStatsClient {
continue;
}

throw error;
throw new Error('Failed to connect to CI Stats.');
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions .buildkite/scripts/lifecycle/pre_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if [[ "${GITHUB_BUILD_COMMIT_STATUS_ENABLED:-}" != "true" ]]; then
"$(dirname "${0}")/commit_status_start.sh"
fi

export CI_STATS_TOKEN="$(retry 5 5 vault read -field=api_token secret/kibana-issues/dev/kibana_ci_stats)"
export CI_STATS_HOST="$(retry 5 5 vault read -field=api_host secret/kibana-issues/dev/kibana_ci_stats)"

ts-node "$(dirname "${0}")/ci_stats_start.ts"

Expand Down
12 changes: 6 additions & 6 deletions .buildkite/scripts/lifecycle/pre_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ EOF
{
CI_STATS_BUILD_ID="$(buildkite-agent meta-data get ci_stats_build_id --default '')"
export CI_STATS_BUILD_ID

CI_STATS_TOKEN="$(retry 5 5 vault read -field=api_token secret/kibana-issues/dev/kibana_ci_stats)"
export CI_STATS_TOKEN

CI_STATS_HOST="$(retry 5 5 vault read -field=api_host secret/kibana-issues/dev/kibana_ci_stats)"
export CI_STATS_HOST

if [[ "$CI_STATS_BUILD_ID" ]]; then
echo "CI Stats Build ID: $CI_STATS_BUILD_ID"

CI_STATS_TOKEN="$(retry 5 5 vault read -field=api_token secret/kibana-issues/dev/kibana_ci_stats)"
export CI_STATS_TOKEN

CI_STATS_HOST="$(retry 5 5 vault read -field=api_host secret/kibana-issues/dev/kibana_ci_stats)"
export CI_STATS_HOST

KIBANA_CI_STATS_CONFIG=$(jq -n \
--arg buildId "$CI_STATS_BUILD_ID" \
--arg apiUrl "https://$CI_STATS_HOST" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { LicenseType } from '@kbn/licensing-plugin/server';
import type { LicenseType } from '@kbn/licensing-plugin/server';

export const PLUGIN = {
ID: 'alerting',
Expand Down
31 changes: 31 additions & 0 deletions x-pack/plugins/alerting/common/maintenance_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export enum MaintenanceWindowStatus {
Archived = 'archived',
}

export const filterStateStore = {
APP_STATE: 'appState',
GLOBAL_STATE: 'globalState',
} as const;

export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];

export interface MaintenanceWindowModificationMetadata {
createdBy: string | null;
updatedBy: string | null;
Expand All @@ -26,6 +33,23 @@ export interface DateRange {
lte: string;
}

export interface ScopeQueryFilter {
query?: Record<string, unknown>;
meta: Record<string, unknown>;
$state?: {
store: FilterStateStore;
};
}

export interface ScopedQueryAttributes {
kql: string;
filters: ScopeQueryFilter[];
dsl?: string;
}

/**
* @deprecated Use the data/maintenance_window types instead
*/
export interface MaintenanceWindowSOProperties {
title: string;
enabled: boolean;
Expand All @@ -34,11 +58,18 @@ export interface MaintenanceWindowSOProperties {
events: DateRange[];
rRule: RRuleParams;
categoryIds?: string[] | null;
scopedQuery?: ScopedQueryAttributes | null;
}

/**
* @deprecated Use the data/maintenance_window types instead
*/
export type MaintenanceWindowSOAttributes = MaintenanceWindowSOProperties &
MaintenanceWindowModificationMetadata;

/**
* @deprecated Use the application/maintenance_window types instead
*/
export type MaintenanceWindow = MaintenanceWindowSOAttributes & {
status: MaintenanceWindowStatus;
eventStartTime: string | null;
Expand Down
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { filterStateStore } from './v1';
export type { FilterStateStore } from './v1';
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const filterStateStore = {
APP_STATE: 'appState',
GLOBAL_STATE: 'globalState',
} as const;

export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];
14 changes: 14 additions & 0 deletions x-pack/plugins/alerting/common/routes/alerts_filter_query/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

export { filterStateStore } from './constants/latest';
export type { FilterStateStore } from './constants/latest';
export { alertsFilterQuerySchema } from './schemas/latest';

export { filterStateStore as filterStateStoreV1 } from './constants/v1';
export type { FilterStateStore as FilterStateStoreV1 } from './constants/v1';
export { alertsFilterQuerySchema as alertsFilterQuerySchemaV1 } from './schemas/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { alertsFilterQuerySchema } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { schema } from '@kbn/config-schema';
import { filterStateStore } from '..';

export const alertsFilterQuerySchema = schema.object({
kql: schema.string(),
filters: schema.arrayOf(
schema.object({
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
meta: schema.recordOf(schema.string(), schema.any()),
$state: schema.maybe(
schema.object({
store: schema.oneOf([
schema.literal(filterStateStore.APP_STATE),
schema.literal(filterStateStore.GLOBAL_STATE),
]),
})
),
})
),
dsl: schema.maybe(schema.string()),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import { schema } from '@kbn/config-schema';
import { maintenanceWindowCategoryIdsSchemaV1 } from '../../../shared';
import { rRuleRequestSchemaV1 } from '../../../../r_rule';
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';

export const createBodySchema = schema.object({
title: schema.string(),
duration: schema.number(),
r_rule: rRuleRequestSchemaV1,
category_ids: maintenanceWindowCategoryIdsSchemaV1,
scoped_query: schema.maybe(schema.nullable(alertsFilterQuerySchemaV1)),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { schema } from '@kbn/config-schema';
import { maintenanceWindowCategoryIdsSchemaV1 } from '../../../shared';
import { rRuleRequestSchemaV1 } from '../../../../r_rule';
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';

export const updateParamsSchema = schema.object({
id: schema.string(),
Expand All @@ -19,4 +20,5 @@ export const updateBodySchema = schema.object({
duration: schema.maybe(schema.number()),
r_rule: schema.maybe(rRuleRequestSchemaV1),
category_ids: maintenanceWindowCategoryIdsSchemaV1,
scoped_query: schema.maybe(schema.nullable(alertsFilterQuerySchemaV1)),
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema';
import { maintenanceWindowStatusV1 } from '..';
import { maintenanceWindowCategoryIdsSchemaV1 } from '../../shared';
import { rRuleResponseSchemaV1 } from '../../../r_rule';
import { alertsFilterQuerySchemaV1 } from '../../../alerts_filter_query';

export const maintenanceWindowEventSchema = schema.object({
gte: schema.string(),
Expand Down Expand Up @@ -36,4 +37,5 @@ export const maintenanceWindowResponseSchema = schema.object({
schema.literal(maintenanceWindowStatusV1.ARCHIVED),
]),
category_ids: maintenanceWindowCategoryIdsSchemaV1,
scoped_query: schema.maybe(schema.nullable(alertsFilterQuerySchemaV1)),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { schema } from '@kbn/config-schema';
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
import { notifyWhenSchemaV1 } from '../../../response';
import { filterStateStore } from '../../../common/constants/v1';
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';

export const actionFrequencySchema = schema.object({
summary: schema.boolean(),
Expand All @@ -17,26 +17,7 @@ export const actionFrequencySchema = schema.object({
});

export const actionAlertsFilterSchema = schema.object({
query: schema.maybe(
schema.object({
kql: schema.string(),
filters: schema.arrayOf(
schema.object({
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
meta: schema.recordOf(schema.string(), schema.any()),
$state: schema.maybe(
schema.object({
store: schema.oneOf([
schema.literal(filterStateStore.APP_STATE),
schema.literal(filterStateStore.GLOBAL_STATE),
]),
})
),
})
),
dsl: schema.maybe(schema.string()),
})
),
query: schema.maybe(alertsFilterQuerySchemaV1),
timeframe: schema.maybe(
schema.object({
days: schema.arrayOf(
Expand Down
22 changes: 2 additions & 20 deletions x-pack/plugins/alerting/common/routes/rule/response/schemas/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import { schema } from '@kbn/config-schema';
import { rRuleResponseSchemaV1 } from '../../../r_rule';
import { alertsFilterQuerySchemaV1 } from '../../../alerts_filter_query';
import {
ruleNotifyWhen as ruleNotifyWhenV1,
ruleExecutionStatusValues as ruleExecutionStatusValuesV1,
ruleExecutionStatusErrorReason as ruleExecutionStatusErrorReasonV1,
ruleExecutionStatusWarningReason as ruleExecutionStatusWarningReasonV1,
ruleLastRunOutcomeValues as ruleLastRunOutcomeValuesV1,
filterStateStore as filterStateStoreV1,
} from '../../common/constants/v1';
import { validateNotifyWhenV1 } from '../../validation';

Expand Down Expand Up @@ -41,25 +41,7 @@ const actionFrequencySchema = schema.object({
});

const actionAlertsFilterSchema = schema.object({
query: schema.maybe(
schema.object({
kql: schema.string(),
filters: schema.arrayOf(
schema.object({
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
meta: schema.recordOf(schema.string(), schema.any()),
$state: schema.maybe(
schema.object({
store: schema.oneOf([
schema.literal(filterStateStoreV1.APP_STATE),
schema.literal(filterStateStoreV1.GLOBAL_STATE),
]),
})
),
})
),
})
),
query: schema.maybe(alertsFilterQuerySchemaV1),
timeframe: schema.maybe(
schema.object({
days: schema.arrayOf(
Expand Down
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const filterStateStore = {
APP_STATE: 'appState',
GLOBAL_STATE: 'globalState',
} as const;

export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { schema } from '@kbn/config-schema';
import { filterStateStore } from '../constants';

export const alertsFilterQuerySchema = schema.object({
kql: schema.string(),
filters: schema.arrayOf(
schema.object({
query: schema.maybe(schema.recordOf(schema.string(), schema.any())),
meta: schema.recordOf(schema.string(), schema.any()),
$state: schema.maybe(
schema.object({
store: schema.oneOf([
schema.literal(filterStateStore.APP_STATE),
schema.literal(filterStateStore.GLOBAL_STATE),
]),
})
),
})
),
dsl: schema.maybe(schema.string()),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { alertsFilterQuerySchema } from './alerts_filter_query_schemas';
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TypeOf } from '@kbn/config-schema';
import { alertsFilterQuerySchema } from '../schemas/alerts_filter_query_schemas';

export type AlertsFilterQuery = TypeOf<typeof alertsFilterQuerySchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export type { AlertsFilterQuery } from './alerts_filter_query';
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export const maintenanceWindowStatus = {
} as const;

export const maintenanceWindowCategoryIdTypes = {
KIBANA: 'kibana',
OBSERVABILITY: 'observability',
SECURITY_SOLUTION: 'securitySolution',
MANAGEMENT: 'management',
} as const;

export const filterStateStore = {
APP_STATE: 'appState',
GLOBAL_STATE: 'globalState',
} as const;
Loading

0 comments on commit dd44fa8

Please sign in to comment.