@sentio/runtime 3.0.0-rc.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chunk-757YRULG.js +38 -0
- package/lib/{chunk-CPJKSHSV.js.map → chunk-757YRULG.js.map} +1 -1
- package/lib/chunk-AUPVVLD3.js +3 -0
- package/lib/chunk-CJDESLYQ.js +3 -0
- package/lib/{chunk-L2A6JPIQ.js.map → chunk-CJDESLYQ.js.map} +1 -1
- package/lib/chunk-KF7FHZ25.js +117 -0
- package/lib/{chunk-4FNYVNIX.js.map → chunk-KF7FHZ25.js.map} +1 -1
- package/lib/chunk-TW627LH5.js +3 -0
- package/lib/{chunk-MV6JXS2P.js.map → chunk-TW627LH5.js.map} +1 -1
- package/lib/chunk-ZTRGPIW7.js +26 -0
- package/lib/{chunk-ROBPWJIE.js.map → chunk-ZTRGPIW7.js.map} +1 -1
- package/lib/getMachineId-bsd-CDSZ2S36.js +3 -0
- package/lib/{getMachineId-bsd-ZJR2OQTA.js.map → getMachineId-bsd-CDSZ2S36.js.map} +1 -1
- package/lib/getMachineId-darwin-LM5BSWCG.js +4 -0
- package/lib/{getMachineId-darwin-OW6SYINH.js.map → getMachineId-darwin-LM5BSWCG.js.map} +1 -1
- package/lib/getMachineId-linux-UA53ZQFA.js +3 -0
- package/lib/{getMachineId-linux-L5XPRJBN.js.map → getMachineId-linux-UA53ZQFA.js.map} +1 -1
- package/lib/getMachineId-unsupported-LDR77GGJ.js +3 -0
- package/lib/{getMachineId-unsupported-B3NMIOO3.js.map → getMachineId-unsupported-LDR77GGJ.js.map} +1 -1
- package/lib/getMachineId-win-XULW45X4.js +3 -0
- package/lib/{getMachineId-win-TT64F63B.js.map → getMachineId-win-XULW45X4.js.map} +1 -1
- package/lib/index.js +1 -137
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +43 -32939
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +2 -132
- package/lib/service-worker.js.map +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/db-context.ts +0 -1
- package/src/otlp.ts +20 -12
- package/src/processor-runner.ts +3 -3
- package/src/service-v3.ts +11 -18
- package/lib/chunk-4FNYVNIX.js +0 -60146
- package/lib/chunk-CPJKSHSV.js +0 -10976
- package/lib/chunk-KVSDPGUI.js +0 -50
- package/lib/chunk-L2A6JPIQ.js +0 -21
- package/lib/chunk-MV6JXS2P.js +0 -1703
- package/lib/chunk-ROBPWJIE.js +0 -25794
- package/lib/getMachineId-bsd-ZJR2OQTA.js +0 -41
- package/lib/getMachineId-darwin-OW6SYINH.js +0 -41
- package/lib/getMachineId-linux-L5XPRJBN.js +0 -33
- package/lib/getMachineId-unsupported-B3NMIOO3.js +0 -24
- package/lib/getMachineId-win-TT64F63B.js +0 -43
- /package/lib/{chunk-KVSDPGUI.js.map → chunk-AUPVVLD3.js.map} +0 -0
package/lib/service-worker.js
CHANGED
|
@@ -1,134 +1,4 @@
|
|
|
1
1
|
import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from "./chunk-CPJKSHSV.js";
|
|
5
|
-
import {
|
|
6
|
-
ProcessorServiceImpl,
|
|
7
|
-
configureEndpoints,
|
|
8
|
-
errorString,
|
|
9
|
-
freezeGlobalConfig,
|
|
10
|
-
require_cjs,
|
|
11
|
-
require_lib3 as require_lib,
|
|
12
|
-
require_lib4 as require_lib2
|
|
13
|
-
} from "./chunk-4FNYVNIX.js";
|
|
14
|
-
import "./chunk-ROBPWJIE.js";
|
|
15
|
-
import "./chunk-MV6JXS2P.js";
|
|
16
|
-
import {
|
|
17
|
-
__toESM
|
|
18
|
-
} from "./chunk-KVSDPGUI.js";
|
|
19
|
-
|
|
20
|
-
// src/service-worker.ts
|
|
21
|
-
var import_nice_grpc = __toESM(require_lib(), 1);
|
|
22
|
-
var import_nice_grpc_error_details = __toESM(require_lib2(), 1);
|
|
23
|
-
import { threadId } from "worker_threads";
|
|
24
|
-
import { Piscina } from "piscina";
|
|
25
|
-
var import_rxjs = __toESM(require_cjs(), 1);
|
|
26
|
-
var started = false;
|
|
27
|
-
var unhandled;
|
|
28
|
-
process.on("uncaughtException", (err) => {
|
|
29
|
-
console.error("Uncaught Exception, please checking if await is properly used", err);
|
|
30
|
-
unhandled = err;
|
|
31
|
-
}).on("unhandledRejection", (reason, p) => {
|
|
32
|
-
if (reason?.message.startsWith('invalid ENS name (disallowed character: "*"')) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
console.error("Unhandled Rejection, please checking if await is properly", reason);
|
|
36
|
-
unhandled = reason;
|
|
37
|
-
}).on("exit", () => {
|
|
38
|
-
console.info("Worker thread exiting, threadId:", threadId);
|
|
39
|
-
});
|
|
40
|
-
var service;
|
|
41
|
-
var loader = async (options) => {
|
|
42
|
-
if (options.target) {
|
|
43
|
-
const m = await import(options.target);
|
|
44
|
-
console.debug("Module loaded, path:", options.target, "module:", m);
|
|
45
|
-
return m;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var emptyCallContext = {};
|
|
49
|
-
async function start(request, options) {
|
|
50
|
-
if (started) {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
freezeGlobalConfig();
|
|
54
|
-
try {
|
|
55
|
-
service = new ProcessorServiceImpl(() => loader(options), options);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.INVALID_ARGUMENT, "Failed to load processor: " + errorString(e));
|
|
58
|
-
}
|
|
59
|
-
await service.start(request, emptyCallContext);
|
|
60
|
-
started = true;
|
|
61
|
-
return {};
|
|
62
|
-
}
|
|
63
|
-
async function service_worker_default({
|
|
64
|
-
processId,
|
|
65
|
-
request: firstRequest,
|
|
66
|
-
workerPort
|
|
67
|
-
}) {
|
|
68
|
-
const { startRequest, configRequest, options } = Piscina.workerData;
|
|
69
|
-
if (!started) {
|
|
70
|
-
const logLevel = process.env["LOG_LEVEL"]?.toUpperCase();
|
|
71
|
-
setupLogger(options.logFormat === "json", logLevel === "debug" ? true : options.debug, threadId);
|
|
72
|
-
configureEndpoints(options);
|
|
73
|
-
if (startRequest) {
|
|
74
|
-
await start(startRequest, options);
|
|
75
|
-
console.debug("worker", threadId, " started, template instance:", startRequest.templateInstances?.length);
|
|
76
|
-
}
|
|
77
|
-
if (configRequest) {
|
|
78
|
-
await service?.getConfig(configRequest, emptyCallContext);
|
|
79
|
-
console.debug("worker", threadId, " configured");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (unhandled) {
|
|
83
|
-
const err = unhandled;
|
|
84
|
-
unhandled = void 0;
|
|
85
|
-
console.error("Unhandled exception/rejection in previous request:", err);
|
|
86
|
-
throw new import_nice_grpc_error_details.RichServerError(
|
|
87
|
-
import_nice_grpc.Status.UNAVAILABLE,
|
|
88
|
-
"Unhandled exception/rejection in previous request: " + errorString(err),
|
|
89
|
-
[
|
|
90
|
-
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
|
91
|
-
detail: err.message,
|
|
92
|
-
stackEntries: err.stack?.split("\n")
|
|
93
|
-
})
|
|
94
|
-
]
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
const timeout = (options.workerTimeout || 0) * 1e3;
|
|
98
|
-
const enablePartition = options.enablePartition || false;
|
|
99
|
-
await new Promise((resolve, reject) => {
|
|
100
|
-
const subject = new import_rxjs.Subject();
|
|
101
|
-
let timeoutId = void 0;
|
|
102
|
-
subject.subscribe((resp) => {
|
|
103
|
-
console.debug("Worker", threadId, "send response:", resp.result ? "result" : "dbResult");
|
|
104
|
-
workerPort.postMessage(resp);
|
|
105
|
-
if (resp.result) {
|
|
106
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
107
|
-
resolve();
|
|
108
|
-
workerPort.close();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
workerPort.on("message", (msg) => {
|
|
112
|
-
const request = msg;
|
|
113
|
-
console.debug("Worker", threadId, "received request:", request.start ? "start" : "dbResult");
|
|
114
|
-
service?.handleRequest(request, firstRequest.binding, subject);
|
|
115
|
-
if (enablePartition && request.start && timeout > 0) {
|
|
116
|
-
timeoutId = setTimeout(async () => {
|
|
117
|
-
reject(new import_nice_grpc_error_details.RichServerError(import_nice_grpc.Status.DEADLINE_EXCEEDED, "Worker timeout exceeded"));
|
|
118
|
-
}, timeout);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
console.debug("Worker", threadId, "handle request: binding");
|
|
122
|
-
service?.handleRequest(firstRequest, firstRequest.binding, subject);
|
|
123
|
-
if (!enablePartition && timeout > 0) {
|
|
124
|
-
timeoutId = setTimeout(() => {
|
|
125
|
-
reject(new import_nice_grpc_error_details.RichServerError(import_nice_grpc.Status.DEADLINE_EXCEEDED, "Worker timeout exceeded"));
|
|
126
|
-
}, timeout);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
import("node:process").then((p) => p.stdout.write(""));
|
|
131
|
-
export {
|
|
132
|
-
service_worker_default as default
|
|
133
|
-
};
|
|
2
|
+
import{a as k}from"./chunk-757YRULG.js";import{E as I,c as h,j as S,l as x,m as C,q,z as y}from"./chunk-KF7FHZ25.js";import"./chunk-ZTRGPIW7.js";import"./chunk-TW627LH5.js";import{e as E}from"./chunk-AUPVVLD3.js";var s=E(x(),1);var i=E(C(),1);import{threadId as o}from"worker_threads";import{Piscina as L}from"piscina";var D=E(y(),1),b=!1,u;process.on("uncaughtException",e=>{console.error("Uncaught Exception, please checking if await is properly used",e),u=e}).on("unhandledRejection",(e,t)=>{e?.message.startsWith('invalid ENS name (disallowed character: "*"')||(console.error("Unhandled Rejection, please checking if await is properly",e),u=e)}).on("exit",()=>{console.info("Worker thread exiting, threadId:",o)});var d,A=async e=>{if(e.target){let t=await import(e.target);return console.debug("Module loaded, path:",e.target,"module:",t),t}},v={};async function N(e,t){if(b)return{};q();try{d=new I(()=>A(t),t)}catch(a){throw new s.ServerError(s.Status.INVALID_ARGUMENT,"Failed to load processor: "+h(a))}return await d.start(e,v),b=!0,{}}async function F({processId:e,request:t,workerPort:a}){let{startRequest:p,configRequest:w,options:n}=L.workerData;if(!b){let r=process.env.LOG_LEVEL?.toUpperCase();k(n.logFormat==="json",r==="debug"?!0:n.debug,o),S(n),p&&(await N(p,n),console.debug("worker",o," started, template instance:",p.templateInstances?.length)),w&&(await d?.getConfig(w,v),console.debug("worker",o," configured"))}if(u){let r=u;throw u=void 0,console.error("Unhandled exception/rejection in previous request:",r),new i.RichServerError(s.Status.UNAVAILABLE,"Unhandled exception/rejection in previous request: "+h(r),[i.DebugInfo.fromPartial({detail:r.message,stackEntries:r.stack?.split(`
|
|
3
|
+
`)})])}let l=(n.workerTimeout||0)*1e3,P=n.enablePartition||!1;await new Promise((r,R)=>{let f=new D.Subject,m;f.subscribe(c=>{console.debug("Worker",o,"send response:",c.result?"result":"dbResult"),a.postMessage(c),c.result&&(m&&clearTimeout(m),r(),a.close())}),a.on("message",c=>{let g=c;console.debug("Worker",o,"received request:",g.start?"start":"dbResult"),d?.handleRequest(g,t.binding,f),P&&g.start&&l>0&&(m=setTimeout(async()=>{R(new i.RichServerError(s.Status.DEADLINE_EXCEEDED,"Worker timeout exceeded"))},l))}),console.debug("Worker",o,"handle request: binding"),d?.handleRequest(t,t.binding,f),!P&&l>0&&(m=setTimeout(()=>{R(new i.RichServerError(s.Status.DEADLINE_EXCEEDED,"Worker timeout exceeded"))},l))})}import("node:process").then(e=>e.stdout.write(""));export{F as default};
|
|
134
4
|
//# sourceMappingURL=service-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import { DeepPartial, Empty, ProcessStreamRequest, ProcessStreamResponse, StartRequest } from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { ProcessorServiceImpl } from './service.js'\nimport { MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { Subject } from 'rxjs'\nimport { ProcessorRuntimeOptions } from 'processor-runner-program.js'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n .on('exit', () => {\n console.info('Worker thread exiting, threadId:', threadId)\n })\n\nlet service: ProcessorServiceImpl | undefined\n\nconst loader = async (options: ProcessorRuntimeOptions) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst emptyCallContext = <CallContext>{}\n\nasync function start(request: StartRequest, options: ProcessorRuntimeOptions): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n service = new ProcessorServiceImpl(() => loader(options), options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await service.start(request, emptyCallContext)\n started = true\n return {}\n}\n\nexport default async function ({\n processId,\n request: firstRequest,\n workerPort\n}: {\n processId: number\n request: ProcessStreamRequest\n workerPort: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options.logFormat === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker', threadId, ' started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await service?.getConfig(configRequest, emptyCallContext)\n console.debug('worker', threadId, ' configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n console.error('Unhandled exception/rejection in previous request:', err)\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n const timeout = (options.workerTimeout || 0) * 1000 // convert to milliseconds\n const enablePartition = options.enablePartition || false\n await new Promise<void>((resolve, reject) => {\n const subject = new Subject<DeepPartial<ProcessStreamResponse>>()\n let timeoutId: NodeJS.Timeout | undefined = undefined\n subject.subscribe((resp: ProcessStreamResponse) => {\n console.debug('Worker', threadId, 'send response:', resp.result ? 'result' : 'dbResult')\n workerPort.postMessage(resp)\n // receive the response from the processor , close and resolve the promise\n if (resp.result) {\n if (timeoutId) clearTimeout(timeoutId)\n resolve()\n workerPort.close()\n }\n })\n workerPort.on('message', (msg: ProcessStreamRequest) => {\n const request = msg as ProcessStreamRequest\n console.debug('Worker', threadId, 'received request:', request.start ? 'start' : 'dbResult')\n service?.handleRequest(request, firstRequest.binding, subject)\n if (enablePartition && request.start && timeout > 0) {\n timeoutId = setTimeout(async () => {\n reject(new RichServerError(Status.DEADLINE_EXCEEDED, 'Worker timeout exceeded'))\n }, timeout)\n }\n })\n console.debug('Worker', threadId, 'handle request: binding')\n service?.handleRequest(firstRequest, firstRequest.binding, subject)\n if (!enablePartition && timeout > 0) {\n timeoutId = setTimeout(() => {\n reject(new RichServerError(Status.DEADLINE_EXCEEDED, 'Worker timeout exceeded'))\n }, timeout)\n }\n })\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import { DeepPartial, Empty, ProcessStreamRequest, ProcessStreamResponse, StartRequest } from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { ProcessorServiceImpl } from './service.js'\nimport { MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { Subject } from 'rxjs'\nimport { ProcessorRuntimeOptions } from 'processor-runner-program.js'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n .on('exit', () => {\n console.info('Worker thread exiting, threadId:', threadId)\n })\n\nlet service: ProcessorServiceImpl | undefined\n\nconst loader = async (options: ProcessorRuntimeOptions) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst emptyCallContext = <CallContext>{}\n\nasync function start(request: StartRequest, options: ProcessorRuntimeOptions): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n service = new ProcessorServiceImpl(() => loader(options), options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await service.start(request, emptyCallContext)\n started = true\n return {}\n}\n\nexport default async function ({\n processId,\n request: firstRequest,\n workerPort\n}: {\n processId: number\n request: ProcessStreamRequest\n workerPort: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options.logFormat === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker', threadId, ' started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await service?.getConfig(configRequest, emptyCallContext)\n console.debug('worker', threadId, ' configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n console.error('Unhandled exception/rejection in previous request:', err)\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n const timeout = (options.workerTimeout || 0) * 1000 // convert to milliseconds\n const enablePartition = options.enablePartition || false\n await new Promise<void>((resolve, reject) => {\n const subject = new Subject<DeepPartial<ProcessStreamResponse>>()\n let timeoutId: NodeJS.Timeout | undefined = undefined\n subject.subscribe((resp: ProcessStreamResponse) => {\n console.debug('Worker', threadId, 'send response:', resp.result ? 'result' : 'dbResult')\n workerPort.postMessage(resp)\n // receive the response from the processor , close and resolve the promise\n if (resp.result) {\n if (timeoutId) clearTimeout(timeoutId)\n resolve()\n workerPort.close()\n }\n })\n workerPort.on('message', (msg: ProcessStreamRequest) => {\n const request = msg as ProcessStreamRequest\n console.debug('Worker', threadId, 'received request:', request.start ? 'start' : 'dbResult')\n service?.handleRequest(request, firstRequest.binding, subject)\n if (enablePartition && request.start && timeout > 0) {\n timeoutId = setTimeout(async () => {\n reject(new RichServerError(Status.DEADLINE_EXCEEDED, 'Worker timeout exceeded'))\n }, timeout)\n }\n })\n console.debug('Worker', threadId, 'handle request: binding')\n service?.handleRequest(firstRequest, firstRequest.binding, subject)\n if (!enablePartition && timeout > 0) {\n timeoutId = setTimeout(() => {\n reject(new RichServerError(Status.DEADLINE_EXCEEDED, 'Worker timeout exceeded'))\n }, timeout)\n }\n })\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";qNACA,IAAAA,EAAiD,SAGjD,IAAAC,EAA2C,SAE3C,OAAsB,YAAAC,MAA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AAmBD,EAAU,IAChCK,EAAY,WAAW,IAAM,CAC3BF,EAAO,IAAI,kBAAgB,SAAO,kBAAmB,yBAAyB,CAAC,CACjF,EAAGH,CAAO,EAEd,CAAC,CACH,CACC,OAAO,cAAc,EAAE,KAAMvB,GAAMA,EAAE,OAAO,MAAM,EAAE,CAAC","names":["import_nice_grpc","import_nice_grpc_error_details","threadId","Piscina","import_rxjs","started","unhandled","err","reason","p","threadId","service","loader","options","m","emptyCallContext","start","request","freezeGlobalConfig","ProcessorServiceImpl","e","errorString","service_worker_default","processId","firstRequest","workerPort","startRequest","configRequest","Piscina","logLevel","setupLogger","configureEndpoints","timeout","enablePartition","resolve","reject","subject","timeoutId","resp","msg"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\nimport { AccountConfig, InitResponse, ProcessConfigResponse, ProcessStreamResponse_Partitions } from '@sentio/protos'\n\nexport class TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n\n async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {\n return {\n partitions: request.handlerIds.reduce(\n (acc, id) => ({\n ...acc,\n [id]: {\n userValue: 'test'\n }\n }),\n {}\n )\n }\n }\n\n async init(config: InitResponse): Promise<void> {\n config.chainIds = ['1']\n }\n\n async configure(config: ProcessConfigResponse, forChainId?: string): Promise<void> {\n config.accountConfigs = [\n AccountConfig.fromPartial({\n address: '0x',\n chainId: '1'\n })\n ]\n }\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\nimport { AccountConfig, InitResponse, ProcessConfigResponse, ProcessStreamResponse_Partitions } from '@sentio/protos'\n\nexport class TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n\n async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {\n return {\n partitions: request.handlerIds.reduce(\n (acc, id) => ({\n ...acc,\n [id]: {\n userValue: 'test'\n }\n }),\n {}\n )\n }\n }\n\n async init(config: InitResponse): Promise<void> {\n config.chainIds = ['1']\n }\n\n async configure(config: ProcessConfigResponse, forChainId?: string): Promise<void> {\n config.accountConfigs = [\n AccountConfig.fromPartial({\n address: '0x',\n chainId: '1'\n })\n ]\n }\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";yFAIO,IAAMA,EAAN,cAAyBC,CAAO,CACrC,MAAM,eAAeC,EAA8C,CACjE,IAAMC,EAAYC,EAAc,SAAS,sBAAsB,SAAS,EACxE,OAAID,GACF,MAAMA,EAAU,YAAY,CAC1B,IAAK,CACH,OAAQ,OACR,GAAI,GACN,CACF,CAAC,EAGIE,EAAc,YAAY,CAC/B,OAAQ,CACN,cAAe,EACjB,CACF,CAAC,CACH,CACA,kBAAoB,IAAyC,EAE7D,MAAM,UAAUH,EAAiE,CAC/E,MAAO,CACL,WAAYA,EAAQ,WAAW,OAC7B,CAACI,EAAKC,KAAQ,CACZ,GAAGD,EACH,CAACC,CAAE,EAAG,CACJ,UAAW,MACb,CACF,GACA,CAAC,CACH,CACF,CACF,CAEA,MAAM,KAAKC,EAAqC,CAC9CA,EAAO,SAAW,CAAC,GAAG,CACxB,CAEA,MAAM,UAAUA,EAA+BC,EAAoC,CACjFD,EAAO,eAAiB,CACtBE,EAAc,YAAY,CACxB,QAAS,KACT,QAAS,GACX,CAAC,CACH,CACF,CACF,EAEAN,EAAc,SAAS,QAAU,CAAC,EAClCA,EAAc,SAAS,SAAS,IAAIJ,CAAY,EAC/C,OAAO,cAAc,EAAE,KAAMW,GAAMA,EAAE,OAAO,MAAM,EAAE,CAAC","names":["TestPlugin","Plugin","request","dbContext","PluginManager","ProcessResult","acc","id","config","forChainId","AccountConfig","p"]}
|
package/package.json
CHANGED
package/src/db-context.ts
CHANGED
|
@@ -281,7 +281,6 @@ export class DataBindingContext extends AbstractStoreContext implements IDataBin
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
doSend(resp: DeepPartial<ProcessStreamResponseV3>) {
|
|
284
|
-
console.debug('sending db request, processId ', this.processId, 'opId', resp.dbRequest?.opId)
|
|
285
284
|
this.subject.next({
|
|
286
285
|
...resp,
|
|
287
286
|
processId: this.processId
|
package/src/otlp.ts
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
|
|
1
|
+
import { IMetricReader, MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
|
|
2
2
|
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'
|
|
3
3
|
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'
|
|
4
|
-
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
5
|
-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
|
|
6
4
|
import { diag, DiagConsoleLogger, DiagLogLevel, metrics } from '@opentelemetry/api'
|
|
7
5
|
|
|
8
6
|
export async function setupOTLP(debug?: boolean) {
|
|
7
|
+
console.log('Setting up OTLP metrics, debug=', !!debug)
|
|
9
8
|
if (debug) {
|
|
10
9
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG)
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const readers: IMetricReader[] = [
|
|
13
|
+
new PeriodicExportingMetricReader({
|
|
14
|
+
exporter: new OTLPMetricExporter(),
|
|
15
|
+
exportIntervalMillis: 60000
|
|
16
|
+
})
|
|
17
|
+
]
|
|
18
|
+
if (debug) {
|
|
19
|
+
readers.push(
|
|
20
20
|
new PrometheusExporter({
|
|
21
21
|
host: '0.0.0.0',
|
|
22
22
|
port: 4041
|
|
23
23
|
})
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
const meterProvider = new MeterProvider({
|
|
27
|
+
readers: [
|
|
28
|
+
new PeriodicExportingMetricReader({
|
|
29
|
+
exporter: new OTLPMetricExporter(),
|
|
30
|
+
exportIntervalMillis: 60000
|
|
31
|
+
})
|
|
24
32
|
]
|
|
25
33
|
})
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
metrics.setGlobalMeterProvider(meterProvider)
|
|
28
36
|
;['SIGINT', 'SIGTERM'].forEach((signal) => {
|
|
29
|
-
process.on(signal as any, () =>
|
|
37
|
+
process.on(signal as any, () => meterProvider.forceFlush().catch(console.error))
|
|
30
38
|
})
|
|
31
39
|
|
|
32
40
|
metrics.getMeter('processor').createGauge('up').record(1)
|
package/src/processor-runner.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from 'fs-extra'
|
|
4
|
-
|
|
4
|
+
// import { compressionAlgorithms } from '@grpc/grpc-js'
|
|
5
5
|
import { createServer } from 'nice-grpc'
|
|
6
6
|
import { errorDetailsServerMiddleware } from 'nice-grpc-error-details'
|
|
7
7
|
// import { registry as niceGrpcRegistry } from 'nice-grpc-prometheus'
|
|
8
|
-
import { openTelemetryServerMiddleware } from 'nice-grpc-opentelemetry'
|
|
8
|
+
// import { openTelemetryServerMiddleware } from 'nice-grpc-opentelemetry'
|
|
9
9
|
import http from 'http'
|
|
10
10
|
// @ts-ignore inspector promises is not included in @type/node
|
|
11
11
|
import { Session } from 'node:inspector/promises'
|
|
@@ -61,7 +61,7 @@ if (options.startActionServer) {
|
|
|
61
61
|
// 'grpc.default_compression_algorithm': compressionAlgorithms.gzip
|
|
62
62
|
})
|
|
63
63
|
// .use(prometheusServerMiddleware())
|
|
64
|
-
.use(openTelemetryServerMiddleware())
|
|
64
|
+
// .use(openTelemetryServerMiddleware())
|
|
65
65
|
.use(errorDetailsServerMiddleware)
|
|
66
66
|
|
|
67
67
|
if (options.worker > 1) {
|
package/src/service-v3.ts
CHANGED
|
@@ -29,6 +29,9 @@ import { ProcessorRuntimeOptions } from 'processor-runner-program.js'
|
|
|
29
29
|
|
|
30
30
|
const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
|
|
31
31
|
|
|
32
|
+
const WRITE_V2_EVENT_LOGS = process.env.WRITE_V2_EVENT_LOGS !== 'false'
|
|
33
|
+
const TIME_SERIES_RESULT_BATCH_SIZE = 1000
|
|
34
|
+
|
|
32
35
|
export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation {
|
|
33
36
|
readonly enablePartition: boolean
|
|
34
37
|
private readonly loader: () => Promise<any>
|
|
@@ -165,35 +168,26 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
|
165
168
|
) {
|
|
166
169
|
const context = this.contexts.new(processId, subject)
|
|
167
170
|
const start = Date.now()
|
|
168
|
-
console.debug('process binding', processId)
|
|
169
171
|
PluginManager.INSTANCE.processBinding(binding, undefined, context)
|
|
170
172
|
.then(async (result) => {
|
|
171
|
-
console.debug(`process binding ${processId} done`)
|
|
172
173
|
await context.awaitPendings()
|
|
173
174
|
const { timeseriesResult, ...otherResults } = result
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
for (let i = 0; i < timeseriesResult.length; i += TIME_SERIES_RESULT_BATCH_SIZE) {
|
|
176
|
+
const batch = timeseriesResult.slice(i, i + TIME_SERIES_RESULT_BATCH_SIZE)
|
|
176
177
|
subject.next({
|
|
177
178
|
processId,
|
|
178
179
|
tsRequest: {
|
|
179
|
-
data:
|
|
180
|
+
data: batch
|
|
180
181
|
}
|
|
181
182
|
})
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
/* if (result.states?.configUpdated) {
|
|
185
|
-
console.debug('sending tpl updates:')
|
|
186
|
-
subject.next({
|
|
187
|
-
processId,
|
|
188
|
-
tplRequest: {
|
|
189
|
-
templates: TemplateInstanceState.INSTANCE.getValues()
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
}*/
|
|
193
|
-
|
|
194
|
-
console.debug('sending binding result', processId)
|
|
195
185
|
subject.next({
|
|
196
|
-
result:
|
|
186
|
+
result: WRITE_V2_EVENT_LOGS
|
|
187
|
+
? otherResults
|
|
188
|
+
: {
|
|
189
|
+
states: otherResults.states
|
|
190
|
+
},
|
|
197
191
|
processId: processId
|
|
198
192
|
})
|
|
199
193
|
recordRuntimeInfo(result, binding.handlerType)
|
|
@@ -207,7 +201,6 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
|
207
201
|
const cost = Date.now() - start
|
|
208
202
|
process_binding_time.add(cost)
|
|
209
203
|
this.contexts.delete(processId)
|
|
210
|
-
console.debug('process binding done', processId)
|
|
211
204
|
})
|
|
212
205
|
}
|
|
213
206
|
|