-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ResponseOps] Alerting V2 schema package #250023
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c38da4d
create schema package
darnautov b4d6602
Changes from yarn openapi:bundle
kibanamachine c0261d3
rename package
darnautov 99a8d1d
Changes from node scripts/lint_ts_projects --fix
kibanamachine 5ea4309
Changes from node scripts/lint_packages --fix
kibanamachine 8f22d2c
Merge branch 'rule-schema-package' of github.com:darnautov/kibana int…
darnautov c67f6a3
move package to response-ops
darnautov e019c97
remove kbn- prefix
darnautov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # @kbn/alerting-v2-schemas | ||
|
|
||
| Zod schemas and shared types for alerting v2 requests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/kibana.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "shared-common", | ||
| "id": "@kbn/alerting-v2-schemas", | ||
| "owner": "@elastic/response-ops", | ||
| "group": "platform", | ||
| "visibility": "shared" | ||
| } |
8 changes: 8 additions & 0 deletions
8
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "name": "@kbn/alerting-v2-schemas", | ||
| "description": "Alerting v2 request Zod schemas and shared types.", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "license": "Elastic License 2.0", | ||
| "sideEffects": false | ||
| } |
8 changes: 8 additions & 0 deletions
8
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 * from './rule_data_schema'; | ||
67 changes: 67 additions & 0 deletions
67
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/src/rule_data_schema.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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 { Parser } from '@kbn/esql-language'; | ||
| import { z } from '@kbn/zod'; | ||
|
|
||
| const DURATION_RE = /^(\d+)(ms|s|m|h|d|w)$/; | ||
|
|
||
| const durationSchema = z.string().superRefine((value, ctx) => { | ||
| if (!DURATION_RE.test(value)) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| message: `Invalid duration "${value}". Expected format like "5m", "1h", "30s", "250ms"`, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| const withEsqlValidation = (schema: z.ZodString) => | ||
| schema.superRefine((query, ctx) => { | ||
| const errors = Parser.parseErrors(query); | ||
| if (errors.length > 0) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| message: `Invalid ES|QL query: ${errors[0].message}`, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| const scheduleSchema = z | ||
| .object({ | ||
| custom: durationSchema, | ||
| }) | ||
| .strict(); | ||
|
|
||
| export const createRuleDataSchema = z | ||
| .object({ | ||
| name: z.string().min(1).max(64), | ||
| tags: z.array(z.string().max(64)).max(100).default([]), | ||
| schedule: scheduleSchema, | ||
| enabled: z.boolean().default(true), | ||
| query: withEsqlValidation(z.string().min(1).max(10000)), | ||
| timeField: z.string().min(1).max(128).default('@timestamp'), | ||
| lookbackWindow: durationSchema, | ||
| groupingKey: z.array(z.string()).max(16).default([]), | ||
| }) | ||
| .strip(); | ||
|
|
||
| export type CreateRuleData = z.infer<typeof createRuleDataSchema>; | ||
|
|
||
| export const updateRuleDataSchema = z | ||
| .object({ | ||
| name: z.string().min(1).optional(), | ||
| tags: z.array(z.string()).optional(), | ||
| schedule: scheduleSchema.optional(), | ||
| enabled: z.boolean().optional(), | ||
| query: withEsqlValidation(z.string().min(1)).optional(), | ||
| timeField: z.string().min(1).optional(), | ||
| lookbackWindow: durationSchema.optional(), | ||
| groupingKey: z.array(z.string()).optional(), | ||
| }) | ||
| .strip(); | ||
|
|
||
| export type UpdateRuleData = z.infer<typeof updateRuleDataSchema>; |
16 changes: 16 additions & 0 deletions
16
x-pack/platform/packages/shared/response-ops/alerting-v2-schemas/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "extends": "@kbn/tsconfig-base/tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "target/types", | ||
| }, | ||
| "include": [ | ||
| "**/*.ts", | ||
| ], | ||
| "exclude": [ | ||
| "target/**/*" | ||
| ], | ||
| "kbn_references": [ | ||
| "@kbn/esql-language", | ||
| "@kbn/zod" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
...orm/plugins/shared/alerting_v2/server/lib/rules_client/schemas/create_rule_data_schema.ts
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...orm/plugins/shared/alerting_v2/server/lib/rules_client/schemas/update_rule_data_schema.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would avoid barrel export so people will not import everything if they want to use only one schema. For types thought that will not be an issue. I am mostly concerned about the UI.