2025-03-18 15:54:55 +01:00
|
|
|
import pkg/chronicles
|
|
|
|
|
import pkg/chronos
|
|
|
|
|
import pkg/questionable
|
|
|
|
|
import pkg/questionable/results
|
|
|
|
|
|
|
|
|
|
import ../state
|
|
|
|
|
import ../services/metrics
|
|
|
|
|
import ../services/marketplace
|
|
|
|
|
import ../component
|
|
|
|
|
|
|
|
|
|
logScope:
|
2025-03-18 18:22:31 +01:00
|
|
|
topics = "chainmetrics"
|
2025-03-18 15:54:55 +01:00
|
|
|
|
|
|
|
|
type ChainMetrics* = ref object of Component
|
|
|
|
|
state: State
|
|
|
|
|
metrics: Metrics
|
|
|
|
|
marketplace: MarketplaceService
|
|
|
|
|
|
|
|
|
|
proc step(c: ChainMetrics): Future[?!void] {.async: (raises: []).} =
|
2025-03-19 15:59:55 +01:00
|
|
|
# replace slotFills entirely:
|
|
|
|
|
# iterate all requests in requestStore:
|
|
|
|
|
# get state of request on chain
|
|
|
|
|
# if failed/canceled/error:
|
|
|
|
|
# if last-seen is old (1month?3months?)
|
|
|
|
|
# delete entry
|
|
|
|
|
# else (request is running):
|
|
|
|
|
# count:
|
|
|
|
|
# total running
|
|
|
|
|
# total num slots
|
|
|
|
|
# total size of request
|
|
|
|
|
# iter finished: update metrics!
|
|
|
|
|
|
|
|
|
|
|
2025-03-20 15:27:17 +01:00
|
|
|
# without slotFills =? (await c.marketplace.getRecentSlotFillEvents()), err:
|
|
|
|
|
# trace "Unable to get recent slotFill events from chain", err = err.msg
|
|
|
|
|
# return success() # We don't propagate this error.
|
|
|
|
|
# # The call is allowed to fail and the app should continue as normal.
|
2025-03-18 15:54:55 +01:00
|
|
|
|
2025-03-20 15:27:17 +01:00
|
|
|
# c.metrics.setSlotFill(slotFills.len)
|
2025-03-18 15:54:55 +01:00
|
|
|
return success()
|
|
|
|
|
|
|
|
|
|
method start*(c: ChainMetrics): Future[?!void] {.async.} =
|
2025-03-19 15:52:50 +01:00
|
|
|
info "starting..."
|
2025-03-18 15:54:55 +01:00
|
|
|
|
|
|
|
|
proc onStep(): Future[?!void] {.async: (raises: []), gcsafe.} =
|
|
|
|
|
return await c.step()
|
|
|
|
|
|
|
|
|
|
if c.state.config.marketplaceEnable:
|
|
|
|
|
await c.state.whileRunning(onStep, 10.minutes)
|
|
|
|
|
|
|
|
|
|
return success()
|
|
|
|
|
|
|
|
|
|
method stop*(c: ChainMetrics): Future[?!void] {.async.} =
|
|
|
|
|
return success()
|
|
|
|
|
|
|
|
|
|
proc new*(
|
2025-03-18 15:55:58 +01:00
|
|
|
T: type ChainMetrics,
|
|
|
|
|
state: State,
|
|
|
|
|
metrics: Metrics,
|
|
|
|
|
marketplace: MarketplaceService,
|
2025-03-18 15:54:55 +01:00
|
|
|
): ChainMetrics =
|
|
|
|
|
ChainMetrics(state: state, metrics: metrics, marketplace: marketplace)
|