Skip to content

Commit

Permalink
zed: Use stayalive endpoint
Browse files Browse the repository at this point in the history
Use stayalive endpoint and get rid of node-pipe.

Closes #2884
  • Loading branch information
mattnibs committed Jan 3, 2024
1 parent 080258f commit e00ad2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
5 changes: 1 addition & 4 deletions apps/zui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
"dependencies": {
"keytar": "^7.7.0"
},
"optionalDependencies": {
"node-pipe": "^0.1.1"
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@brimdata/zed-js": "workspace:*",
Expand Down Expand Up @@ -158,7 +155,7 @@
"use-resize-observer": "^8.0.0",
"web-file-polyfill": "^1.0.4",
"web-streams-polyfill": "^3.2.0",
"zed": "brimdata/zed#bbaa82066253a9121ed67d37a9dbe599c30fbd44",
"zed": "brimdata/zed#04d9cbb2cf386b4f1e141c537487d31ec3613b32",
"zui-test-data": "workspace:*"
},
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/zed-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
},
"dependencies": {
"@brimdata/zed-js": "workspace:*",
"fs-extra": "^11.1.1",
"node-fetch": "^2.6.2"
"fs-extra": "^11.1.1"
},
"peerDependencies": {
"zed": "*"
Expand Down
27 changes: 13 additions & 14 deletions packages/zed-node/src/lake.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
import { mkdirpSync } from 'fs-extra';
import { join } from 'path';
import fetch from 'node-fetch';
import { getZedPath } from './binpath';
import { get } from 'http';

type ConstructorOpts = {
root: string;
Expand Down Expand Up @@ -31,7 +31,7 @@ export class Lake {
return `localhost:${this.port}`;
}

start() {
async start() {
mkdirpSync(this.root, { mode: 0o755 });
mkdirpSync(this.logs, { mode: 0o755 });

Expand All @@ -45,6 +45,8 @@ export class Lake {
'-log.filemode=rotate',
'-log.path',
join(this.logs, 'zlake.log'),
'-stayalivetimeout',
'5s',
];
for (const origin of this.cors) {
args.push(`--cors.origin=${origin}`);
Expand All @@ -54,23 +56,20 @@ export class Lake {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
};
// For unix systems, pass posix pipe read file descriptor into lake process.
// In the event of Zui getting shutdown via `SIGKILL`, this will let lake
// know that it has been orphaned and to shutdown.

if (process.platform !== 'win32') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { readfd } = require('node-pipe').pipeSync();
opts.stdio.push(readfd);
args.push(`-brimfd=${opts.stdio.length - 1}`);
}

this.lake = spawn(this.bin, args, opts as SpawnOptions);
this.lake.on('error', (err) => {
console.error('lake spawn error', err);
});

return waitFor(async () => this.isUp());
await waitFor(async () => this.isUp());
// Poll the stayalive endpoint for the life of the program. If the
// connection goes away the Zed process know that it has been orphaned and
// will shutdown.
get(`http://${this.addr()}/stayalive`, (res) => {
if (res.statusCode !== 200) {
console.error(`error polling stayalive endpoint: ${res.statusCode} ${res.statusMessage}`)
}
})
}

async stop(): Promise<boolean> {
Expand Down
34 changes: 5 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,6 @@ __metadata:
"@types/fs-extra": ^11.0.1
"@types/node-fetch": ^2.6.2
fs-extra: ^11.1.1
node-fetch: ^2.6.2
zed: "github:brimdata/zed#main"
peerDependencies:
zed: "*"
Expand Down Expand Up @@ -14264,15 +14263,6 @@ __metadata:
languageName: node
linkType: hard

"node-addon-api@npm:*":
version: 6.1.0
resolution: "node-addon-api@npm:6.1.0"
dependencies:
node-gyp: latest
checksum: 3a539510e677cfa3a833aca5397300e36141aca064cdc487554f2017110709a03a95da937e98c2a14ec3c626af7b2d1b6dabe629a481f9883143d0d5bff07bf2
languageName: node
linkType: hard

"node-addon-api@npm:^1.6.3":
version: 1.7.2
resolution: "node-addon-api@npm:1.7.2"
Expand Down Expand Up @@ -14300,7 +14290,7 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:*, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.11, node-fetch@npm:^2.6.2, node-fetch@npm:^2.6.7":
"node-fetch@npm:*, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.11, node-fetch@npm:^2.6.7":
version: 2.6.11
resolution: "node-fetch@npm:2.6.11"
dependencies:
Expand Down Expand Up @@ -14359,16 +14349,6 @@ __metadata:
languageName: node
linkType: hard

"node-pipe@npm:^0.1.1":
version: 0.1.1
resolution: "node-pipe@npm:0.1.1"
dependencies:
node-addon-api: "*"
node-gyp: latest
conditions: (os=darwin | os=linux)
languageName: node
linkType: hard

"node-releases@npm:^2.0.13":
version: 2.0.13
resolution: "node-releases@npm:2.0.13"
Expand Down Expand Up @@ -19099,10 +19079,10 @@ __metadata:
languageName: node
linkType: hard

"zed@brimdata/zed#bbaa82066253a9121ed67d37a9dbe599c30fbd44":
"zed@brimdata/zed#04d9cbb2cf386b4f1e141c537487d31ec3613b32":
version: 0.33.0-dev
resolution: "zed@https://github.com/brimdata/zed.git#commit=bbaa82066253a9121ed67d37a9dbe599c30fbd44"
checksum: 0bcf867e9acd6605c775d4b3c62d1e92d575c07629ba5cd46ba24925139397a77b0f48283e38213fbd559a591be0c930256e9c051c1d2b46cee82aa012155b7f
resolution: "zed@https://github.com/brimdata/zed.git#commit=04d9cbb2cf386b4f1e141c537487d31ec3613b32"
checksum: cfb7d40d24d80ce89a10a023a18765a0f19f077a66e25b11481c3c60b283ec8d4e4c496f03462ea8e74759f88a2f8f401183fdfcbfe5a71420494aaa1249db28
languageName: node
linkType: hard

Expand Down Expand Up @@ -19261,7 +19241,6 @@ __metadata:
msw: ^0.36.8
next: ^13.3.0
node-fetch: ^2.6.1
node-pipe: ^0.1.1
nodemon: ^2.0.22
npm-run-all: ^4.1.5
ohm-js: ^17.0.4
Expand Down Expand Up @@ -19298,13 +19277,10 @@ __metadata:
use-resize-observer: ^8.0.0
web-file-polyfill: ^1.0.4
web-streams-polyfill: ^3.2.0
zed: "brimdata/zed#bbaa82066253a9121ed67d37a9dbe599c30fbd44"
zed: "brimdata/zed#04d9cbb2cf386b4f1e141c537487d31ec3613b32"
zui-test-data: "workspace:*"
peerDependencies:
react: ^18.0.0
react-dom: ^18.0.0
dependenciesMeta:
node-pipe:
optional: true
languageName: unknown
linkType: soft

0 comments on commit e00ad2d

Please sign in to comment.