forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CM] Event Stream service (elastic#153211)
## Summary This PR implements the Event Stream service for Content Management. For high-level overview see: - [Event Stream technical summary](https://docs.google.com/document/d/1nyMhb0p4gNV43OVF6cLJkxhMf2V4V1BIjPsnACxe_t0/edit#heading=h.typ7x7sxmeye) (a bit old, but still good as general overview read) Implementation details in this PR: - This PR introduces the `EventStreamService` high-level class, which is the public interface to the Event Stream, holds any necessary state, and follows plugin life-cycle methods. - On a lower level the actual event storage is defined in the `EventStreamClient` interface. - There are two `EventStreamClient` implementations: - `EsEventStreamClient` is the production implementation, which stores events to Elasticsearch. - `MemoryEventStreamClient` is used for testing and could be used for demo purposes. - The same test suite `testEventStreamClient` is reused for `EsEventStreamClient` and `MemoryEventStreamClient`, which should help with verifying that both implements work correctly and the same. For `EsEventStreamClient` it is executed as Kibana integration test, but for `MemoryEventStreamClient` it is executed as a Jest test. - In `EventStreamService` events are buffered for 250ms or up to 100 events before they are flushed to the storage. - Events are stored in the `.kibana-event-stream` data stream. - The data stream and index template are create during plugin initialization "start" life-cycle, similar to how it is done in the Event Log and in the Reporting index. - The mappings define a `meta` field, which is currently unused, but will allow to add more fields in the future without needing to change the schema of the data stream. - The mappings define a transaction ID `txId` field, which can be used to correlate multiple related events together or to store the transaction ID. - Events are written to Elasticsearch using the `_bulk` request API. ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Aleh Zasypkin <[email protected]> Co-authored-by: Anton Dosov <[email protected]>
- Loading branch information
1 parent
f5ea8ad
commit 0aeeca2
Showing
37 changed files
with
2,460 additions
and
27 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
# Content management | ||
|
||
The content management plugin provides functionality to manage content in Kibana. | ||
|
||
|
||
## Testing | ||
|
||
Many parts of the Content Management service are implemented *in-memory*, hence it | ||
is possible to test big chunks of the Content Management plugin using Jest | ||
tests. | ||
|
||
|
||
### Elasticsearch Integration tests | ||
|
||
Some functionality of the Content Management plugin can be tested using *Kibana | ||
Integration Tests*, which execute tests against a real Elasticsearch instance. | ||
|
||
Run integrations tests with: | ||
|
||
``` | ||
yarn test:jest_integration src/plugins/content_management | ||
``` |
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 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/jest_integration', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/src/plugins/content_management'], | ||
}; |
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
50 changes: 50 additions & 0 deletions
50
src/plugins/content_management/server/event_stream/README.md
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,50 @@ | ||
# Event Stream | ||
|
||
|
||
## The service | ||
|
||
On a high-level the Event Stream is exposed through the `EventStreamService` | ||
class, which is the public interface to the Event Stream, it holds any necessary | ||
state, and follows plugin life-cycle methods. | ||
|
||
The service also validates the events before they are stored. It also buffers | ||
the events on write. Events are buffered for 250ms or up to 100 events before | ||
they are flushed to the storage. | ||
|
||
|
||
## The client | ||
|
||
On a lower level the actual event storage is defined in the `EventStreamClient` | ||
interface. There are two `EventStreamClient` implementations: | ||
|
||
- `EsEventStreamClient` is the production implementation, which stores events | ||
to the Elasticsearch. | ||
- `MemoryEventStreamClient` is used for testing and could be used for demo | ||
purposes. | ||
|
||
|
||
### The `EsEventStreamClient` client | ||
|
||
`EsEventStreamClient` is used in production. It stores events in the | ||
`.kibana-event-stream` data stream. The data stream and index template are | ||
created during plugin initialization "start" life-cycle. | ||
|
||
The mappings define `meta` and `indexed` fields, which are reserved for future | ||
schema extensions (so that new fields can be added without mapping changes). | ||
|
||
The mappings also define a transaction ID (`txID`) field, which can be used to | ||
correlate multiple related events together or to store the transaction ID. | ||
|
||
Events are written to Elasticsearch using the `_bulk` request API. | ||
|
||
|
||
## Testing | ||
|
||
The `MemoryEventStreamClient` can be used to simulate the Event Stream in Jest | ||
unit test environment. Use `setupEventStreamService()` to spin up the service | ||
in the test environment. | ||
|
||
The clients themselves can be tested using the `testEventStreamClient` test | ||
suite, which should help with verifying that both implements work correctly. | ||
The `EsEventStreamClient` it is tested using Kibana integration tests, but for | ||
`MemoryEventStreamClient` it is tested as a Jest tests. |
Oops, something went wrong.