Skip to content

Commit

Permalink
Move ItemBuffer to package (#196455)
Browse files Browse the repository at this point in the history
## Summary

Part of #186139.

Bfetch exports `ItemBuffer` and `TimedItemBuffer`, the latter of which
is also used inside of the content management plugin.

After bfetch is removed, content management will be the sole consumer,
which is why I've added the team ownership to be appex-sharedux.

### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
lukasolson and kibanamachine authored Oct 18, 2024
1 parent 96585a5 commit b0bae06
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ x-pack/plugins/observability_solution/investigate @elastic/obs-ux-management-tea
packages/kbn-investigation-shared @elastic/obs-ux-management-team
packages/kbn-io-ts-utils @elastic/obs-knowledge-team
packages/kbn-ipynb @elastic/search-kibana
packages/kbn-item-buffer @elastic/appex-sharedux
packages/kbn-jest-serializers @elastic/kibana-operations
packages/kbn-journeys @elastic/kibana-operations @elastic/appex-qa
packages/kbn-json-ast @elastic/kibana-operations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@
"@kbn/investigation-shared": "link:packages/kbn-investigation-shared",
"@kbn/io-ts-utils": "link:packages/kbn-io-ts-utils",
"@kbn/ipynb": "link:packages/kbn-ipynb",
"@kbn/item-buffer": "link:packages/kbn-item-buffer",
"@kbn/json-schemas": "link:x-pack/packages/ml/json_schemas",
"@kbn/kbn-health-gateway-status-plugin": "link:test/health_gateway/plugins/status",
"@kbn/kbn-sample-panel-action-plugin": "link:test/plugin_functional/plugins/kbn_sample_panel_action",
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-item-buffer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @kbn/item-buffer

`ItemBuffer`: A simple buffer that collects items. Can be cleared or flushed; and can automatically flush when specified number of items is reached.
`TimedItemBuffer`: An `ItemBuffer` that flushes buffer when oldest item reaches age specified by this parameter, in milliseconds.
11 changes: 11 additions & 0 deletions packages/kbn-item-buffer/index.ts
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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { ItemBuffer, TimedItemBuffer } from './src';
export type { ItemBufferParams, TimedItemBufferParams } from './src';
14 changes: 14 additions & 0 deletions packages/kbn-item-buffer/jest.config.js
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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-item-buffer'],
};
5 changes: 5 additions & 0 deletions packages/kbn-item-buffer/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/item-buffer",
"owner": "@elastic/appex-sharedux"
}
6 changes: 6 additions & 0 deletions packages/kbn-item-buffer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/item-buffer",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
11 changes: 11 additions & 0 deletions packages/kbn-item-buffer/src/index.ts
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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './item_buffer';
export * from './timed_item_buffer';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ItemBuffer } from '../item_buffer';
import { runItemBufferTests } from './run_item_buffer_tests';
import { ItemBuffer } from './item_buffer';
import { runItemBufferTests } from './__test__/run_item_buffer_tests';

runItemBufferTests(ItemBuffer);
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { TimedItemBuffer } from '../timed_item_buffer';
import { runItemBufferTests } from './run_item_buffer_tests';
import { TimedItemBuffer } from './timed_item_buffer';
import { runItemBufferTests } from './__test__/run_item_buffer_tests';

jest.useFakeTimers({ legacyFakeTimers: true });

Expand Down
17 changes: 17 additions & 0 deletions packages/kbn-item-buffer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { createBatchedFunction } from '../create_batched_function';
import { createBatchedFunction } from './create_batched_function';

describe('createBatchedFunction', () => {
test('calls onCall every time fn is called, calls onBatch once flushOnMaxItems reached', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/bfetch/common/buffer/create_batched_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ItemBufferParams } from './item_buffer';
import { TimedItemBufferParams, TimedItemBuffer } from './timed_item_buffer';
import type { ItemBufferParams, TimedItemBufferParams } from '@kbn/item-buffer';
import { TimedItemBuffer } from '@kbn/item-buffer';

type Fn = (...args: any) => any;

Expand Down
2 changes: 0 additions & 2 deletions src/plugins/bfetch/common/buffer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './item_buffer';
export * from './timed_item_buffer';
export * from './create_batched_function';
3 changes: 1 addition & 2 deletions src/plugins/bfetch/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

export { normalizeError, removeLeadingSlash, appendQueryParam } from './util';
export type { StreamingResponseHandler } from './streaming';
export type { ItemBufferParams, TimedItemBufferParams, BatchedFunctionParams } from './buffer';
export { ItemBuffer, TimedItemBuffer, createBatchedFunction } from './buffer';
export { type BatchedFunctionParams, createBatchedFunction } from './buffer';
export type { ErrorLike, BatchRequestData, BatchResponseItem, BatchItemWrapper } from './batch';
export {
DISABLE_BFETCH_COMPRESSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
*/

import { AbortError, abortSignalToPromise, defer } from '@kbn/kibana-utils-plugin/public';
import {
ItemBufferParams,
TimedItemBufferParams,
createBatchedFunction,
ErrorLike,
normalizeError,
} from '../../common';
import type { ItemBufferParams, TimedItemBufferParams } from '@kbn/item-buffer';
import { createBatchedFunction, ErrorLike, normalizeError } from '../../common';
import { fetchStreaming } from '../streaming';
import { BatchedFunc, BatchItem } from './types';

Expand Down
1 change: 1 addition & 0 deletions src/plugins/bfetch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@kbn/core-http-common",
"@kbn/bfetch-error",
"@kbn/ebt-tools",
"@kbn/item-buffer",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type { CoreSetup } from '@kbn/core/server';
import { TimedItemBuffer } from '@kbn/bfetch-plugin/common';
import { TimedItemBuffer } from '@kbn/item-buffer';
import type {
EventStreamClient,
EventStreamClientFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/content_management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@kbn/core-http-request-handler-context-server",
"@kbn/es-query",
"@kbn/core-test-helpers-kbn-server",
"@kbn/bfetch-plugin",
"@kbn/item-buffer",
"@kbn/object-versioning",
"@kbn/core-saved-objects-api-server-mocks",
"@kbn/core-saved-objects-api-server",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,8 @@
"@kbn/io-ts-utils/*": ["packages/kbn-io-ts-utils/*"],
"@kbn/ipynb": ["packages/kbn-ipynb"],
"@kbn/ipynb/*": ["packages/kbn-ipynb/*"],
"@kbn/item-buffer": ["packages/kbn-item-buffer"],
"@kbn/item-buffer/*": ["packages/kbn-item-buffer/*"],
"@kbn/jest-serializers": ["packages/kbn-jest-serializers"],
"@kbn/jest-serializers/*": ["packages/kbn-jest-serializers/*"],
"@kbn/journeys": ["packages/kbn-journeys"],
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5447,6 +5447,10 @@
version "0.0.0"
uid ""

"@kbn/item-buffer@link:packages/kbn-item-buffer":
version "0.0.0"
uid ""

"@kbn/jest-serializers@link:packages/kbn-jest-serializers":
version "0.0.0"
uid ""
Expand Down

0 comments on commit b0bae06

Please sign in to comment.