2.0.2-3 loki-storage support: handle 504, adjust log level/logging/notes

pull/1061/head
Ryan Tharp 5 years ago
parent f9baac91a1
commit bee436ebbb

@ -195,7 +195,8 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => {
let snodePool = await lokiSnodeAPI.getRandomSnodePool(); let snodePool = await lokiSnodeAPI.getRandomSnodePool();
if (snodePool.length < 2) { if (snodePool.length < 2) {
log.error( // this is semi-normal to happen
log.info(
'lokiRpc::sendToProxy - Not enough service nodes for a proxy request, only have:', 'lokiRpc::sendToProxy - Not enough service nodes for a proxy request, only have:',
snodePool.length, snodePool.length,
'snode, attempting refresh' 'snode, attempting refresh'
@ -277,7 +278,33 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => {
return sendToProxy(options, targetNode, retryNumber + 1); return sendToProxy(options, targetNode, retryNumber + 1);
} }
// relay is fine but destination is not good
if (response.status === 504) {
const pRetryNumber = retryNumber + 1;
if (pRetryNumber > 3) {
log.warn(
`lokiRpc:::sendToProxy - snode ${randSnode.ip}:${randSnode.port}`,
`can not relay to target node ${targetNode.ip}:${targetNode.port}`,
`after 3 retries`
);
if (options.ourPubKey) {
lokiSnodeAPI.unreachableNode(options.ourPubKey, targetNode);
} else {
console.trace('no ourPubKey in call')
}
return false;
}
// we don't have to wait here
// because we're not marking the random snode bad
// grab a fresh random one
return sendToProxy(options, targetNode, pRetryNumber);
}
// detect SNode is not ready (not in swarm; not done syncing) // detect SNode is not ready (not in swarm; not done syncing)
// 503 can be proxy target or destination in pre 2.0.3
// 2.0.3 and after means target
if (response.status === 503 || response.status === 500) { if (response.status === 503 || response.status === 500) {
// this doesn't mean the random node is bad, it could be the target node // this doesn't mean the random node is bad, it could be the target node
// but we got a ton of randomPool nodes, let's just not worry about this one // but we got a ton of randomPool nodes, let's just not worry about this one
@ -390,7 +417,7 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => {
return JSON.parse(jsonRes.body); return JSON.parse(jsonRes.body);
} catch (e) { } catch (e) {
log.error( log.error(
'lokiRpc:::sendToProxy - parse error', 'lokiRpc:::sendToProxy - (inner) parse error',
e.code, e.code,
e.message, e.message,
`from ${randSnode.ip}:${randSnode.port} json:`, `from ${randSnode.ip}:${randSnode.port} json:`,
@ -400,7 +427,7 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => {
return false; return false;
}; };
if (retryNumber) { if (retryNumber) {
log.info( log.debug(
`lokiRpc:::sendToProxy - request succeeded,`, `lokiRpc:::sendToProxy - request succeeded,`,
`snode ${randSnode.ip}:${randSnode.port} to ${targetNode.ip}:${ `snode ${randSnode.ip}:${randSnode.port} to ${targetNode.ip}:${
targetNode.port targetNode.port
@ -411,7 +438,7 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => {
return jsonRes; return jsonRes;
} catch (e) { } catch (e) {
log.error( log.error(
'lokiRpc:::sendToProxy - parse error', 'lokiRpc:::sendToProxy - (outer) parse error',
e.code, e.code,
e.message, e.message,
`from ${randSnode.ip}:${randSnode.port} json:`, `from ${randSnode.ip}:${randSnode.port} json:`,
@ -475,12 +502,19 @@ const lokiFetch = async (url, options = {}, targetNode = null) => {
const result = await sendToProxy(fetchOptions, targetNode); const result = await sendToProxy(fetchOptions, targetNode);
if (result === false) { if (result === false) {
// should we retry? // should we retry?
log.warn(`lokiRpc:::lokiFetch - sendToProxy returned false`);
// even though we can't be sure our caller is going to log or handle the failure
// we do know that sendToProxy should be logging
// so I don't think we need or want a log item here...
// log.warn(`lokiRpc:::lokiFetch - sendToProxy failed`);
// one case is: // one case is:
// snodePool didn't have enough // snodePool didn't have enough
// even after a refresh // even after a refresh
// likely a network disconnect? // likely a network disconnect?
// but not all cases... // another is:
// failure to send to target node after 3 retries
// what else?
/* /*
log.warn( log.warn(
'lokiRpc:::lokiFetch - useSnodeProxy failure, could not refresh randomPool, offline?' 'lokiRpc:::lokiFetch - useSnodeProxy failure, could not refresh randomPool, offline?'
@ -498,7 +532,7 @@ const lokiFetch = async (url, options = {}, targetNode = null) => {
fetchOptions.agent = snodeHttpsAgent; fetchOptions.agent = snodeHttpsAgent;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
} else { } else {
log.info('lokirpc:::lokiFetch - http communication', url); log.debug('lokirpc:::lokiFetch - http communication', url);
} }
const response = await nodeFetch(url, fetchOptions); const response = await nodeFetch(url, fetchOptions);
// restore TLS checking // restore TLS checking

Loading…
Cancel
Save