I have a page that displays all cache keys for a running instance (both in-memory cache as well as SQLite cache) and I’d like to be able to specify which instance’s caches I want to look at. To do this I need the instance hostname. Is it possible for my app to query fly for all running instance hostnames of itself?
- Retrieve
alloc-id
s of an app: Feature request: list of running ALLOC_IDs via DNS - #2 by charsleysa - Address them: Fly Apps on machines: prerelease of fly deploy - #8 by kurt
Thanks, but I have no idea what to do with this information
Sorry, I should have linked to sample code. Here’s one in JavaScript: https://github.com/fly-apps/privatenet/blob/cfe81768d3/lookup.js#L61-L73
In your case, you’d want to:
resolveTxt
onvms.<app-name>.internal
- Split on
,
and retrievealloc-id
s resolve6
thosealloc-id
s:<alloc-id>.vm.<app-name>.internal
I’m typing the below on mobile, so it won’t be accurate:
// step 1
async function getAllocIds(appname) {
let recs = null;
try {
recs = await dns.promises.resolveTxt(`vms.${appname}.internal`)
} catch (err) {
console.error(err);
}
if (rec == null) return [];
// step 2; may be incorrect...
const ids = recs.map(r => r.split(",")).map(vm => vm.split(" ")[0]);
return ids;
};
// step 3
async function resolve(appname, allocids) {
const ips = new Array(allocids.length);
Arrays.fill(ips, "");
for (const i in allocids) {
const id = allocids[i];
try {
const ans = await dns.promises.resolve6(`${id}.vm.${appname}.internal`));
if (ans == null || ans.length <=0) continue;
else ips[i] = ans[0];
} catch (err) {
console.log(err);
continue;
}
}
return ips;
};
That helped a lot! Thank you.
I don’t need to resolve to IP addresses myself, so here’s my solution: kentcdodds.com/fly.server.ts at 96db2a79158809f09dda50aa15d0b34982958047 · kentcdodds/kentcdodds.com · GitHub
And here’s the first place I’m using this: kentcdodds.com/cache.admin.tsx at 96db2a79158809f09dda50aa15d0b34982958047 · kentcdodds/kentcdodds.com · GitHub
You can watch me build this here: Coding with Kent: Multi-region instance management - YouTube (see me use the feature I’m building this for here: Coding with Kent: Multi-region instance management - YouTube, basically, it allows me to inspect the cache for a specific instance).
Thanks again.