Skip to content

Commit 256f5f3

Browse files
committed
Add auto-restart to QA subgraph
1 parent c70e58b commit 256f5f3

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

scripts/status.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const miningABI = require('./abis/IReputationMiningCycle.json');
3535

3636
let ongoingGenericIncident = false;
3737
let ongoingGraphIncident = false;
38+
let ongoingQAIncident = false;
3839

3940
module.exports = robot => {
4041
const { brain, messageChannel } = robot
@@ -54,6 +55,11 @@ module.exports = robot => {
5455
let message = ""
5556
// Get latest block from graph
5657
const graphNumberRes = getGraphLatestBlock("https://xdai.colony.io/graph/subgraphs/name/joinColony/subgraph")
58+
59+
// Get latest block from QA graph
60+
61+
const qaGraphNumberRes = getGraphLatestBlock("http://thegraph-query-red-network-100:8000/subgraphs/name/joinColony/subgraph")
62+
5763
// Get latest block from blockscout
5864
const blockscoutRes = fetch("https://blockscout.com/xdai/mainnet/api?module=block&action=eth_block_number")
5965

@@ -99,7 +105,7 @@ module.exports = robot => {
99105
})
100106
})
101107

102-
const [graphNumber, blockScoutBlock, RPCBlock, balance, xdaichainRpcBlock] = await Promise.all([graphNumberRes, blockscoutRes, rpcRes, balanceRes, xdaichainRpcRes])
108+
const [graphNumber, qaGraphNumber, blockScoutBlock, RPCBlock, balance, xdaichainRpcBlock] = await Promise.all([graphNumberRes, qaGraphNumberRes, blockscoutRes, rpcRes, balanceRes, xdaichainRpcRes])
103109

104110
output = await blockScoutBlock.json()
105111
const blockscoutLatestBlock = parseInt(output.result,16)
@@ -145,6 +151,34 @@ module.exports = robot => {
145151
}
146152
}
147153

154+
// QA Graph latest block
155+
smallestQAGraphDiscrepancy = Math.min(
156+
Math.abs(qaGraphNumber-blockscoutLatestBlock),
157+
Math.abs(qaGraphNumber-xdaichainLatestBlock)
158+
)
159+
160+
if ((blockscoutLatestBlock - qaGraphNumber) >= 48 && !ongoingQAIncident){
161+
ongoingQAIncident = true;
162+
try { // Try and restart the qa graph digest pod
163+
// By the time this happens, the deployments script should have authed us
164+
// QA colour is red
165+
const colour = "red"
166+
// Get production graph digest node
167+
res = await exec(`kubectl get pods --sort-by=.metadata.creationTimestamp | grep digest-${colour} | tail -n1 | awk '{print $1}' | tr -d '\n'`)
168+
const qaGraphDigest = res.stdout;
169+
// delete it
170+
await exec(`kubectl delete pod ${qaGraphDigest}`)
171+
await channel.send(`**Attempted to restart QA subgraph as it appeared ${smallestQAGraphDiscrepancy} blocks behind.**`)
172+
} catch (err) {
173+
console.log(err)
174+
await channel.send("**Attempted restart of QA graph failed - check logs.**\n")
175+
}
176+
} else if ((blockscoutLatestBlock - qaGraphNumber) < 48 && ongoingQAIncident){
177+
ongoingQAIncident = false;
178+
await channel.send(`QA subgraph appears fixed`)
179+
}
180+
181+
148182
// Miner balance
149183

150184
output = await balance.json()

0 commit comments

Comments
 (0)