-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd1273d
commit 4c78c91
Showing
1 changed file
with
22 additions
and
9 deletions.
There are no files selected for viewing
31 changes: 22 additions & 9 deletions
31
tf-managed/modules/snapshot-monitoring/snapshot-age-monitor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
var assert = require('assert'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires -- "approved" methods of resolving this lint do not work in the NR context. | ||
var assert = require("assert"); | ||
|
||
function check_snapshot(url, genesisTime) { | ||
var callback = function (err, response, body) { | ||
assert.equal(response.statusCode, 200, 'Expected a 200 OK response'); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- that's how the callback works in this context. | ||
var callback = function (_err, response, _body) { | ||
assert.equal(response.statusCode, 200, "Expected a 200 OK response"); | ||
|
||
var snapshotName = response.url.split('/').pop(); | ||
var snapshotName = response.url.split("/").pop(); | ||
var height = snapshotName.match(/height_(\d+)/)[1]; | ||
|
||
var currentTime = Math.floor(Date.now() / 1000); | ||
var snapshotTime = height * 30 + genesisTime; | ||
var snapshotAgeInMinutes = (currentTime - snapshotTime) / 60; | ||
|
||
assert(snapshotAgeInMinutes < 360, 'Expected snapshot to be less than 360 minutes old'); | ||
} | ||
assert( | ||
snapshotAgeInMinutes < 360, | ||
"Expected snapshot to be less than 360 minutes old" | ||
); | ||
}; | ||
|
||
$http.head(url, callback) | ||
// This variable is provided by New Relic. | ||
// eslint-disable-next-line no-undef | ||
$http.head(url, callback); | ||
} | ||
|
||
check_snapshot('https://forest-archive.chainsafe.dev/latest/calibnet/', 1667326380) | ||
check_snapshot('https://forest-archive.chainsafe.dev/latest/mainnet/', 1598306400) | ||
check_snapshot( | ||
"https://forest-archive.chainsafe.dev/latest/calibnet/", | ||
1667326380 | ||
); | ||
check_snapshot( | ||
"https://forest-archive.chainsafe.dev/latest/mainnet/", | ||
1598306400 | ||
); |