Skip to content

Commit dd578dc

Browse files
committed
address review comments
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent 44b259a commit dd578dc

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

observer/bin/spark-observer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Sentry from '@sentry/node'
55
import timers from 'node:timers/promises'
66
import { createInflux } from '../lib/telemetry.js'
77
import assert from 'node:assert/strict'
8+
import slug from 'slug'
89

910
import { RPC_URL, rpcHeaders } from '../lib/config.js'
1011
import { getPgPools } from '@filecoin-station/spark-stats-db'
@@ -43,14 +44,15 @@ const loop = async (name, fn, interval) => {
4344
}
4445
const dt = Date.now() - start
4546
console.log(`Loop "${name}" took ${dt}ms`)
46-
recordTelemetry(`loop_${name.replaceAll(' ', '_')}`, point => {
47+
48+
recordTelemetry(`loop_${slug(name, '_')}`, point => {
4749
point.intField('interval_ms', interval)
4850
point.intField('duration_ms', dt)
4951
point.intField('delay_ms', interval - dt)
5052
})
51-
if (dt < interval) {
52-
await timers.setTimeout(interval - dt)
53-
}
53+
54+
// This is safe to do because setTimeout(-10) has the same result as setTimeout(0)
55+
await timers.setTimeout(interval - dt)
5456
}
5557
}
5658

observer/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
"@filecoin-station/spark-stats-db": "^1.0.0",
2020
"@influxdata/influxdb-client": "^1.35.0",
2121
"@sentry/node": "^8.39.0",
22+
"@types/slug": "^5.0.9",
2223
"debug": "^4.3.7",
2324
"ethers": "^6.13.4",
24-
"pg": "^8.13.1"
25+
"pg": "^8.13.1",
26+
"slug": "^10.0.0"
2527
},
2628
"standard": {
2729
"env": [

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)