Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Disable voyager when running on Saturn node #3

Merged
merged 3 commits into from
Mar 12, 2024
Merged
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
41 changes: 39 additions & 2 deletions voyager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ new BasicTracerProvider().register()
Zinnia.activity.info('Voyager benchmarking started')

export async function runSaturnBenchmarkInterval() {
let runningOnSaturnNode = false
try {
runningOnSaturnNode = await isRunningOnSaturnNode()
} catch (err) {
console.error(
'Could not check if running on Saturn node',
{ cause: err }
)
}
if (runningOnSaturnNode) {
console.log('Running on Saturn host, skipping benchmark')
} else {
await runSaturnBenchmark()
}
console.log('Sleeping for 60s...')
setTimeout(runSaturnBenchmarkInterval, 1000 * 60)
}

async function runSaturnBenchmark() {
const random = Math.random()
if (random <= prodOpts.sampleRate) {
console.log('Running prod benchmark...')
Expand All @@ -66,8 +85,26 @@ export async function runSaturnBenchmarkInterval() {
}
Zinnia.jobCompleted()
}
console.log('Sleeping for 60s...')
setTimeout(runSaturnBenchmarkInterval, 1000 * 60)
}

async function getPublicIPv4Address () {
// TODO Replace with Voyager API once available
const res = await fetch(`https://api.filspark.com/inspect-request`)
const { cloudflareAddr: ip } = await res.json()
return ip
}

async function isRunningOnSaturnNode () {
const ip = await getPublicIPv4Address()
const subdomain = ip.replaceAll('.', '-')
try {
await fetch(`https://${subdomain}.l1s.saturn.ms/`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is enough, at least for now, but I want @hannahhoward to double check my reasoning that if this returns anything at all there is a Saturn node running on the given IP - couldn't think of any cases where that wouldn't be true (aside from maybe some node startup/shutdown edge cases that probably aren't worth worrying about right now?) but also worth noting that I'm still feeling my way around the Saturn codebase so might be missing something!

This definitely seems worth shipping now in any case - we can refine as we go!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's merge if there is pressure to do so, otherwise wait for @hannahhoward's review?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's totally fine to wait, this isn't "need it today" urgent as far as I know!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we tested this against an actual saturn node to verify it accepts an HTTP connection at root?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this doesn't end up working, you can definitely use /ipfs with the health check cid -- https://github.com/filecoin-saturn/orchestrator/blob/651e34809ac02cf174f6fa9444524b8624132b1c/src/cron/health-check.js#L26

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this with an actual Saturn node, and it worked 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the root address, it will redirect to saturn.ms, so it's a good http response code

redirect: 'manual'
})
return true
} catch {
return false
}
}

export async function runBenchmark(saturn) {
Expand Down