Skip to content

Commit

Permalink
Adding temp fix (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
kev306 authored Jul 2, 2024
1 parent 146b62f commit 54fcaf3
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/clients/victoriaMetrics/promAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,41 @@ export class PromAgent {
process.exit(1);
}

const response = await fetch(process.env.VM_IMPORT_PROMETHEUS_URL, {
method: 'POST',
body: metrics,
headers: {
'Content-Type': 'text/plain',
},
});

if (!response.ok) {
const errMsg = `Failed to push metrics: status=${response.status} text=${response.statusText}`;
console.error(errMsg);

// Alert Discord while errors are less than MAX_PUSH_METRICS_ERRORS
const now = Date.now();
this.pushMetricsErrorsTimestamps.push(now);

while (this.pushMetricsErrorsTimestamps.length > 0) {
const timeDiff = now - this.pushMetricsErrorsTimestamps[0];

if (timeDiff > FORGET_ERROR_TIME_THRESHOLD) {
this.pushMetricsErrorsTimestamps.unshift();
} else {
break;
try {
const response = await fetch(process.env.VM_IMPORT_PROMETHEUS_URL, {
method: 'POST',
body: metrics,
headers: {
'Content-Type': 'text/plain',
},
});

if (!response.ok) {
const errMsg = `Failed to push metrics: status=${response.status} text=${response.statusText}`;
console.error(errMsg);

// Alert Discord while errors are less than MAX_PUSH_METRICS_ERRORS
const now = Date.now();
this.pushMetricsErrorsTimestamps.push(now);

while (this.pushMetricsErrorsTimestamps.length > 0) {
const timeDiff = now - this.pushMetricsErrorsTimestamps[0];

if (timeDiff > FORGET_ERROR_TIME_THRESHOLD) {
this.pushMetricsErrorsTimestamps.unshift();
} else {
break;
}
}
}

if (this.pushMetricsErrorsTimestamps.length <= MAX_PUSH_METRICS_ERRORS) {
sendToDiscordAdmins(errMsg);
if (
this.pushMetricsErrorsTimestamps.length <= MAX_PUSH_METRICS_ERRORS
) {
sendToDiscordAdmins(errMsg);
}
}
} catch (e) {
return;
}
}
}
Expand Down

0 comments on commit 54fcaf3

Please sign in to comment.