envio 3.0.0-alpha.2 → 3.0.0-alpha.21

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.
Files changed (184) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +578 -1
  6. package/index.js +4 -0
  7. package/package.json +47 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +725 -25
  18. package/src/Config.res.mjs +692 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +33 -73
  23. package/src/Env.res.mjs +29 -85
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +77 -9
  26. package/src/Envio.res.mjs +39 -1
  27. package/src/EventConfigBuilder.res +408 -0
  28. package/src/EventConfigBuilder.res.mjs +376 -0
  29. package/src/EventProcessing.res +469 -0
  30. package/src/EventProcessing.res.mjs +337 -0
  31. package/src/EvmTypes.gen.ts +6 -0
  32. package/src/EvmTypes.res +1 -0
  33. package/src/FetchState.res +1256 -639
  34. package/src/FetchState.res.mjs +1135 -612
  35. package/src/GlobalState.res +1224 -0
  36. package/src/GlobalState.res.mjs +1291 -0
  37. package/src/GlobalStateManager.res +68 -0
  38. package/src/GlobalStateManager.res.mjs +75 -0
  39. package/src/GlobalStateManager.resi +7 -0
  40. package/src/HandlerLoader.res +89 -0
  41. package/src/HandlerLoader.res.mjs +79 -0
  42. package/src/HandlerRegister.res +357 -0
  43. package/src/HandlerRegister.res.mjs +299 -0
  44. package/src/HandlerRegister.resi +30 -0
  45. package/src/Hasura.res +111 -175
  46. package/src/Hasura.res.mjs +88 -150
  47. package/src/InMemoryStore.res +1 -1
  48. package/src/InMemoryStore.res.mjs +3 -3
  49. package/src/InMemoryTable.res +1 -1
  50. package/src/InMemoryTable.res.mjs +1 -1
  51. package/src/Internal.gen.ts +6 -0
  52. package/src/Internal.res +265 -12
  53. package/src/Internal.res.mjs +115 -1
  54. package/src/LoadLayer.res +444 -0
  55. package/src/LoadLayer.res.mjs +296 -0
  56. package/src/LoadLayer.resi +32 -0
  57. package/src/LogSelection.res +33 -27
  58. package/src/LogSelection.res.mjs +6 -0
  59. package/src/Logging.res +21 -7
  60. package/src/Logging.res.mjs +16 -8
  61. package/src/Main.res +390 -0
  62. package/src/Main.res.mjs +341 -0
  63. package/src/Persistence.res +7 -21
  64. package/src/Persistence.res.mjs +3 -3
  65. package/src/PgStorage.gen.ts +10 -0
  66. package/src/PgStorage.res +116 -69
  67. package/src/PgStorage.res.d.mts +5 -0
  68. package/src/PgStorage.res.mjs +93 -50
  69. package/src/Prometheus.res +294 -224
  70. package/src/Prometheus.res.mjs +353 -340
  71. package/src/ReorgDetection.res +6 -10
  72. package/src/ReorgDetection.res.mjs +6 -6
  73. package/src/SafeCheckpointTracking.res +4 -4
  74. package/src/SafeCheckpointTracking.res.mjs +2 -2
  75. package/src/SimulateItems.res +353 -0
  76. package/src/SimulateItems.res.mjs +335 -0
  77. package/src/Sink.res +4 -2
  78. package/src/Sink.res.mjs +2 -1
  79. package/src/TableIndices.res +0 -1
  80. package/src/TestIndexer.res +913 -0
  81. package/src/TestIndexer.res.mjs +698 -0
  82. package/src/TestIndexerProxyStorage.res +205 -0
  83. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  84. package/src/TopicFilter.res +1 -1
  85. package/src/Types.ts +1 -1
  86. package/src/UserContext.res +424 -0
  87. package/src/UserContext.res.mjs +279 -0
  88. package/src/Utils.res +97 -26
  89. package/src/Utils.res.mjs +91 -44
  90. package/src/bindings/BigInt.res +10 -0
  91. package/src/bindings/BigInt.res.mjs +15 -0
  92. package/src/bindings/ClickHouse.res +120 -23
  93. package/src/bindings/ClickHouse.res.mjs +118 -28
  94. package/src/bindings/DateFns.res +74 -0
  95. package/src/bindings/DateFns.res.mjs +22 -0
  96. package/src/bindings/EventSource.res +11 -2
  97. package/src/bindings/EventSource.res.mjs +8 -1
  98. package/src/bindings/Express.res +1 -0
  99. package/src/bindings/Hrtime.res +14 -1
  100. package/src/bindings/Hrtime.res.mjs +22 -2
  101. package/src/bindings/Hrtime.resi +4 -0
  102. package/src/bindings/Lodash.res +0 -1
  103. package/src/bindings/NodeJs.res +49 -3
  104. package/src/bindings/NodeJs.res.mjs +11 -3
  105. package/src/bindings/Pino.res +24 -10
  106. package/src/bindings/Pino.res.mjs +14 -8
  107. package/src/bindings/Postgres.gen.ts +8 -0
  108. package/src/bindings/Postgres.res +5 -1
  109. package/src/bindings/Postgres.res.d.mts +5 -0
  110. package/src/bindings/PromClient.res +0 -10
  111. package/src/bindings/PromClient.res.mjs +0 -3
  112. package/src/bindings/Vitest.res +144 -0
  113. package/src/bindings/Vitest.res.mjs +9 -0
  114. package/src/bindings/WebSocket.res +27 -0
  115. package/src/bindings/WebSocket.res.mjs +2 -0
  116. package/src/bindings/Yargs.res +8 -0
  117. package/src/bindings/Yargs.res.mjs +2 -0
  118. package/src/db/EntityHistory.res +7 -7
  119. package/src/db/EntityHistory.res.mjs +9 -9
  120. package/src/db/InternalTable.res +59 -111
  121. package/src/db/InternalTable.res.mjs +73 -104
  122. package/src/db/Table.res +27 -8
  123. package/src/db/Table.res.mjs +25 -14
  124. package/src/sources/Evm.res +84 -0
  125. package/src/sources/Evm.res.mjs +105 -0
  126. package/src/sources/EvmChain.res +94 -0
  127. package/src/sources/EvmChain.res.mjs +60 -0
  128. package/src/sources/Fuel.res +19 -34
  129. package/src/sources/Fuel.res.mjs +34 -16
  130. package/src/sources/FuelSDK.res +38 -0
  131. package/src/sources/FuelSDK.res.mjs +29 -0
  132. package/src/sources/HyperFuel.res +2 -2
  133. package/src/sources/HyperFuel.resi +1 -1
  134. package/src/sources/HyperFuelClient.res +2 -2
  135. package/src/sources/HyperFuelSource.res +35 -13
  136. package/src/sources/HyperFuelSource.res.mjs +26 -16
  137. package/src/sources/HyperSync.res +61 -60
  138. package/src/sources/HyperSync.res.mjs +53 -67
  139. package/src/sources/HyperSync.resi +6 -4
  140. package/src/sources/HyperSyncClient.res +29 -2
  141. package/src/sources/HyperSyncClient.res.mjs +9 -0
  142. package/src/sources/HyperSyncHeightStream.res +76 -118
  143. package/src/sources/HyperSyncHeightStream.res.mjs +68 -75
  144. package/src/sources/HyperSyncSource.res +122 -143
  145. package/src/sources/HyperSyncSource.res.mjs +106 -121
  146. package/src/sources/Rpc.res +86 -14
  147. package/src/sources/Rpc.res.mjs +101 -9
  148. package/src/sources/RpcSource.res +731 -364
  149. package/src/sources/RpcSource.res.mjs +845 -410
  150. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  151. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  152. package/src/sources/SimulateSource.res +59 -0
  153. package/src/sources/SimulateSource.res.mjs +50 -0
  154. package/src/sources/Source.res +7 -5
  155. package/src/sources/SourceManager.res +358 -221
  156. package/src/sources/SourceManager.res.mjs +346 -171
  157. package/src/sources/SourceManager.resi +17 -6
  158. package/src/sources/Svm.res +81 -0
  159. package/src/sources/Svm.res.mjs +90 -0
  160. package/src/tui/Tui.res +247 -0
  161. package/src/tui/Tui.res.mjs +337 -0
  162. package/src/tui/bindings/Ink.res +371 -0
  163. package/src/tui/bindings/Ink.res.mjs +72 -0
  164. package/src/tui/bindings/Style.res +123 -0
  165. package/src/tui/bindings/Style.res.mjs +2 -0
  166. package/src/tui/components/BufferedProgressBar.res +40 -0
  167. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  168. package/src/tui/components/CustomHooks.res +122 -0
  169. package/src/tui/components/CustomHooks.res.mjs +179 -0
  170. package/src/tui/components/Messages.res +41 -0
  171. package/src/tui/components/Messages.res.mjs +75 -0
  172. package/src/tui/components/SyncETA.res +174 -0
  173. package/src/tui/components/SyncETA.res.mjs +263 -0
  174. package/src/tui/components/TuiData.res +47 -0
  175. package/src/tui/components/TuiData.res.mjs +34 -0
  176. package/svm.schema.json +112 -0
  177. package/bin.js +0 -48
  178. package/src/EventRegister.res +0 -241
  179. package/src/EventRegister.res.mjs +0 -240
  180. package/src/EventRegister.resi +0 -30
  181. package/src/bindings/Ethers.gen.ts +0 -14
  182. package/src/bindings/Ethers.res +0 -204
  183. package/src/bindings/Ethers.res.mjs +0 -130
  184. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -1,45 +1,3 @@
