kibana/examples/response_stream
Walter Rafelsberger 6b77e05586
[ML] AIOps: Log Rate Analysis embeddable (#197943)
## Summary

Follow up to #192167 (rebase/push gone wrong)

<img width="1920" alt="image"
src="https://github.com/user-attachments/assets/0ee12b65-0bff-4a02-805d-adab1be2a52a">

- [x] Let's users create a Log Rate Analysis panel using the "Add Panel"
button when editing dashboards.
- [x] Retains functionality of links in results table to Discover and
Pattern Analysis.
[41b4337](41b4337f9a)
- [x] Create `Logs AIOps` section in Add Panel menu.
- [x] Brushes not working with multiple panels fixed in
[75ca4ca](75ca4cac37).
The reason was the `DualBrush` component used hard coded html ids.
- [x] Panel now updates when data view is changed in options flyout,
fixed in
[2b58567](2b58567771).
- [x] When the user selects a data view without time field, we now show
the same warning as used for pattern analysis and the apply button gets
disabled, fixed in
[a01975d](a01975dba7).
- [x] Pass on and use global search/filters to embeddable.
[2c24dbd](2c24dbd116)
- [x] Moving labels
[26cd1a5](26cd1a53df)
- [x] No results after time range update
[632b711](632b711ca1)

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [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
- [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)
2024-11-05 15:48:45 +01:00
..
common Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
public [ML] AIOps: Log Rate Analysis embeddable (#197943) 2024-11-05 15:48:45 +01:00
server Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana.jsonc [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
README.md [ML] Adds redux toolkit example for response_stream to developer examples. (#182690) 2024-05-22 16:51:36 +02:00
tsconfig.json [EuiProvider] Fix Response-Stream example (#184253) 2024-05-25 10:03:47 -07:00

response stream

This plugin demonstrates how to stream chunks of data to the client with just a single request.

To run Kibana with the described examples, use yarn start --run-examples.

The response_stream plugin demonstrates API endpoints that can stream data chunks with a single request with gzip/compression support. gzip-streams get decompressed natively by browsers. The plugin demonstrates some use cases to get you started:

  • Streaming just a raw string.
  • Streaming NDJSON with "old-school" redux like actions and client side state managed with useFetchStream(). This uses React's own useReducer() under the hood.
  • Streaming NDJSON with actions created via Redux Toolkit's createSlice() to a client with a full Redux Toolkit setup.

Code in @kbn/ml-response-stream contains helpers to set up a stream on the server side (streamFactory()) and consume it on the client side via a custom hook (useFetchStream()) or slice (streamSlice()). The utilities make use of TS generics in a way that allows to have type safety for both request related options as well as the returned data.

Besides Redux Toolkit for its particular use case, no additional third party libraries are used in the helpers to make it work. On the server, they integrate with Hapi and use node's own gzip. On the client, the custom hook abstracts away the necessary logic to consume the stream, internally it makes use of a generator function and useReducer() to update React state.

On the server, the simpler stream to send a string is set up like this:

const { end, push, responseWithHeaders } = streamFactory(request.headers);

The request's headers get passed on to automatically identify if compression is supported by the client.

On the client, the custom hook is used like this:

const { errors, start, cancel, data, isRunning } = useFetchStream(
  '/internal/response_stream/simple_string_stream'
);