Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: improve processor metrics #363

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal-processor-tools",
"comment": "bound processor metrics chain height with request range",
"type": "patch"
},
{
"packageName": "@subsquid/util-internal-processor-tools",
"comment": "allow to disable processor exit",
"type": "minor"
}
],
"packageName": "@subsquid/util-internal-processor-tools"
}
21 changes: 18 additions & 3 deletions util/util-internal-processor-tools/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Runner<R, S> {
if (this.getLeftRequests(state).length == 0) {
this.printProcessingRange()
log.info('nothing to do')
return
return this.exit()
}

this.printProcessingMessage(state)
Expand Down Expand Up @@ -110,9 +110,11 @@ export class Runner<R, S> {
state = nextState
}

return this.processHotBlocks(state).finally(
await this.processHotBlocks(state).finally(
this.chainHeightUpdateLoop(hot)
)

return this.exit()
}

private async assertWeAreOnTheSameChain(src: DataSource<unknown, unknown>, state: HashAndHeight): Promise<void> {
Expand Down Expand Up @@ -306,7 +308,8 @@ export class Runner<R, S> {

private async initMetrics(chainHeight: number, state: HotDatabaseState): Promise<void> {
let initialized = this.metrics.getChainHeight() >= 0
this.metrics.setChainHeight(chainHeight)
let boundedChainHeight = Math.min(chainHeight, rangeEnd(last(this.config.requests).range))
this.metrics.setChainHeight(boundedChainHeight)
if (initialized) return
this.metrics.setLastProcessedBlock(state.height + state.top.length)
this.metrics.updateProgress()
Expand Down Expand Up @@ -343,6 +346,14 @@ export class Runner<R, S> {
this.log.info(msg)
}

private async exit(): Promise<void> {
if (isProcessorExitDisabled()) {
while (true) {
await wait(5000)
}
}
}

@def
private async startPrometheusServer(): Promise<void> {
let prometheusServer = await this.config.prometheus.serve()
Expand All @@ -353,3 +364,7 @@ export class Runner<R, S> {
return this.config.log
}
}

function isProcessorExitDisabled() {
return process.env.SQUID_PROCESSOR_EXIT_DISABLED === 'true'
}
Loading