1
- let loadEntitiesDurationCounter = PromClient.Counter.makeCounter({
2
- "name": "load_entities_processing_time_spent",
3
- "help": "Duration spend on loading entities",
4
- "labelNames": [],
5
- })
6
-
7
- let eventRouterDurationCounter = PromClient.Counter.makeCounter({
8
- "name": "event_router_processing_time_spent",
9
- "help": "Duration spend on event routing",
10
- "labelNames": [],
11
- })
12
-
13
- let executeBatchDurationCounter = PromClient.Counter.makeCounter({
14
- "name": "execute_batch_processing_time_spent",
15
- "help": "Duration spend on executing batch",
16
- "labelNames": [],
17
- })
18
-
19
- let storageWriteTimeCounter = PromClient.Counter.makeCounter({
20
- "name": "envio_storage_write_time",
21
- "help": "Cumulative time spent writing batches to storage in milliseconds",
22
- "labelNames": [],
23
- })
24
-
25
- let storageWriteCounter = PromClient.Counter.makeCounter({
26
- "name": "envio_storage_write_count",
27
- "help": "Total number of batch writes to storage",
28
- "labelNames": [],
29
- })
30
-
31
- let allChainsSyncedToHead = PromClient.Gauge.makeGauge({
32
- "name": "hyperindex_synced_to_head",
33
- "help": "All chains fully synced",
34
- "labelNames": [],
35
- })
36
-
37
- let sourceChainHeight = PromClient.Gauge.makeGauge({
38
- "name": "chain_block_height",
39
- "help": "Chain Height of Source Chain",
40
- "labelNames": ["chainId"],
41
- })
42
-
43
1
  module Labels = {
44
2
  let rec schemaIsString = (schema: S.t<'a>) =>
45
3
  switch schema->S.classify {
@@ -142,7 +100,13 @@ module SafeCounter = MakeSafePromMetric({
142
100
  let make = PromClient.Counter.makeCounter
143
101
  let labels = PromClient.Counter.labels
144
102
  let handleInt = PromClient.Counter.incMany
145
- let handleFloat = PromClient.Counter.incMany->Utils.magic
103
+ let handleFloat =
104
+ PromClient.Counter.incMany->(
105
+ Utils.magic: ((PromClient.Counter.counter, int) => unit) => (
106
+ PromClient.Counter.counter,
107
+ float,
108
+ ) => unit
109
+ )
146
110
  })
147
111
 
148
112
  module SafeGauge = MakeSafePromMetric({
@@ -153,117 +117,213 @@ module SafeGauge = MakeSafePromMetric({
153
117
  let handleFloat = PromClient.Gauge.setFloat
154
118
  })
155
119
 
156
- let makeSafeHistogramOrThrow = (~name, ~help, ~labelSchema, ~backets=?) => {
157
- let histogram = PromClient.Histogram.make({
158
- "name": name,
159
- "help": help,
160
- "labelNames": labelSchema->Labels.getLabelNames->Belt.Result.getExn,
161
- "buckets": backets,
120
+
121
+ module ProcessingBatch = {
122
+ let loadTimeCounter = PromClient.Counter.makeCounter({
123
+ "name": "envio_preload_seconds",
124
+ "help": "Cumulative time spent on preloading entities during batch processing.",
125
+ })
126
+
127
+ let handlerTimeCounter = PromClient.Counter.makeCounter({
128
+ "name": "envio_processing_seconds",
129
+ "help": "Cumulative time spent executing event handlers during batch processing.",
130
+ })
131
+
132
+ let writeTimeCounter = PromClient.Counter.makeCounter({
133
+ "name": "envio_storage_write_seconds",
134
+ "help": "Cumulative time spent writing batch data to storage.",
135
+ })
136
+
137
+ let writeCount = PromClient.Counter.makeCounter({
138
+ "name": "envio_storage_write_total",
139
+ "help": "Total number of batch writes to storage.",
162
140
  })
163
141
 
164
- labels => {
165
- histogram
166
- ->PromClient.Histogram.labels(labels->S.reverseConvertToJsonOrThrow(labelSchema))
167
- ->PromClient.Histogram.startTimer
142
+ let registerMetrics = (~loadDuration, ~handlerDuration, ~dbWriteDuration) => {
143
+ loadTimeCounter->PromClient.Counter.incMany(loadDuration->(Utils.magic: float => int))
144
+ handlerTimeCounter->PromClient.Counter.incMany(handlerDuration->(Utils.magic: float => int))
145
+ writeTimeCounter->PromClient.Counter.incMany(dbWriteDuration->(Utils.magic: float => int))
146
+ writeCount->PromClient.Counter.inc
168
147
  }
169
148
  }
170
149
 
171
- module BenchmarkSummaryData = {
172
- type labels = {
173
- group: string,
174
- stat: string,
175
- label: string,
176
- }
177
- let labelSchema = S.schema(s => {
178
- group: s.matches(S.string),
179
- stat: s.matches(S.string),
180
- label: s.matches(S.string),
181
- })
150
+ let chainIdLabelsSchema = S.object(s => {
151
+ s.field("chainId", S.string->S.coerce(S.int))
152
+ })
182
153
 
154
+ module ProgressReady = {
183
155
  let gauge = SafeGauge.makeOrThrow(
184
- ~name="benchmark_summary_data",
185
- ~help="All data points collected during indexer benchmark",
186
- ~labelSchema,
187
- )
188
-
189
- let set = (
190
- ~group: string,
191
- ~label: string,
192
- ~n: float,
193
- ~mean: float,
194
- ~stdDev: option<float>,
195
- ~min: float,
196
- ~max: float,
197
- ~sum: float,
198
- ) => {
199
- let mk = stat => {
200
- group,
201
- stat,
202
- label,
203
- }
204
- gauge->SafeGauge.handleFloat(~labels=mk("n"), ~value=n)
205
- gauge->SafeGauge.handleFloat(~labels=mk("mean"), ~value=mean)
206
- gauge->SafeGauge.handleFloat(~labels=mk("min"), ~value=min)
207
- gauge->SafeGauge.handleFloat(~labels=mk("max"), ~value=max)
208
- gauge->SafeGauge.handleFloat(~labels=mk("sum"), ~value=sum)
209
- switch stdDev {
210
- | Some(stdDev) => gauge->SafeGauge.handleFloat(~labels=mk("stdDev"), ~value=stdDev)
211
- | None => ()
212
- }
156
+ ~name="envio_progress_ready",
157
+ ~help="Whether the chain is fully synced to the head.",
158
+ ~labelSchema=chainIdLabelsSchema,
159
+ )
160
+
161
+ // Keep legacy metric name for backward compatibility
162
+ let legacyGauge = PromClient.Gauge.makeGauge({
163
+ "name": "hyperindex_synced_to_head",
164
+ "help": "All chains fully synced",
165
+ })
166
+
167
+ let init = (~chainId) => {
168
+ gauge->SafeGauge.handleInt(~labels=chainId, ~value=0)
213
169
  }
214
- }
215
170
 
216
- let incrementLoadEntityDurationCounter = (~duration) => {
217
- loadEntitiesDurationCounter->PromClient.Counter.incMany(duration)
218
- }
171
+ let set = (~chainId) => {
172
+ gauge->SafeGauge.handleInt(~labels=chainId, ~value=1)
173
+ }
219
174
 
220
- let incrementEventRouterDurationCounter = (~duration) => {
221
- eventRouterDurationCounter->PromClient.Counter.incMany(duration)
175
+ let setAllReady = () => {
176
+ legacyGauge->PromClient.Gauge.set(1)
177
+ }
222
178
  }
223
179
 
224
- let incrementExecuteBatchDurationCounter = (~duration) => {
225
- executeBatchDurationCounter->PromClient.Counter.incMany(duration)
226
- }
180
+ let handlerLabelsSchema = S.schema(s =>
181
+ {
182
+ "contract": s.matches(S.string),
183
+ "event": s.matches(S.string),
184
+ }
185
+ )
227
186
 
228
- let incrementStorageWriteTimeCounter = (~duration) => {
229
- storageWriteTimeCounter->PromClient.Counter.incMany(duration)
230
- }
187
+ module ProcessingHandler = {
188
+ let timeCounter = SafeCounter.makeOrThrow(
189
+ ~name="envio_processing_handler_seconds",
190
+ ~help="Cumulative time spent inside individual event handler executions.",
191
+ ~labelSchema=handlerLabelsSchema,
192
+ )
231
193
 
232
- let incrementStorageWriteCounter = () => {
233
- storageWriteCounter->PromClient.Counter.inc
234
- }
194
+ let count = SafeCounter.makeOrThrow(
195
+ ~name="envio_processing_handler_total",
196
+ ~help="Total number of individual event handler executions.",
197
+ ~labelSchema=handlerLabelsSchema,
198
+ )
235
199
 
236
- let setSourceChainHeight = (~blockNumber, ~chainId) => {
237
- sourceChainHeight
238
- ->PromClient.Gauge.labels({"chainId": chainId})
239
- ->PromClient.Gauge.set(blockNumber)
200
+ let increment = (~contract, ~event, ~duration) => {
201
+ let labels = {"contract": contract, "event": event}
202
+ timeCounter->SafeCounter.handleFloat(~labels, ~value=duration)
203
+ count->SafeCounter.increment(~labels)
204
+ }
240
205
  }
241
206
 
242
- let setAllChainsSyncedToHead = () => {
243
- allChainsSyncedToHead->PromClient.Gauge.set(1)
207
+ module PreloadHandler = {
208
+ let timeCounter = SafeCounter.makeOrThrow(
209
+ ~name="envio_preload_handler_seconds",
210
+ ~help="Wall-clock time spent inside individual preload handler executions.",
211
+ ~labelSchema=handlerLabelsSchema,
212
+ )
213
+
214
+ let count = SafeCounter.makeOrThrow(
215
+ ~name="envio_preload_handler_total",
216
+ ~help="Total number of individual preload handler executions.",
217
+ ~labelSchema=handlerLabelsSchema,
218
+ )
219
+
220
+ let sumTimeCounter = SafeCounter.makeOrThrow(
221
+ ~name="envio_preload_handler_seconds_total",
222
+ ~help="Cumulative time spent inside individual preload handler executions. Can exceed wall-clock time due to parallel execution.",
223
+ ~labelSchema=handlerLabelsSchema,
224
+ )
225
+
226
+ type operationRef = {
227
+ mutable pendingCount: int,
228
+ timerRef: Hrtime.timeRef,
229
+ }
230
+ let operations: Js.Dict.t<operationRef> = Js.Dict.empty()
231
+
232
+ let makeKey = (~contract, ~event) => contract ++ ":" ++ event
233
+
234
+ let startOperation = (~contract, ~event) => {
235
+ let key = makeKey(~contract, ~event)
236
+ switch operations->Utils.Dict.dangerouslyGetNonOption(key) {
237
+ | Some(operationRef) => operationRef.pendingCount = operationRef.pendingCount + 1
238
+ | None =>
239
+ operations->Js.Dict.set(
240
+ key,
241
+ {
242
+ pendingCount: 1,
243
+ timerRef: Hrtime.makeTimer(),
244
+ },
245
+ )
246
+ }
247
+ Hrtime.makeTimer()
248
+ }
249
+
250
+ let endOperation = (timerRef, ~contract, ~event) => {
251
+ let key = makeKey(~contract, ~event)
252
+ let labels = {"contract": contract, "event": event}
253
+ let operationRef = operations->Js.Dict.unsafeGet(key)
254
+ operationRef.pendingCount = operationRef.pendingCount - 1
255
+ if operationRef.pendingCount === 0 {
256
+ timeCounter->SafeCounter.handleFloat(
257
+ ~labels,
258
+ ~value=operationRef.timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat,
259
+ )
260
+ operations->Utils.Dict.deleteInPlace(key)
261
+ }
262
+ sumTimeCounter->SafeCounter.handleFloat(
263
+ ~labels,
264
+ ~value=timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat,
265
+ )
266
+ count->SafeCounter.increment(~labels)
267
+ }
244
268
  }
245
269
 
246
- module BenchmarkCounters = {
247
- type labels = {label: string}
248
- let labelSchema = S.schema(s => {
249
- label: s.matches(S.string),
250
- })
270
+ module FetchingBlockRange = {
271
+ let timeCounter = SafeCounter.makeOrThrow(
272
+ ~name="envio_fetching_block_range_seconds",
273
+ ~help="Cumulative time spent fetching block ranges.",
274
+ ~labelSchema=chainIdLabelsSchema,
275
+ )
251
276
 
252
- let gauge = SafeGauge.makeOrThrow(
253
- ~name="benchmark_counters",
254
- ~help="All counters collected during indexer benchmark",
255
- ~labelSchema,
277
+ let parseTimeCounter = SafeCounter.makeOrThrow(
278
+ ~name="envio_fetching_block_range_parse_seconds",
279
+ ~help="Cumulative time spent parsing block range fetch responses.",
280
+ ~labelSchema=chainIdLabelsSchema,
256
281
  )
257
282
 
258
- let set = (~label, ~millis, ~totalRuntimeMillis) => {
259
- gauge->SafeGauge.handleFloat(~labels={label: label}, ~value=millis)
260
- gauge->SafeGauge.handleFloat(~labels={label: "Total Run Time (ms)"}, ~value=totalRuntimeMillis)
283
+ let count = SafeCounter.makeOrThrow(
284
+ ~name="envio_fetching_block_range_total",
285
+ ~help="Total number of block range fetch operations.",
286
+ ~labelSchema=chainIdLabelsSchema,
287
+ )
288
+
289
+ let eventsCount = SafeCounter.makeOrThrow(
290
+ ~name="envio_fetching_block_range_events_total",
291
+ ~help="Cumulative number of events fetched across all block range operations.",
292
+ ~labelSchema=chainIdLabelsSchema,
293
+ )
294
+
295
+ let sizeCounter = SafeCounter.makeOrThrow(
296
+ ~name="envio_fetching_block_range_size",
297
+ ~help="Cumulative number of blocks covered across all block range fetch operations.",
298
+ ~labelSchema=chainIdLabelsSchema,
299
+ )
300
+
301
+ let increment = (
302
+ ~chainId,
303
+ ~totalTimeElapsed,
304
+ ~parsingTimeElapsed,
305
+ ~numEvents,
306
+ ~blockRangeSize,
307
+ ) => {
308
+ timeCounter->SafeCounter.handleFloat(~labels=chainId, ~value=totalTimeElapsed)
309
+ parseTimeCounter->SafeCounter.handleFloat(~labels=chainId, ~value=parsingTimeElapsed)
310
+ count->SafeCounter.increment(~labels=chainId)
311
+ eventsCount->SafeCounter.handleInt(~labels=chainId, ~value=numEvents)
312
+ sizeCounter->SafeCounter.handleInt(~labels=chainId, ~value=blockRangeSize)
261
313
  }
262
314
  }
263
315
 
264
- let chainIdLabelsSchema = S.object(s => {
265
- s.field("chainId", S.string->S.coerce(S.int))
266
- })
316
+ module IndexingKnownHeight = {
317
+ let gauge = SafeGauge.makeOrThrow(
318
+ ~name="envio_indexing_known_height",
319
+ ~help="The latest known block number reported by the active indexing source. This value may lag behind the actual chain height, as it is updated only when needed.",
320
+ ~labelSchema=chainIdLabelsSchema,
321
+ )
322
+
323
+ let set = (~blockNumber, ~chainId) => {
324
+ gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
325
+ }
326
+ }
267
327
 
268
328
  module Info = {
269
329
  let gauge = SafeGauge.makeOrThrow(
@@ -281,6 +341,17 @@ module Info = {
281
341
  }
282
342
  }
283
343
 
344
+ module ProcessStartTimeSeconds = {
345
+ let gauge = PromClient.Gauge.makeGauge({
346
+ "name": "envio_process_start_time_seconds",
347
+ "help": "Start time of the process since unix epoch in seconds.",
348
+ })
349
+
350
+ let set = () => {
351
+ gauge->PromClient.Gauge.setFloat(Js.Date.now() /. 1000.0)
352
+ }
353
+ }
354
+
284
355
  module IndexingAddresses = {
285
356
  let gauge = SafeGauge.makeOrThrow(
286
357
  ~name="envio_indexing_addresses",
@@ -331,24 +402,24 @@ module IndexingPartitions = {
331
402
 
332
403
  module IndexingIdleTime = {
333
404
  let counter = SafeCounter.makeOrThrow(
334
- ~name="envio_indexing_idle_time",
335
- ~help="The number of milliseconds the indexer source syncing has been idle. A high value may indicate the source sync is a bottleneck.",
405
+ ~name="envio_indexing_idle_seconds",
406
+ ~help="The time the indexer source syncing has been idle. A high value may indicate the source sync is a bottleneck.",
336
407
  ~labelSchema=chainIdLabelsSchema,
337
408
  )
338
409
  }
339
410
 
340
411
  module IndexingSourceWaitingTime = {
341
412
  let counter = SafeCounter.makeOrThrow(
342
- ~name="envio_indexing_source_waiting_time",
343
- ~help="The number of milliseconds the indexer has been waiting for new blocks.",
413
+ ~name="envio_indexing_source_waiting_seconds",
414
+ ~help="The time the indexer has been waiting for new blocks.",
344
415
  ~labelSchema=chainIdLabelsSchema,
345
416
  )
346
417
  }
347
418
 
348
419
  module IndexingQueryTime = {
349
420
  let counter = SafeCounter.makeOrThrow(
350
- ~name="envio_indexing_query_time",
351
- ~help="The number of milliseconds spent performing queries to the chain data-source.",
421
+ ~name="envio_indexing_source_querying_seconds",
422
+ ~help="The time spent performing queries to the chain data-source.",
352
423
  ~labelSchema=chainIdLabelsSchema,
353
424
  )
354
425
  }
@@ -377,22 +448,13 @@ module IndexingTargetBufferSize = {
377
448
  }
378
449
 
379
450
  module IndexingBufferBlockNumber = {
380
- let deprecatedGauge = PromClient.Gauge.makeGauge({
381
- "name": "chain_block_height_fully_fetched",
382
- "help": "Block height fully fetched by indexer",
383
- "labelNames": ["chainId"],
384
- })
385
-
386
451
  let gauge = SafeGauge.makeOrThrow(
387
- ~name="envio_indexing_buffer_block_number",
452
+ ~name="envio_indexing_buffer_block",
388
453
  ~help="The highest block number that has been fully fetched by the indexer.",
389
454
  ~labelSchema=chainIdLabelsSchema,
390
455
  )
391
456
 
392
457
  let set = (~blockNumber, ~chainId) => {
393
- deprecatedGauge
394
- ->PromClient.Gauge.labels({"chainId": chainId})
395
- ->PromClient.Gauge.set(blockNumber)
396
458
  gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
397
459
  }
398
460
  }
@@ -416,9 +478,44 @@ let sourceLabelsSchema = S.schema(s =>
416
478
  }
417
479
  )
418
480
 
481
+ let sourceRequestLabelsSchema = S.schema(s =>
482
+ {
483
+ "source": s.matches(S.string),
484
+ "chainId": s.matches(S.string->S.coerce(S.int)),
485
+ "method": s.matches(S.string),
486
+ }
487
+ )
488
+
489
+ module SourceRequestCount = {
490
+ let counter = SafeCounter.makeOrThrow(
491
+ ~name="envio_source_request_total",
492
+ ~help="The number of requests made to data sources.",
493
+ ~labelSchema=sourceRequestLabelsSchema,
494
+ )
495
+
496
+ let sumTimeCounter = SafeCounter.makeOrThrow(
497
+ ~name="envio_source_request_seconds_total",
498
+ ~help="Cumulative time spent on data source requests.",
499
+ ~labelSchema=sourceRequestLabelsSchema,
500
+ )
501
+
502
+ let increment = (~sourceName, ~chainId, ~method) => {
503
+ counter->SafeCounter.increment(
504
+ ~labels={"source": sourceName, "chainId": chainId, "method": method},
505
+ )
506
+ }
507
+
508
+ let addSeconds = (~sourceName, ~chainId, ~method, ~seconds) => {
509
+ sumTimeCounter->SafeCounter.handleFloat(
510
+ ~labels={"source": sourceName, "chainId": chainId, "method": method},
511
+ ~value=seconds,
512
+ )
513
+ }
514
+ }
515
+
419
516
  module SourceHeight = {
420
517
  let gauge = SafeGauge.makeOrThrow(
421
- ~name="envio_source_height",
518
+ ~name="envio_source_known_height",
422
519
  ~help="The latest known block number reported by the source. This value may lag behind the actual chain height, as it is updated only when queried.",
423
520
  ~labelSchema=sourceLabelsSchema,
424
521
  )
@@ -431,30 +528,21 @@ module SourceHeight = {
431
528
  }
432
529
  }
433
530
 
434
- module SourceGetHeightDuration = {
435
- let startTimer = makeSafeHistogramOrThrow(
436
- ~name="envio_source_get_height_duration",
437
- ~help="Duration of the source get height requests in seconds",
438
- ~labelSchema=sourceLabelsSchema,
439
- ~backets=[0.1, 0.5, 1., 10.],
440
- )
441
- }
442
-
443
531
  module ReorgCount = {
444
- let gauge = SafeGauge.makeOrThrow(
445
- ~name="envio_reorg_count",
532
+ let counter = SafeCounter.makeOrThrow(
533
+ ~name="envio_reorg_detected_total",
446
534
  ~help="Total number of reorgs detected",
447
535
  ~labelSchema=chainIdLabelsSchema,
448
536
  )
449
537
 
450
538
  let increment = (~chain) => {
451
- gauge->SafeGauge.increment(~labels=chain->ChainMap.Chain.toChainId)
539
+ counter->SafeCounter.increment(~labels=chain->ChainMap.Chain.toChainId)
452
540
  }
453
541
  }
454
542
 
455
543
  module ReorgDetectionBlockNumber = {
456
544
  let gauge = SafeGauge.makeOrThrow(
457
- ~name="envio_reorg_detection_block_number",
545
+ ~name="envio_reorg_detected_block",
458
546
  ~help="The block number where reorg was detected the last time. This doesn't mean that the block was reorged, this is simply where we found block hash to be different.",
459
547
  ~labelSchema=chainIdLabelsSchema,
460
548
  )
@@ -488,24 +576,26 @@ module RollbackEnabled = {
488
576
 
489
577
  module RollbackSuccess = {
490
578
  let timeCounter = PromClient.Counter.makeCounter({
491
- "name": "envio_rollback_time",
492
- "help": "Rollback on reorg total time in milliseconds",
579
+ "name": "envio_rollback_seconds",
580
+ "help": "Rollback on reorg total time.",
493
581
  })
494
582
 
495
583
  let counter = PromClient.Counter.makeCounter({
496
- "name": "envio_rollback_count",
584
+ "name": "envio_rollback_total",
497
585
  "help": "Number of successful rollbacks on reorg",
498
586
  })
499
587
 
500
588
  let eventsCounter = PromClient.Counter.makeCounter({
501
- "name": "envio_rollback_events_count",
589
+ "name": "envio_rollback_events",
502
590
  "help": "Number of events rollbacked on reorg",
503
591
  })
504
592
 
505
- let increment = (~timeMillis: Hrtime.milliseconds, ~rollbackedProcessedEvents) => {
506
- timeCounter->PromClient.Counter.incMany(timeMillis->Hrtime.intFromMillis)
593
+ let increment = (~timeSeconds: float, ~rollbackedProcessedEvents: float) => {
594
+ timeCounter->PromClient.Counter.incMany(timeSeconds->(Utils.magic: float => int))
507
595
  counter->PromClient.Counter.inc
508
- eventsCounter->PromClient.Counter.incMany(rollbackedProcessedEvents)
596
+ eventsCounter->PromClient.Counter.incMany(
597
+ rollbackedProcessedEvents->Utils.floatToInt,
598
+ )
509
599
  }
510
600
  }
511
601
 
@@ -513,29 +603,26 @@ module RollbackHistoryPrune = {
513
603
  let entityNameLabelsSchema = S.object(s => s.field("entity", S.string))
514
604
 
515
605
  let timeCounter = SafeCounter.makeOrThrow(
516
- ~name="envio_rollback_history_prune_time",
517
- ~help="The total time spent pruning entity history which is not in the reorg threshold. (milliseconds)",
606
+ ~name="envio_rollback_history_prune_seconds",
607
+ ~help="The total time spent pruning entity history which is not in the reorg threshold.",
518
608
  ~labelSchema=entityNameLabelsSchema,
519
609
  )
520
610
 
521
611
  let counter = SafeCounter.makeOrThrow(
522
- ~name="envio_rollback_history_prune_count",
612
+ ~name="envio_rollback_history_prune_total",
523
613
  ~help="Number of successful entity history prunes",
524
614
  ~labelSchema=entityNameLabelsSchema,
525
615
  )
526
616
 
527
- let increment = (~timeMillis, ~entityName) => {
528
- timeCounter->SafeCounter.handleInt(
529
- ~labels={entityName},
530
- ~value=timeMillis->Hrtime.intFromMillis,
531
- )
617
+ let increment = (~timeSeconds, ~entityName) => {
618
+ timeCounter->SafeCounter.handleFloat(~labels={entityName}, ~value=timeSeconds)
532
619
  counter->SafeCounter.increment(~labels={entityName})
533
620
  }
534
621
  }
535
622
 
536
623
  module RollbackTargetBlockNumber = {
537
624
  let gauge = SafeGauge.makeOrThrow(
538
- ~name="envio_rollback_target_block_number",
625
+ ~name="envio_rollback_target_block",
539
626
  ~help="The block number reorg was rollbacked to the last time.",
540
627
  ~labelSchema=chainIdLabelsSchema,
541
628
  )
@@ -558,7 +645,7 @@ module ProcessingMaxBatchSize = {
558
645
 
559
646
  module ProgressBlockNumber = {
560
647
  let gauge = SafeGauge.makeOrThrow(
561
- ~name="envio_progress_block_number",
648
+ ~name="envio_progress_block",
562
649
  ~help="The block number of the latest block processed and stored in the database.",
563
650
  ~labelSchema=chainIdLabelsSchema,
564
651
  )
@@ -569,34 +656,17 @@ module ProgressBlockNumber = {
569
656
  }
570
657
 
571
658
  module ProgressEventsCount = {
572
- let deprecatedGauge = PromClient.Gauge.makeGauge({
573
- "name": "events_processed",
574
- "help": "Total number of events processed",
575
- "labelNames": ["chainId"],
576
- })
577
-
578
659
  let gauge = SafeGauge.makeOrThrow(
579
- ~name="envio_progress_events_count",
660
+ ~name="envio_progress_events",
580
661
  ~help="The number of events processed and reflected in the database.",
581
662
  ~labelSchema=chainIdLabelsSchema,
582
663
  )
583
664
 
584
- let set = (~processedCount, ~chainId) => {
585
- deprecatedGauge
586
- ->PromClient.Gauge.labels({"chainId": chainId})
587
- ->PromClient.Gauge.set(processedCount)
588
- gauge->SafeGauge.handleInt(~labels=chainId, ~value=processedCount)
589
- }
590
- }
591
-
592
- module ProgressBatchCount = {
593
- let counter = PromClient.Counter.makeCounter({
594
- "name": "envio_progress_batches_count",
595
- "help": "The number of batches processed and reflected in the database.",
596
- })
597
-
598
- let increment = () => {
599
- counter->PromClient.Counter.inc
665
+ let set = (~processedCount: float, ~chainId) => {
666
+ gauge->SafeGauge.handleFloat(
667
+ ~labels=chainId,
668
+ ~value=processedCount,
669
+ )
600
670
  }
601
671
  }
602
672
 
@@ -618,25 +688,25 @@ let effectLabelsSchema = S.object(s => {
618
688
 
619
689
  module EffectCalls = {
620
690
  let timeCounter = SafeCounter.makeOrThrow(
621
- ~name="envio_effect_calls_time",
622
- ~help="Processing time taken to call the Effect function. (milliseconds)",
691
+ ~name="envio_effect_call_seconds",
692
+ ~help="Processing time taken to call the Effect function.",
623
693
  ~labelSchema=effectLabelsSchema,
624
694
  )
625
695
 
626
696
  let sumTimeCounter = SafeCounter.makeOrThrow(
627
- ~name="envio_effect_calls_sum_time",
628
- ~help="Cumulative time spent calling the Effect function during the indexing process. (milliseconds)",
697
+ ~name="envio_effect_call_seconds_total",
698
+ ~help="Cumulative time spent calling the Effect function during the indexing process.",
629
699
  ~labelSchema=effectLabelsSchema,
630
700
  )
631
701
 
632
702
  let totalCallsCount = SafeCounter.makeOrThrow(
633
- ~name="envio_effect_calls_count",
703
+ ~name="envio_effect_call_total",
634
704
  ~help="Cumulative number of resolved Effect function calls during the indexing process.",
635
705
  ~labelSchema=effectLabelsSchema,
636
706
  )
637
707
 
638
708
  let activeCallsCount = SafeGauge.makeOrThrow(
639
- ~name="envio_effect_active_calls_count",
709
+ ~name="envio_effect_active_calls",
640
710
  ~help="The number of Effect function calls that are currently running.",
641
711
  ~labelSchema=effectLabelsSchema,
642
712
  )
@@ -644,7 +714,7 @@ module EffectCalls = {
644
714
 
645
715
  module EffectCacheCount = {
646
716
  let gauge = SafeGauge.makeOrThrow(
647
- ~name="envio_effect_cache_count",
717
+ ~name="envio_effect_cache",
648
718
  ~help="The number of items in the effect cache.",
649
719
  ~labelSchema=effectLabelsSchema,
650
720
  )
@@ -656,7 +726,7 @@ module EffectCacheCount = {
656
726
 
657
727
  module EffectCacheInvalidationsCount = {
658
728
  let counter = SafeCounter.makeOrThrow(
659
- ~name="envio_effect_cache_invalidations_count",
729
+ ~name="envio_effect_cache_invalidations",
660
730
  ~help="The number of effect cache invalidations.",
661
731
  ~labelSchema=effectLabelsSchema,
662
732
  )
@@ -668,14 +738,14 @@ module EffectCacheInvalidationsCount = {
668
738
 
669
739
  module EffectQueueCount = {
670
740
  let gauge = SafeGauge.makeOrThrow(
671
- ~name="envio_effect_queue_count",
741
+ ~name="envio_effect_queue",
672
742
  ~help="The number of effect calls waiting in the rate limit queue.",
673
743
  ~labelSchema=effectLabelsSchema,
674
744
  )
675
745
 
676
746
  let timeCounter = SafeCounter.makeOrThrow(
677
- ~name="envio_effect_queue_time",
678
- ~help="The time spent waiting in the rate limit queue. (milliseconds)",
747
+ ~name="envio_effect_queue_wait_seconds",
748
+ ~help="The time spent waiting in the rate limit queue.",
679
749
  ~labelSchema=effectLabelsSchema,
680
750
  )
681
751
 
@@ -688,19 +758,19 @@ module StorageLoad = {
688
758
  let operationLabelsSchema = S.object(s => s.field("operation", S.string))
689
759
 
690
760
  let timeCounter = SafeCounter.makeOrThrow(
691
- ~name="envio_storage_load_time",
692
- ~help="Processing time taken to load data from storage. (milliseconds)",
761
+ ~name="envio_storage_load_seconds",
762
+ ~help="Processing time taken to load data from storage.",
693
763
  ~labelSchema=operationLabelsSchema,
694
764
  )
695
765
 
696
766
  let sumTimeCounter = SafeCounter.makeOrThrow(
697
- ~name="envio_storage_load_sum_time",
698
- ~help="Cumulative time spent loading data from storage during the indexing process. (milliseconds)",
767
+ ~name="envio_storage_load_seconds_total",
768
+ ~help="Cumulative time spent loading data from storage during the indexing process.",
699
769
  ~labelSchema=operationLabelsSchema,
700
770
  )
701
771
 
702
772
  let counter = SafeCounter.makeOrThrow(
703
- ~name="envio_storage_load_count",
773
+ ~name="envio_storage_load_total",
704
774
  ~help="Cumulative number of successful storage load operations during the indexing process.",
705
775
  ~labelSchema=operationLabelsSchema,
706
776
  )
@@ -744,15 +814,15 @@ module StorageLoad = {
744
814
  let operationRef = operations->Js.Dict.unsafeGet(operation)
745
815
  operationRef.pendingCount = operationRef.pendingCount - 1
746
816
  if operationRef.pendingCount === 0 {
747
- timeCounter->SafeCounter.handleInt(
817
+ timeCounter->SafeCounter.handleFloat(
748
818
  ~labels={operation},
749
- ~value=operationRef.timerRef->Hrtime.timeSince->Hrtime.toMillis->Hrtime.intFromMillis,
819
+ ~value=operationRef.timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat,
750
820
  )
751
821
  operations->Utils.Dict.deleteInPlace(operation)
752
822
  }
753
- sumTimeCounter->SafeCounter.handleInt(
823
+ sumTimeCounter->SafeCounter.handleFloat(
754
824
  ~labels={operation},
755
- ~value=timerRef->Hrtime.timeSince->Hrtime.toMillis->Hrtime.intFromMillis,
825
+ ~value=timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat,
756
826
  )
757
827
  counter->SafeCounter.increment(~labels={operation})
758
828
  whereSizeCounter->SafeCounter.handleInt(~labels={operation}, ~value=whereSize)
@@ -764,19 +834,19 @@ module SinkWrite = {
764
834
  let sinkLabelsSchema = S.object(s => s.field("sink", S.string))
765
835
 
766
836
  let timeCounter = SafeCounter.makeOrThrow(
767
- ~name="envio_sink_write_time",
768
- ~help="Processing time taken to write data to sink. (milliseconds)",
837
+ ~name="envio_sink_write_seconds",
838
+ ~help="Processing time taken to write data to sink.",
769
839
  ~labelSchema=sinkLabelsSchema,
770
840
  )
771
841
 
772
842
  let counter = SafeCounter.makeOrThrow(
773
- ~name="envio_sink_write_count",
843
+ ~name="envio_sink_write_total",
774
844
  ~help="Cumulative number of successful sink write operations during the indexing process.",
775
845
  ~labelSchema=sinkLabelsSchema,
776
846
  )
777
847
 
778
- let increment = (~sinkName, ~timeMillis) => {
779
- timeCounter->SafeCounter.handleInt(~labels={sinkName}, ~value=timeMillis)
848
+ let increment = (~sinkName, ~timeSeconds) => {
849
+ timeCounter->SafeCounter.handleFloat(~labels={sinkName}, ~value=timeSeconds)
780
850
  counter->SafeCounter.increment(~labels={sinkName})
781
851
  }
782
852
  }