@sentio/runtime 2.3.5 → 2.3.6-rc.1

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.
@@ -6,6 +6,10 @@ import commandLineArgs from 'command-line-args';
6
6
  import { createServer } from 'nice-grpc';
7
7
  import { createLogger, transports, format } from 'winston';
8
8
  import { compressionAlgorithms } from '@grpc/grpc-js';
9
+ import { register as globalRegistry, Registry } from 'prom-client';
10
+ import { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus';
11
+ import http from 'http';
12
+ const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry]);
9
13
  import { ProcessorDefinition } from '@sentio/protos';
10
14
  import { ProcessorServiceImpl } from './service.js';
11
15
  import { Endpoints } from './endpoints.js';
@@ -77,7 +81,7 @@ const server = createServer({
77
81
  'grpc.max_send_message_length': 128 * 1024 * 1024,
78
82
  'grpc.max_receive_message_length': 128 * 1024 * 1024,
79
83
  'grpc.default_compression_algorithm': compressionAlgorithms.gzip,
80
- });
84
+ }).use(prometheusServerMiddleware());
81
85
  const baseService = new ProcessorServiceImpl(async () => {
82
86
  const m = await import(options.target);
83
87
  if (options.debug) {
@@ -89,4 +93,18 @@ const service = new FullProcessorServiceImpl(baseService);
89
93
  server.add(ProcessorDefinition, service);
90
94
  server.listen('0.0.0.0:' + options.port);
91
95
  console.log('Processor Server Started at:', options.port);
96
+ const metricsPort = 4040;
97
+ http
98
+ .createServer(async function (req, res) {
99
+ if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {
100
+ const metrics = await mergedRegistry.metrics();
101
+ res.write(metrics);
102
+ }
103
+ else {
104
+ res.writeHead(404);
105
+ }
106
+ res.end();
107
+ })
108
+ .listen(metricsPort);
109
+ console.log('Metric Server Started at:', metricsPort);
92
110
  //# sourceMappingURL=processor-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names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AAE;YACR,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;SAC7C;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,EAAE,CAAC,CAAA;SAChD;KACF;CACF;AAED,IAAI,OAAO,CAAC,KAAK,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,8BAA8B,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACjD,iCAAiC,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACpD,oCAAoC,EAAE,qBAAqB,CAAC,IAAI;CACjE,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,IAAI,oBAAoB,CAAC,KAAK,IAAI,EAAE;IACtD,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACtC,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;KAChC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;AACnB,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC,WAAW,CAAC,CAAA;AAEzD,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { ProcessorDefinition } from '@sentio/protos'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n})\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n"]}
1
+ {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AAC/F,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,CAAA;AAEzE,OAAO,EAAE,mBAAmB,E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AAW,CAAC,CAAA;AAEtB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { register as globalRegistry, Registry } from 'prom-client'\nimport { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'\nimport http from 'http'\n\nconst mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])\n\nimport { ProcessorDefinition } from '@sentio/protos'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n}).use(prometheusServerMiddleware())\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n\nconst metricsPort = 4040\nhttp\n .createServer(async function (req, res) {\n if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {\n const metrics = await mergedRegistry.metrics()\n res.write(metrics)\n } else {\n res.writeHead(404)\n }\n res.end()\n })\n .listen(metricsPort)\n\nconsole.log('Metric Server Started at:', metricsPort)\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
3
  "license": "Apache-2.0",
4
- "version": "2.3.5",
4
+ "version": "2.3.6-rc.1",
5
5
  "scripts": {
6
6
  "compile": "tsc",
7
7
  "build": "yarn compile",
@@ -13,13 +13,14 @@
13
13
  "start_js": "ts-node-esm --files ./lib/processor-runner.js $PWD/../../debug/dist/lib.js"
14
14
  },
15
15
  "dependencies": {
16
- "@sentio/protos": "^2.3.5",
16
+ "@sentio/protos": "^2.3.6-rc.1",
17
17
  "command-line-args": "^5.2.1",
18
18
  "command-line-usage": "^6.1.3",
19
19
  "fs-extra": "^11.0.0",
20
20
  "google-protobuf": "^3.15.8",
21
21
  "nice-grpc": "^2.1.0",
22
22
  "nice-grpc-client-middleware-retry": "^2.0.2",
23
+ "nice-grpc-prometheus": "^0.1.2",
23
24
  "winston": "^3.8.2"
24
25
  },
25
26
  "devDependencies": {
@@ -45,5 +46,5 @@
45
46
  "!{lib,src}/tests",
46
47
  "!**/*.test.{js,ts}"
47
48
  ],
48
- "gitHead": "b8bcbe0d3f769c14e2001d7987b401bbd553fac2"
49
+ "gitHead": "95d6e4dc0ce01ecbeda747dc5dcee39d8853a087"
49
50
  }
@@ -9,6 +9,12 @@ import { createServer } from 'nice-grpc'
9
9
  import { createLogger, transports, format } from 'winston'
10
10
  import { compressionAlgorithms } from '@grpc/grpc-js'
11
11
 
12
+ import { register as globalRegistry, Registry } from 'prom-client'
13
+ import { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'
14
+ import http from 'http'
15
+
16
+ const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
17
+
12
18
  import { ProcessorDefinition } from '@sentio/protos'
13
19
  import { ProcessorServiceImpl } from './service.js'
14
20
  import { Endpoints } from './endpoints.js'
@@ -94,7 +100,7 @@ const server = createServer({
94
100
  'grpc.max_send_message_length': 128 * 1024 * 1024,
95
101
  'grpc.max_receive_message_length': 128 * 1024 * 1024,
96
102
  'grpc.default_compression_algorithm': compressionAlgorithms.gzip,
97
- })
103
+ }).use(prometheusServerMiddleware())
98
104
 
99
105
  const baseService = new ProcessorServiceImpl(async () => {
100
106
  const m = await import(options.target)
@@ -110,3 +116,18 @@ server.add(ProcessorDefinition, service)
110
116
  server.listen('0.0.0.0:' + options.port)
111
117
 
112
118
  console.log('Processor Server Started at:', options.port)
119
+
120
+ const metricsPort = 4040
121
+ http
122
+ .createServer(async function (req, res) {
123
+ if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {
124
+ const metrics = await mergedRegistry.metrics()
125
+ res.write(metrics)
126
+ } else {
127
+ res.writeHead(404)
128
+ }
129
+ res.end()
130
+ })
131
+ .listen(metricsPort)
132
+
133
+ console.log('Metric Server Started at:', metricsPort)