Skip to content

Commit

Permalink
feat(#525): Add prom metrics for price oracles, fix distributor oracl…
Browse files Browse the repository at this point in the history
…e total rewards metric (#528)

* feat(#525): Add prom metrics for price oracles, fix distributor oracle total rewards metric

* Fix locks
  • Loading branch information
ChewingGlass authored Dec 27, 2023
1 parent 47e142e commit 13a5cb8
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 375 deletions.
54 changes: 0 additions & 54 deletions packages/crons/yarn.deploy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ __metadata:
cors: ^2.8.5
dotenv: ^16.0.3
fastify: ^4.13.0
fastify-cron: ^1.3.1
git-format-staged: ^2.1.3
ky: ^0.31.4
nodemon: ^2.0.20
Expand Down Expand Up @@ -835,15 +834,6 @@ __metadata:
languageName: node
linkType: hard

"@types/cron@npm:^2.0.0":
version: 2.4.0
resolution: "@types/cron@npm:2.4.0"
dependencies:
cron: "npm:*"
checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc
languageName: node
linkType: hard

"@types/crypto-js@npm:^4.1.1":
version: 4.1.1
resolution: "@types/crypto-js@npm:4.1.1"
Expand Down Expand Up @@ -898,13 +888,6 @@ __metadata:
languageName: node
linkType: hard

"@types/luxon@npm:~3.3.0":
version: 3.3.2
resolution: "@types/luxon@npm:3.3.2"
checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8
languageName: node
linkType: hard

"@types/mime@npm:*":
version: 3.0.1
resolution: "@types/mime@npm:3.0.1"
Expand Down Expand Up @@ -1623,16 +1606,6 @@ __metadata:
languageName: node
linkType: hard

"cron@npm:*, cron@npm:^2.0.0":
version: 2.4.3
resolution: "cron@npm:2.4.3"
dependencies:
"@types/luxon": "npm:~3.3.0"
luxon: "npm:~3.3.0"
checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.8
resolution: "cross-fetch@npm:3.1.8"
Expand Down Expand Up @@ -1931,26 +1904,6 @@ __metadata:
languageName: node
linkType: hard

"fastify-cron@npm:^1.3.1":
version: 1.3.1
resolution: "fastify-cron@npm:1.3.1"
dependencies:
"@types/cron": "npm:^2.0.0"
cron: "npm:^2.0.0"
fastify-plugin: "npm:^3.0.0"
peerDependencies:
fastify: ^4.1.0
checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9
languageName: node
linkType: hard

"fastify-plugin@npm:^3.0.0":
version: 3.0.1
resolution: "fastify-plugin@npm:3.0.1"
checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374
languageName: node
linkType: hard

"fastify-plugin@npm:^4.0.0":
version: 4.5.1
resolution: "fastify-plugin@npm:4.5.1"
Expand Down Expand Up @@ -2624,13 +2577,6 @@ __metadata:
languageName: node
linkType: hard

"luxon@npm:~3.3.0":
version: 3.3.0
resolution: "luxon@npm:3.3.0"
checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187
languageName: node
linkType: hard

"make-error@npm:^1.1.1":
version: 1.3.6
resolution: "make-error@npm:1.3.6"
Expand Down
1 change: 0 additions & 1 deletion packages/distributor-oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"fastify": "^4.13.0",
"fastify-cron": "^1.3.1",
"ky": "^0.31.4",
"pg": "^8.9.0",
"prom-client": "^15.0.0",
Expand Down
28 changes: 12 additions & 16 deletions packages/distributor-oracle/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dotenv from "dotenv";
import fastifyCron from "fastify-cron";
dotenv.config();
// @ts-ignore
import {
Expand Down Expand Up @@ -195,22 +194,19 @@ export class OracleServer {
server.get("/health", async () => {
return { ok: true };
});
server.register(fastifyCron, {
jobs: [
{
cronTime: "0 * * * *",
runOnInit: true,
onTick: async () => {
console.log("Updating total rewards");
const rewards = toNumber(new BN(await db.getTotalRewards()), 6);
totalRewardsGauge
.labels(DNT.toBase58())
.set(Number(rewards));
},
},
],
});
let lastCall = 0;
async function getTotalRewards() {
const currTs = new Date().valueOf();
// Only update once every 10m
if (currTs - lastCall > 10 * 60 * 1000) {
console.log("Updating total rewards");
const rewards = toNumber(new BN(await db.getTotalRewards()), 6);
totalRewardsGauge.labels(DNT.toBase58()).set(Number(rewards));
lastCall = currTs;
}
}
server.get("/metrics", async (request, reply) => {
await getTotalRewards();
return register.metrics();
});

Expand Down
54 changes: 0 additions & 54 deletions packages/distributor-oracle/yarn.deploy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ __metadata:
cors: ^2.8.5
dotenv: ^16.0.3
fastify: ^4.13.0
fastify-cron: ^1.3.1
git-format-staged: ^2.1.3
ky: ^0.31.4
nodemon: ^2.0.20
Expand Down Expand Up @@ -694,15 +693,6 @@ __metadata:
languageName: node
linkType: hard

"@types/cron@npm:^2.0.0":
version: 2.4.0
resolution: "@types/cron@npm:2.4.0"
dependencies:
cron: "npm:*"
checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc
languageName: node
linkType: hard

"@types/crypto-js@npm:^4.1.1":
version: 4.1.1
resolution: "@types/crypto-js@npm:4.1.1"
Expand Down Expand Up @@ -757,13 +747,6 @@ __metadata:
languageName: node
linkType: hard

"@types/luxon@npm:~3.3.0":
version: 3.3.2
resolution: "@types/luxon@npm:3.3.2"
checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8
languageName: node
linkType: hard

"@types/mime@npm:*":
version: 3.0.1
resolution: "@types/mime@npm:3.0.1"
Expand Down Expand Up @@ -1455,16 +1438,6 @@ __metadata:
languageName: node
linkType: hard

"cron@npm:*, cron@npm:^2.0.0":
version: 2.4.3
resolution: "cron@npm:2.4.3"
dependencies:
"@types/luxon": "npm:~3.3.0"
luxon: "npm:~3.3.0"
checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.8
resolution: "cross-fetch@npm:3.1.8"
Expand Down Expand Up @@ -1756,26 +1729,6 @@ __metadata:
languageName: node
linkType: hard

"fastify-cron@npm:^1.3.1":
version: 1.3.1
resolution: "fastify-cron@npm:1.3.1"
dependencies:
"@types/cron": "npm:^2.0.0"
cron: "npm:^2.0.0"
fastify-plugin: "npm:^3.0.0"
peerDependencies:
fastify: ^4.1.0
checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9
languageName: node
linkType: hard

"fastify-plugin@npm:^3.0.0":
version: 3.0.1
resolution: "fastify-plugin@npm:3.0.1"
checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374
languageName: node
linkType: hard

"fastify-plugin@npm:^4.0.0":
version: 4.5.1
resolution: "fastify-plugin@npm:4.5.1"
Expand Down Expand Up @@ -2442,13 +2395,6 @@ __metadata:
languageName: node
linkType: hard

"luxon@npm:~3.3.0":
version: 3.3.0
resolution: "luxon@npm:3.3.0"
checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187
languageName: node
linkType: hard

"make-error@npm:^1.1.1":
version: 1.3.6
resolution: "make-error@npm:1.3.6"
Expand Down
54 changes: 0 additions & 54 deletions packages/helium-admin-cli/yarn.deploy.lock
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ __metadata:
cors: ^2.8.5
dotenv: ^16.0.3
fastify: ^4.13.0
fastify-cron: ^1.3.1
git-format-staged: ^2.1.3
ky: ^0.31.4
nodemon: ^2.0.20
Expand Down Expand Up @@ -881,15 +880,6 @@ __metadata:
languageName: node
linkType: hard

"@types/cron@npm:^2.0.0":
version: 2.4.0
resolution: "@types/cron@npm:2.4.0"
dependencies:
cron: "npm:*"
checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc
languageName: node
linkType: hard

"@types/crypto-js@npm:^4.1.1":
version: 4.1.1
resolution: "@types/crypto-js@npm:4.1.1"
Expand Down Expand Up @@ -944,13 +934,6 @@ __metadata:
languageName: node
linkType: hard

"@types/luxon@npm:~3.3.0":
version: 3.3.2
resolution: "@types/luxon@npm:3.3.2"
checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8
languageName: node
linkType: hard

"@types/mime@npm:*":
version: 3.0.1
resolution: "@types/mime@npm:3.0.1"
Expand Down Expand Up @@ -1704,16 +1687,6 @@ __metadata:
languageName: node
linkType: hard

"cron@npm:*, cron@npm:^2.0.0":
version: 2.4.3
resolution: "cron@npm:2.4.3"
dependencies:
"@types/luxon": "npm:~3.3.0"
luxon: "npm:~3.3.0"
checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.8
resolution: "cross-fetch@npm:3.1.8"
Expand Down Expand Up @@ -2012,26 +1985,6 @@ __metadata:
languageName: node
linkType: hard

"fastify-cron@npm:^1.3.1":
version: 1.3.1
resolution: "fastify-cron@npm:1.3.1"
dependencies:
"@types/cron": "npm:^2.0.0"
cron: "npm:^2.0.0"
fastify-plugin: "npm:^3.0.0"
peerDependencies:
fastify: ^4.1.0
checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9
languageName: node
linkType: hard

"fastify-plugin@npm:^3.0.0":
version: 3.0.1
resolution: "fastify-plugin@npm:3.0.1"
checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374
languageName: node
linkType: hard

"fastify-plugin@npm:^4.0.0":
version: 4.5.1
resolution: "fastify-plugin@npm:4.5.1"
Expand Down Expand Up @@ -2732,13 +2685,6 @@ __metadata:
languageName: node
linkType: hard

"luxon@npm:~3.3.0":
version: 3.3.0
resolution: "luxon@npm:3.3.0"
checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187
languageName: node
linkType: hard

"make-error@npm:^1.1.1":
version: 1.3.6
resolution: "make-error@npm:1.3.6"
Expand Down
Loading

0 comments on commit 13a5cb8

Please sign in to comment.