-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌊 Refactor APIs to follow Elasticsearch conventions (#204671)
## Summary This PR refactors the API by creating a new packaged called `@kbn/streams-schema` where you can find all the Zod types along with some type guards. I've also updated all the API's and calls to use the new schemas. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Joe Reuter <[email protected]>
- Loading branch information
1 parent
34bc507
commit 5ae53d4
Showing
90 changed files
with
1,486 additions
and
613 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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 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 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 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/streams-schema | ||
|
||
This shared package contains the Zod schema definition for the Streams project. |
This file contains 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,10 @@ | ||
/* | ||
* 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 './src/apis'; | ||
export * from './src/models'; | ||
export * from './src/helpers'; |
This file contains 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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/packages/kbn-streams-schema'], | ||
}; |
This file contains 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 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/streams-schema", | ||
"owner": "@elastic/streams-program-team", | ||
"group": "observability", | ||
"visibility": "shared" | ||
} | ||
|
This file contains 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 @@ | ||
{ | ||
"name": "@kbn/streams-schema", | ||
"description": "Streams Zod schema definition and common models shared between public and server.", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0" | ||
} |
105 changes: 105 additions & 0 deletions
105
x-pack/packages/kbn-streams-schema/src/apis/__snapshots__/read_streams_response.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,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 * from './read_streams_response'; | ||
export * from './list_streams_response'; |
14 changes: 14 additions & 0 deletions
14
x-pack/packages/kbn-streams-schema/src/apis/list_streams_response.ts
This file contains 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,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. | ||
*/ | ||
import { z } from '@kbn/zod'; | ||
import { streamDefintionSchema } from '../models'; | ||
|
||
export const listStreamsResponseSchema = z.object({ | ||
streams: z.array(streamDefintionSchema), | ||
}); | ||
|
||
export type ListStreamsResponse = z.infer<typeof listStreamsResponseSchema>; |
15 changes: 15 additions & 0 deletions
15
x-pack/packages/kbn-streams-schema/src/apis/read_streams_response.test.ts
This file contains 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,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. | ||
*/ | ||
|
||
import { readStreamResponse } from '../fixtures/read_streams_response'; | ||
import { readStreamResponseSchema } from './read_streams_response'; | ||
|
||
describe('ReadStreamResponse', () => { | ||
it('should successfully parse', () => { | ||
expect(readStreamResponseSchema.parse(readStreamResponse)).toMatchSnapshot(); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
x-pack/packages/kbn-streams-schema/src/apis/read_streams_response.ts
This file contains 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,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. | ||
*/ | ||
|
||
import { z } from '@kbn/zod'; | ||
import { readStreamDefinitonSchema } from '../models'; | ||
|
||
export const readStreamResponseSchema = z.object({ | ||
streams: z.array(readStreamDefinitonSchema), | ||
}); | ||
|
||
export type ReadStreamResponse = z.infer<typeof readStreamResponseSchema>; |
22 changes: 22 additions & 0 deletions
22
x-pack/packages/kbn-streams-schema/src/fixtures/ingest_read_stream.ts
This file contains 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,22 @@ | ||
/* | ||
* 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 { ingestStream } from './ingest_stream'; | ||
|
||
export const ingestReadStream = { | ||
...ingestStream, | ||
inherited_fields: { | ||
'@timestamp': { | ||
type: 'date', | ||
from: 'logs', | ||
}, | ||
message: { | ||
type: 'match_only_text', | ||
from: 'logs', | ||
}, | ||
}, | ||
}; |
14 changes: 14 additions & 0 deletions
14
x-pack/packages/kbn-streams-schema/src/fixtures/ingest_stream.ts
This file contains 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,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. | ||
*/ | ||
|
||
import { ingestStreamConfig } from './ingest_stream_config'; | ||
|
||
export const ingestStream = { | ||
name: 'logs.nginx', | ||
elasticsearch_assets: [], | ||
stream: ingestStreamConfig, | ||
}; |
36 changes: 36 additions & 0 deletions
36
x-pack/packages/kbn-streams-schema/src/fixtures/ingest_stream_config.ts
This file contains 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,36 @@ | ||
/* | ||
* 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 ingestStreamConfig = { | ||
ingest: { | ||
processing: [ | ||
{ | ||
config: { | ||
grok: { | ||
field: 'message', | ||
patterns: ['%{TIMESTAMP_ISO8601:event.timestamp} %{GREEDY:rest}'], | ||
}, | ||
}, | ||
condition: { | ||
field: 'log.level', | ||
operator: 'eq', | ||
value: 'error', | ||
}, | ||
}, | ||
], | ||
routing: [ | ||
{ | ||
name: 'logs.errors', | ||
condition: { | ||
field: 'log.level', | ||
operator: 'eq', | ||
value: 'error', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
13 changes: 13 additions & 0 deletions
13
x-pack/packages/kbn-streams-schema/src/fixtures/read_streams_response.ts
This file contains 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,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. | ||
*/ | ||
|
||
import { ingestReadStream } from './ingest_read_stream'; | ||
import { wiredReadStream } from './wired_read_stream'; | ||
|
||
export const readStreamResponse = { | ||
streams: [wiredReadStream, ingestReadStream], | ||
}; |
22 changes: 22 additions & 0 deletions
22
x-pack/packages/kbn-streams-schema/src/fixtures/wired_read_stream.ts
This file contains 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,22 @@ | ||
/* | ||
* 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 { wiredStream } from './wired_stream'; | ||
|
||
export const wiredReadStream = { | ||
...wiredStream, | ||
inherited_fields: { | ||
'@timestamp': { | ||
type: 'date', | ||
from: 'logs', | ||
}, | ||
message: { | ||
type: 'match_only_text', | ||
from: 'logs', | ||
}, | ||
}, | ||
}; |
14 changes: 14 additions & 0 deletions
14
x-pack/packages/kbn-streams-schema/src/fixtures/wired_stream.ts
This file contains 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,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. | ||
*/ | ||
|
||
import { wiredStreamConfig } from './wired_stream_config'; | ||
|
||
export const wiredStream = { | ||
name: 'logs.nginx', | ||
elasticsearch_assets: [], | ||
stream: wiredStreamConfig, | ||
}; |
Oops, something went wrong.