@sentio/runtime 2.39.7-rc.21 → 2.39.7-rc.23
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/db-context.d.ts +2 -4
- package/lib/db-context.d.ts.map +1 -1
- package/lib/db-context.js +40 -17
- package/lib/db-context.js.map +1 -1
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +10 -2
- package/lib/service.js.map +1 -1
- package/package.json +2 -2
- package/src/db-context.ts +46 -21
- package/src/service.ts +12 -2
package/lib/db-context.d.ts
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
import { Subject } from 'rxjs';
|
2
2
|
import { DBRequest, DBRequest_DBUpsert, DBResponse, DeepPartial, ProcessStreamResponse } from '@sentio/protos';
|
3
3
|
type Request = Omit<DBRequest, 'opId'>;
|
4
|
+
type RequestType = keyof Request;
|
4
5
|
export declare const timeoutError: unique symbol;
|
5
6
|
export declare class StoreContext {
|
6
7
|
readonly subject: Subject<DeepPartial<ProcessStreamResponse>>;
|
7
8
|
readonly processId: number;
|
8
9
|
private static opCounter;
|
9
|
-
private send_counts;
|
10
|
-
private recv_counts;
|
11
10
|
private defers;
|
12
11
|
private statsInterval;
|
13
12
|
constructor(subject: Subject<DeepPartial<ProcessStreamResponse>>, processId: number);
|
14
|
-
newPromise<T>(opId: bigint, requestType?:
|
13
|
+
newPromise<T>(opId: bigint, requestType?: RequestType): Promise<T>;
|
15
14
|
sendRequest(request: DeepPartial<Request>, timeoutSecs?: number): Promise<DBResponse>;
|
16
15
|
result(dbResult: DBResponse): void;
|
17
16
|
error(processId: number, e: any): void;
|
@@ -19,7 +18,6 @@ export declare class StoreContext {
|
|
19
18
|
queuedUpsert: DBRequest_DBUpsert | undefined;
|
20
19
|
queuedUpsertPromise: Promise<DBResponse> | undefined;
|
21
20
|
private sendUpsert;
|
22
|
-
startPrintStats(): void;
|
23
21
|
}
|
24
22
|
export {};
|
25
23
|
//# sourceMappingURL=db-context.d.ts.map
|
package/lib/db-context.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"db-context.d.ts","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,WAAW,EAEX,qBAAqB,EACtB,MAAM,gBAAgB,CAAA;
|
1
|
+
{"version":3,"file":"db-context.d.ts","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,WAAW,EAEX,qBAAqB,EACtB,MAAM,gBAAgB,CAAA;AAMvB,KAAK,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AACtC,KAAK,WAAW,GAAG,MAAM,OAAO,CAAA;AA8BhC,eAAO,MAAM,YAAY,eAAW,CAAA;AAEpC,qBAAa,YAAY;IAUrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM;IAV5B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAK;IAE7B,OAAO,CAAC,MAAM,CAGX;IACH,OAAO,CAAC,aAAa,CAA4B;gBAGtC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,EACpD,SAAS,EAAE,MAAM;IAG5B,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW;IAOrD,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAiDrF,MAAM,CAAC,QAAQ,EAAE,UAAU;IAkB3B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG;IAa/B,KAAK;IAWL,YAAY,EAAE,kBAAkB,GAAG,SAAS,CAAA;IAC5C,mBAAmB,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;YAEtC,UAAU;CA6BzB"}
|
package/lib/db-context.js
CHANGED
@@ -1,13 +1,38 @@
|
|
1
1
|
import { ProcessResult } from '@sentio/protos';
|
2
2
|
import * as process from 'node:process';
|
3
|
-
|
3
|
+
import { metrics } from '@opentelemetry/api';
|
4
|
+
const STORE_BATCH_IDLE = process.env['STORE_BATCH_IDLE'] ? parseInt(process.env['STORE_BATCH_IDLE']) : 0;
|
5
|
+
const meter = metrics.getMeter('store');
|
6
|
+
const send_counts = {
|
7
|
+
get: meter.createCounter('store_get_count'),
|
8
|
+
upsert: meter.createCounter('store_upsert_count'),
|
9
|
+
list: meter.createCounter('store_list_count'),
|
10
|
+
delete: meter.createCounter('store_delete_count')
|
11
|
+
};
|
12
|
+
const recv_counts = {
|
13
|
+
get: meter.createCounter('store_get_count'),
|
14
|
+
upsert: meter.createCounter('store_upsert_count'),
|
15
|
+
list: meter.createCounter('store_list_count'),
|
16
|
+
delete: meter.createCounter('store_delete_count')
|
17
|
+
};
|
18
|
+
const request_times = {
|
19
|
+
get: meter.createCounter('store_get_time'),
|
20
|
+
upsert: meter.createCounter('store_upsert_time'),
|
21
|
+
list: meter.createCounter('store_list_time'),
|
22
|
+
delete: meter.createCounter('store_delete_time')
|
23
|
+
};
|
24
|
+
const request_errors = {
|
25
|
+
get: meter.createCounter('store_get_error'),
|
26
|
+
upsert: meter.createCounter('store_upsert_error'),
|
27
|
+
list: meter.createCounter('store_list_error'),
|
28
|
+
delete: meter.createCounter('store_delete_error')
|
29
|
+
};
|
30
|
+
const unsolved_requests = meter.createGauge('store_unsolved_requests');
|
4
31
|
export const timeoutError = Symbol();
|
5
32
|
export class StoreContext {
|
6
33
|
subject;
|
7
34
|
processId;
|
8
35
|
static opCounter = 0n;
|
9
|
-
send_counts = {};
|
10
|
-
recv_counts = {};
|
11
36
|
defers = new Map();
|
12
37
|
statsInterval;
|
13
38
|
constructor(subject, processId) {
|
@@ -17,6 +42,7 @@ export class StoreContext {
|
|
17
42
|
newPromise(opId, requestType) {
|
18
43
|
return new Promise((resolve, reject) => {
|
19
44
|
this.defers.set(opId, { resolve, reject, requestType });
|
45
|
+
unsolved_requests.record(this.defers.size, { processId: this.processId });
|
20
46
|
});
|
21
47
|
}
|
22
48
|
sendRequest(request, timeoutSecs) {
|
@@ -24,8 +50,9 @@ export class StoreContext {
|
|
24
50
|
// batch upsert if possible
|
25
51
|
return this.sendUpsert(request.upsert, STORE_BATCH_IDLE);
|
26
52
|
}
|
53
|
+
const requestType = Object.keys(request)[0];
|
27
54
|
const opId = StoreContext.opCounter++;
|
28
|
-
const promise = this.newPromise(opId);
|
55
|
+
const promise = this.newPromise(opId, requestType);
|
29
56
|
const start = Date.now();
|
30
57
|
const promises = [promise];
|
31
58
|
console.debug('sending db request ', opId, request);
|
@@ -34,7 +61,6 @@ export class StoreContext {
|
|
34
61
|
const timeoutPromise = new Promise((_r, rej) => (timer = setTimeout(rej, timeoutSecs * 1000, timeoutError)));
|
35
62
|
promises.push(timeoutPromise);
|
36
63
|
}
|
37
|
-
const requestType = Object.keys(request)[0];
|
38
64
|
this.subject.next({
|
39
65
|
dbRequest: {
|
40
66
|
...request,
|
@@ -42,16 +68,18 @@ export class StoreContext {
|
|
42
68
|
},
|
43
69
|
processId: this.processId
|
44
70
|
});
|
45
|
-
|
71
|
+
send_counts[requestType]?.add(1);
|
46
72
|
return Promise.race(promises)
|
47
73
|
.then((result) => {
|
48
|
-
console.
|
74
|
+
console.debug('db request', requestType, 'op', opId, ' took', Date.now() - start, 'ms');
|
75
|
+
request_times[requestType]?.add(Date.now() - start);
|
49
76
|
return result;
|
50
77
|
})
|
51
78
|
.catch((e) => {
|
52
79
|
if (e === timeoutError) {
|
53
80
|
console.error('db request', requestType, 'op:', opId, ' timeout');
|
54
81
|
}
|
82
|
+
request_errors[requestType]?.add(1);
|
55
83
|
throw e;
|
56
84
|
})
|
57
85
|
.finally(() => {
|
@@ -66,7 +94,7 @@ export class StoreContext {
|
|
66
94
|
console.debug('received db result ', opId, dbResult);
|
67
95
|
if (defer) {
|
68
96
|
if (defer.requestType) {
|
69
|
-
|
97
|
+
recv_counts[defer.requestType]?.add(1);
|
70
98
|
}
|
71
99
|
if (dbResult.error) {
|
72
100
|
defer.reject(new Error(dbResult.error));
|
@@ -76,6 +104,7 @@ export class StoreContext {
|
|
76
104
|
}
|
77
105
|
this.defers.delete(opId);
|
78
106
|
}
|
107
|
+
unsolved_requests.record(this.defers.size, { processId: this.processId });
|
79
108
|
}
|
80
109
|
error(processId, e) {
|
81
110
|
console.error('process error', processId, e);
|
@@ -112,12 +141,12 @@ export class StoreContext {
|
|
112
141
|
else {
|
113
142
|
this.queuedUpsert = req;
|
114
143
|
const opId = StoreContext.opCounter++;
|
115
|
-
const promise = this.newPromise(opId);
|
144
|
+
const promise = this.newPromise(opId, 'upsert');
|
116
145
|
this.queuedUpsertPromise = promise;
|
117
146
|
await delay(batchIdleMs);
|
118
147
|
this.queuedUpsertPromise = undefined;
|
119
148
|
this.queuedUpsert = undefined;
|
120
|
-
console.
|
149
|
+
console.debug('sending upsert', opId, 'batch size', req.entity.length);
|
121
150
|
this.subject.next({
|
122
151
|
dbRequest: {
|
123
152
|
upsert: req,
|
@@ -125,16 +154,10 @@ export class StoreContext {
|
|
125
154
|
},
|
126
155
|
processId: this.processId
|
127
156
|
});
|
128
|
-
|
157
|
+
send_counts['upsert']?.add(1);
|
129
158
|
return promise;
|
130
159
|
}
|
131
160
|
}
|
132
|
-
startPrintStats() {
|
133
|
-
this.statsInterval = setInterval(() => {
|
134
|
-
console.log('send counts', this.send_counts);
|
135
|
-
console.log('recv counts', this.recv_counts);
|
136
|
-
}, 10000);
|
137
|
-
}
|
138
161
|
}
|
139
162
|
function delay(ms) {
|
140
163
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
package/lib/db-context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"db-context.js","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,aAAa,EAEd,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;
|
1
|
+
{"version":3,"file":"db-context.js","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,aAAa,EAEd,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAuB,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAEjE,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAKxG,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AACvC,MAAM,WAAW,GAA6C;IAC5D,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC;IAC3C,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC;IACjD,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,kBAAkB,CAAC;IAC7C,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC;CAClD,CAAA;AACD,MAAM,WAAW,GAA6C;IAC5D,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC;IAC3C,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC;IACjD,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,kBAAkB,CAAC;IAC7C,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC;CAClD,CAAA;AACD,MA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AAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC"}
|
package/lib/service.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,WAAW,CAAA;AAK5D,OAAO,EACL,WAAW,EAEX,KAAK,EACL,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,aAAa,EACb,oBAAoB,EAEpB,YAAY,EACb,MAAM,gBAAgB,CAAA;
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,WAAW,CAAA;AAK5D,OAAO,EACL,WAAW,EAEX,KAAK,EACL,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,aAAa,EACb,oBAAoB,EAEpB,YAAY,EACb,MAAM,gBAAgB,CAAA;AAmBvB,qBAAa,oBAAqB,YAAW,8BAA8B;IACzE,OAAO,CAAC,OAAO,CAAQ;IAEvB,SAAS,EAAE,KAAK,CAAA;IAGhB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAE3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAY;gBAEjC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC,EAAE,MAAM,IAAI;IAK9D,SAAS,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAoB9F,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;IAsClE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;IAQ1D,eAAe,CAAC,OAAO,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA6BxG,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAqBlF,qBAAqB,CAAC,QAAQ,EAAE,aAAa,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAiBlF,cAAc;CA4C7B"}
|
package/lib/service.js
CHANGED
@@ -8,6 +8,11 @@ import { errorString, mergeProcessResults } from './utils.js';
|
|
8
8
|
import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js';
|
9
9
|
import { StoreContext } from './db-context.js';
|
10
10
|
import { Subject } from 'rxjs';
|
11
|
+
import { metrics } from '@opentelemetry/api';
|
12
|
+
const meter = metrics.getMeter('store');
|
13
|
+
const process_binding_count = meter.createCounter('process_binding_count');
|
14
|
+
const process_binding_time = meter.createCounter('process_binding_time');
|
15
|
+
const process_binding_error = meter.createCounter('process_binding_error');
|
11
16
|
BigInt.prototype.toJSON = function () {
|
12
17
|
return this.toString();
|
13
18
|
};
|
@@ -142,6 +147,7 @@ export class ProcessorServiceImpl {
|
|
142
147
|
try {
|
143
148
|
console.debug('received request:', request);
|
144
149
|
if (request.binding) {
|
150
|
+
process_binding_count.add(1);
|
145
151
|
const binding = request.binding;
|
146
152
|
const dbContext = contexts.new(request.processId, subject);
|
147
153
|
const start = Date.now();
|
@@ -156,9 +162,12 @@ export class ProcessorServiceImpl {
|
|
156
162
|
.catch((e) => {
|
157
163
|
console.debug(e);
|
158
164
|
dbContext.error(request.processId, e);
|
165
|
+
process_binding_error.add(1);
|
159
166
|
})
|
160
167
|
.finally(() => {
|
161
|
-
|
168
|
+
const cost = Date.now() - start;
|
169
|
+
console.debug('processBinding', request.processId, ' took', cost, 'ms');
|
170
|
+
process_binding_time.add(cost);
|
162
171
|
contexts.delete(request.processId);
|
163
172
|
});
|
164
173
|
}
|
@@ -190,7 +199,6 @@ class Contexts {
|
|
190
199
|
}
|
191
200
|
new(processId, subject) {
|
192
201
|
const context = new StoreContext(subject, processId);
|
193
|
-
context.startPrintStats();
|
194
202
|
this.contexts.set(processId, context);
|
195
203
|
return context;
|
196
204
|
}
|
package/lib/service.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AAEhE,OAAO,EAQL,qBAAqB,EAMtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA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O,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACnC,OAAO,EAAE,KAAK,EAAE,CAAA;QAChB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/runtime",
|
3
|
-
"version": "2.39.7-rc.
|
3
|
+
"version": "2.39.7-rc.23",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"rxjs": "^7.8.1",
|
36
36
|
"utility-types": "^3.11.0",
|
37
37
|
"winston": "^3.11.0",
|
38
|
-
"@sentio/protos": "2.39.7-rc.
|
38
|
+
"@sentio/protos": "2.39.7-rc.23"
|
39
39
|
},
|
40
40
|
"devDependencies": {
|
41
41
|
"@types/command-line-args": "^5.2.3",
|
package/src/db-context.ts
CHANGED
@@ -8,21 +8,49 @@ import {
|
|
8
8
|
ProcessStreamResponse
|
9
9
|
} from '@sentio/protos'
|
10
10
|
import * as process from 'node:process'
|
11
|
+
import { Attributes, Counter, metrics } from '@opentelemetry/api'
|
11
12
|
|
12
|
-
const STORE_BATCH_IDLE = process.env['STORE_BATCH_IDLE'] ? parseInt(process.env['STORE_BATCH_IDLE']) :
|
13
|
+
const STORE_BATCH_IDLE = process.env['STORE_BATCH_IDLE'] ? parseInt(process.env['STORE_BATCH_IDLE']) : 0
|
13
14
|
|
14
15
|
type Request = Omit<DBRequest, 'opId'>
|
16
|
+
type RequestType = keyof Request
|
17
|
+
|
18
|
+
const meter = metrics.getMeter('store')
|
19
|
+
const send_counts: Record<RequestType, Counter<Attributes>> = {
|
20
|
+
get: meter.createCounter('store_get_count'),
|
21
|
+
upsert: meter.createCounter('store_upsert_count'),
|
22
|
+
list: meter.createCounter('store_list_count'),
|
23
|
+
delete: meter.createCounter('store_delete_count')
|
24
|
+
}
|
25
|
+
const recv_counts: Record<RequestType, Counter<Attributes>> = {
|
26
|
+
get: meter.createCounter('store_get_count'),
|
27
|
+
upsert: meter.createCounter('store_upsert_count'),
|
28
|
+
list: meter.createCounter('store_list_count'),
|
29
|
+
delete: meter.createCounter('store_delete_count')
|
30
|
+
}
|
31
|
+
const request_times: Record<RequestType, Counter<Attributes>> = {
|
32
|
+
get: meter.createCounter('store_get_time'),
|
33
|
+
upsert: meter.createCounter('store_upsert_time'),
|
34
|
+
list: meter.createCounter('store_list_time'),
|
35
|
+
delete: meter.createCounter('store_delete_time')
|
36
|
+
}
|
37
|
+
const request_errors: Record<RequestType, Counter<Attributes>> = {
|
38
|
+
get: meter.createCounter('store_get_error'),
|
39
|
+
upsert: meter.createCounter('store_upsert_error'),
|
40
|
+
list: meter.createCounter('store_list_error'),
|
41
|
+
delete: meter.createCounter('store_delete_error')
|
42
|
+
}
|
43
|
+
|
44
|
+
const unsolved_requests = meter.createGauge('store_unsolved_requests')
|
45
|
+
|
15
46
|
export const timeoutError = Symbol()
|
16
47
|
|
17
48
|
export class StoreContext {
|
18
49
|
private static opCounter = 0n
|
19
50
|
|
20
|
-
private send_counts: Record<string, number> = {}
|
21
|
-
private recv_counts: Record<string, number> = {}
|
22
|
-
|
23
51
|
private defers = new Map<
|
24
52
|
bigint,
|
25
|
-
{ resolve: (value: any) => void; reject: (reason?: any) => void; requestType?:
|
53
|
+
{ resolve: (value: any) => void; reject: (reason?: any) => void; requestType?: RequestType }
|
26
54
|
>()
|
27
55
|
private statsInterval: NodeJS.Timeout | undefined
|
28
56
|
|
@@ -31,9 +59,10 @@ export class StoreContext {
|
|
31
59
|
readonly processId: number
|
32
60
|
) {}
|
33
61
|
|
34
|
-
newPromise<T>(opId: bigint, requestType?:
|
62
|
+
newPromise<T>(opId: bigint, requestType?: RequestType) {
|
35
63
|
return new Promise<T>((resolve, reject) => {
|
36
64
|
this.defers.set(opId, { resolve, reject, requestType })
|
65
|
+
unsolved_requests.record(this.defers.size, { processId: this.processId })
|
37
66
|
})
|
38
67
|
}
|
39
68
|
|
@@ -43,8 +72,9 @@ export class StoreContext {
|
|
43
72
|
return this.sendUpsert(request.upsert as DBRequest_DBUpsert, STORE_BATCH_IDLE)
|
44
73
|
}
|
45
74
|
|
75
|
+
const requestType = Object.keys(request)[0] as RequestType
|
46
76
|
const opId = StoreContext.opCounter++
|
47
|
-
const promise = this.newPromise(opId)
|
77
|
+
const promise = this.newPromise(opId, requestType)
|
48
78
|
|
49
79
|
const start = Date.now()
|
50
80
|
const promises = [promise]
|
@@ -55,7 +85,6 @@ export class StoreContext {
|
|
55
85
|
promises.push(timeoutPromise)
|
56
86
|
}
|
57
87
|
|
58
|
-
const requestType = Object.keys(request)[0] as string
|
59
88
|
this.subject.next({
|
60
89
|
dbRequest: {
|
61
90
|
...request,
|
@@ -64,17 +93,19 @@ export class StoreContext {
|
|
64
93
|
processId: this.processId
|
65
94
|
})
|
66
95
|
|
67
|
-
|
96
|
+
send_counts[requestType]?.add(1)
|
68
97
|
|
69
98
|
return Promise.race(promises)
|
70
99
|
.then((result: DBResponse) => {
|
71
|
-
console.
|
100
|
+
console.debug('db request', requestType, 'op', opId, ' took', Date.now() - start, 'ms')
|
101
|
+
request_times[requestType]?.add(Date.now() - start)
|
72
102
|
return result
|
73
103
|
})
|
74
104
|
.catch((e) => {
|
75
105
|
if (e === timeoutError) {
|
76
106
|
console.error('db request', requestType, 'op:', opId, ' timeout')
|
77
107
|
}
|
108
|
+
request_errors[requestType]?.add(1)
|
78
109
|
throw e
|
79
110
|
})
|
80
111
|
.finally(() => {
|
@@ -90,7 +121,7 @@ export class StoreContext {
|
|
90
121
|
console.debug('received db result ', opId, dbResult)
|
91
122
|
if (defer) {
|
92
123
|
if (defer.requestType) {
|
93
|
-
|
124
|
+
recv_counts[defer.requestType]?.add(1)
|
94
125
|
}
|
95
126
|
if (dbResult.error) {
|
96
127
|
defer.reject(new Error(dbResult.error))
|
@@ -99,6 +130,7 @@ export class StoreContext {
|
|
99
130
|
}
|
100
131
|
this.defers.delete(opId)
|
101
132
|
}
|
133
|
+
unsolved_requests.record(this.defers.size, { processId: this.processId })
|
102
134
|
}
|
103
135
|
|
104
136
|
error(processId: number, e: any) {
|
@@ -139,12 +171,12 @@ export class StoreContext {
|
|
139
171
|
} else {
|
140
172
|
this.queuedUpsert = req
|
141
173
|
const opId = StoreContext.opCounter++
|
142
|
-
const promise = this.newPromise<DBResponse>(opId)
|
174
|
+
const promise = this.newPromise<DBResponse>(opId, 'upsert')
|
143
175
|
this.queuedUpsertPromise = promise
|
144
176
|
await delay(batchIdleMs)
|
145
177
|
this.queuedUpsertPromise = undefined
|
146
178
|
this.queuedUpsert = undefined
|
147
|
-
console.
|
179
|
+
console.debug('sending upsert', opId, 'batch size', req.entity.length)
|
148
180
|
this.subject.next({
|
149
181
|
dbRequest: {
|
150
182
|
upsert: req,
|
@@ -152,18 +184,11 @@ export class StoreContext {
|
|
152
184
|
},
|
153
185
|
processId: this.processId
|
154
186
|
})
|
155
|
-
|
187
|
+
send_counts['upsert']?.add(1)
|
156
188
|
|
157
189
|
return promise
|
158
190
|
}
|
159
191
|
}
|
160
|
-
|
161
|
-
startPrintStats() {
|
162
|
-
this.statsInterval = setInterval(() => {
|
163
|
-
console.log('send counts', this.send_counts)
|
164
|
-
console.log('recv counts', this.recv_counts)
|
165
|
-
}, 10000)
|
166
|
-
}
|
167
192
|
}
|
168
193
|
|
169
194
|
function delay(ms: number) {
|
package/src/service.ts
CHANGED
@@ -25,6 +25,13 @@ import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js'
|
|
25
25
|
|
26
26
|
import { StoreContext } from './db-context.js'
|
27
27
|
import { Subject } from 'rxjs'
|
28
|
+
import { metrics } from '@opentelemetry/api'
|
29
|
+
|
30
|
+
const meter = metrics.getMeter('store')
|
31
|
+
const process_binding_count = meter.createCounter('process_binding_count')
|
32
|
+
const process_binding_time = meter.createCounter('process_binding_time')
|
33
|
+
const process_binding_error = meter.createCounter('process_binding_error')
|
34
|
+
|
28
35
|
;(BigInt.prototype as any).toJSON = function () {
|
29
36
|
return this.toString()
|
30
37
|
}
|
@@ -187,6 +194,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
187
194
|
try {
|
188
195
|
console.debug('received request:', request)
|
189
196
|
if (request.binding) {
|
197
|
+
process_binding_count.add(1)
|
190
198
|
const binding = request.binding
|
191
199
|
const dbContext = contexts.new(request.processId, subject)
|
192
200
|
const start = Date.now()
|
@@ -201,9 +209,12 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
201
209
|
.catch((e) => {
|
202
210
|
console.debug(e)
|
203
211
|
dbContext.error(request.processId, e)
|
212
|
+
process_binding_error.add(1)
|
204
213
|
})
|
205
214
|
.finally(() => {
|
206
|
-
|
215
|
+
const cost = Date.now() - start
|
216
|
+
console.debug('processBinding', request.processId, ' took', cost, 'ms')
|
217
|
+
process_binding_time.add(cost)
|
207
218
|
contexts.delete(request.processId)
|
208
219
|
})
|
209
220
|
}
|
@@ -238,7 +249,6 @@ class Contexts {
|
|
238
249
|
|
239
250
|
new(processId: number, subject: Subject<DeepPartial<ProcessStreamResponse>>) {
|
240
251
|
const context = new StoreContext(subject, processId)
|
241
|
-
context.startPrintStats()
|
242
252
|
this.contexts.set(processId, context)
|
243
253
|
return context
|
244
254
|
}
|