Skip to content

Commit

Permalink
fixes: fixed per review
Browse files Browse the repository at this point in the history
  • Loading branch information
Igorgro committed Sep 22, 2023
1 parent d6b4e57 commit 5cf2abd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion substrate/substrate-dump/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@subsquid/util-internal-prometheus-server": "^1.2.0",
"@subsquid/util-internal-range": "^0.0.0",
"commander": "^11.0.0",
"prom-client": "14.2.0"
"prom-client": "^14.2.0"
},
"devDependencies": {
"@types/node": "^18.16.17",
Expand Down
7 changes: 5 additions & 2 deletions substrate/substrate-dump/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ export class Dumper {
} else {
const archive = new ArchiveLayout(this.fs())
const prometheus = this.prometheus();
if (this.options.metricsPort) await prometheus.serve();
if (this.options.metricsPort) {
await prometheus.serve();
this.log().info(`prometheus metrics are available on port {port}`)
}
await archive.appendRawBlocks({
blocks: (nextBlock, prevHash) => this.saveMetadata(this.process(nextBlock, prevHash)),
range: this.range(),
chunkSize: this.options.chunkSize * 1024 * 1024,
onSuccessWrite: this.options.metricsPort ? ((block) => { prometheus.setLastSavedBlock(block); }) : undefined
onSuccessWrite: (block) => { prometheus.setLastSavedBlock(block); }
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/substrate-dump/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runProgram(() => {
program.option('--last-block <number>', 'Height of the last block to dump', nat)
program.option('--with-trace [targets]', 'Fetch block trace')
program.option('--chunk-size <MB>', 'Data chunk size in megabytes', positiveInt, 32)
program.option('--metrics-port <port>', 'Port to serve metrics on', positiveInt)
program.option('--metrics-port <port>', 'Port to serve metrics on', nat)

let args = program.parse().opts() as DumperOptions

Expand Down
8 changes: 1 addition & 7 deletions substrate/substrate-dump/src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ export class PrometheusServer {
this.lastSavedBlockGauge.set(block);
}

private getPort(): number | string {
return this.port == null
? process.env.PROMETHEUS_PORT || 0
: this.port
}


serve(): Promise<ListeningServer> {
return createPrometheusServer(this.registry, this.getPort())
return createPrometheusServer(this.registry, this.port)
}
}
5 changes: 3 additions & 2 deletions util/util-internal-archive-layout/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ export class ArchiveLayout {
assertNotNull(lastBlock)
).transactDir('.', async fs => {
let content = await out.end()
args.onSuccessWrite ? args.onSuccessWrite(lastBlock?.height || 0) : null;
return fs.write('blocks.jsonl.gz', content)
const writeResult = fs.write('blocks.jsonl.gz', content)
writeResult.then(() => args.onSuccessWrite ? args.onSuccessWrite(lastBlock?.height || 0) : null)
return writeResult
})
firstBlock = undefined
lastBlock = undefined
Expand Down

0 comments on commit 5cf2abd

Please sign in to comment.