Skip to content

Commit

Permalink
bound metrics chain height with request range
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Dec 31, 2024
1 parent 8b367b3 commit 5769f61
Showing 1 changed file with 18 additions and 3 deletions.
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'
}

0 comments on commit 5769f61

Please sign in to comment.