Skip to content

Commit

Permalink
[ObsUX][Synthtrace] Replace multistream use with own util method (e…
Browse files Browse the repository at this point in the history
…lastic#203988)

## Summary

A whole dependency was being pulled in for doing something that could
easily be done just using Node.js own utils and be made into a simple
method. As such, `multistream` has been removed since there is no other
place in the codebase that is using it.

## How to test

* Load Kibana local dev environment using synthtrace data/scenarios. No
scenario should fail to load normally, and all tests using synthtrace
data should pass as expected.

Closes elastic#203860
  • Loading branch information
Bluefinger authored Dec 12, 2024
1 parent 2ab8a5c commit d9f8f17
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,6 @@
"@types/minimist": "^1.2.5",
"@types/mock-fs": "^4.13.1",
"@types/moment-duration-format": "^2.2.3",
"@types/multistream": "^4.1.0",
"@types/mustache": "^0.8.31",
"@types/nock": "^10.0.3",
"@types/node": "20.10.5",
Expand Down Expand Up @@ -1798,7 +1797,6 @@
"mock-fs": "^5.1.2",
"ms-chromium-edge-driver": "^0.5.1",
"msw": "^2.4.12",
"multistream": "^4.1.0",
"mutation-observer": "^1.0.3",
"native-hdr-histogram": "^1.0.0",
"nock": "12.0.3",
Expand Down
24 changes: 21 additions & 3 deletions packages/kbn-apm-synthtrace/src/lib/utils/stream_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@
*/

import { eachSeries } from 'async';
import MultiStream from 'multistream';
import { Duplex, Readable, Transform } from 'stream';
import { Duplex, Readable, Transform, PassThrough } from 'stream';

/**
* Pipe one or many streams sequentially into the destination stream. Once all
* source streams have been exhausted, the destination stream is ended.
* @param sources A collection of streams to read from
* @param destination The stream to pipe data to
*/
async function combineStreams(sources: Readable[], destination: PassThrough) {
for (const stream of sources) {
await new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
stream.pipe(destination, { end: false });
});
}
destination.emit('end');
}

export function sequential(...streams: Readable[]) {
return new MultiStream(streams, { objectMode: true });
const output = new PassThrough({ objectMode: true });
combineStreams(streams, output).catch((err) => output.destroy(err));
return output;
}

export function fork(...streams: Transform[]): Duplex {
Expand Down
15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11937,13 +11937,6 @@
dependencies:
moment ">=2.14.0"

"@types/multistream@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@types/multistream/-/multistream-4.1.0.tgz#517770a32e5715fdda87904a6da7d179142feba4"
integrity sha512-KiMkWve/Uu0qwCtNO6ZflMLjglkXsAdLdIwb31o5YQBbevdH2DF7inqebCli+F9am8McvEqCE4GXNOUZe8jOAg==
dependencies:
"@types/node" "*"

"@types/mustache@^0.8.31":
version "0.8.31"
resolved "https://registry.yarnpkg.com/@types/mustache/-/mustache-0.8.31.tgz#7c86cbf74f7733f9e3bdc28817623927eb386616"
Expand Down Expand Up @@ -24796,14 +24789,6 @@ multipipe@^1.0.2:
duplexer2 "^0.1.2"
object-assign "^4.1.0"

multistream@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/multistream/-/multistream-4.1.0.tgz#7bf00dfd119556fbc153cff3de4c6d477909f5a8"
integrity sha512-J1XDiAmmNpRCBfIWJv+n0ymC4ABcf/Pl+5YvC5B/D2f/2+8PtHvCNxMPKiQcZyi922Hq69J2YOpb1pTywfifyw==
dependencies:
once "^1.4.0"
readable-stream "^3.6.0"

murmurhash-js@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/murmurhash-js/-/murmurhash-js-1.0.0.tgz#b06278e21fc6c37fa5313732b0412bcb6ae15f51"
Expand Down

0 comments on commit d9f8f17

Please sign in to comment.