Compare commits

...

5 commits

Author SHA1 Message Date
Suven-p
ea8f209cab
Merge 6380df93c0 into d7ffa33950 2024-10-20 05:17:08 +00:00
Suven-p
6380df93c0 Fix relative path in test 2024-10-20 11:01:56 +05:45
Suven-p
444661e77c Save message for 503 status code 2024-10-20 10:47:01 +05:45
Suven-p
73ee62810d Bugfix: Add support for base url with path 2024-10-20 09:37:22 +05:45
Suven-p
bf32550f86 Fix linting error 2024-10-20 09:35:13 +05:45
2 changed files with 14 additions and 7 deletions

View file

@ -13,16 +13,20 @@ class RabbitMqMonitorType extends MonitorType {
let baseUrls = [];
try {
baseUrls = JSON.parse(monitor.rabbitmqNodes);
}
catch (error) {
} catch (error) {
throw new Error("Invalid RabbitMQ Nodes");
}
heartbeat.status = DOWN;
for (const baseUrl of baseUrls) {
for (let baseUrl of baseUrls) {
try {
// Without a trailing slash, path in baseUrl will be removed. https://example.com/api -> https://example.com
if ( !baseUrl.endsWith("/") ) {
baseUrl += "/";
}
const options = {
url: new URL("/api/health/checks/alarms", baseUrl).href,
// Do not start with slash, it will strip the trailing slash from baseUrl
url: new URL("api/health/checks/alarms/", baseUrl).href,
method: "get",
timeout: monitor.timeout * 1000,
headers: {
@ -31,7 +35,8 @@ class RabbitMqMonitorType extends MonitorType {
},
// Use axios signal to handle connection timeouts https://stackoverflow.com/a/74739938
signal: axiosAbortSignal((monitor.timeout + 10) * 1000),
validateStatus: () => true,
// Capture reason for 503 status
validateStatus: (status) => status === 200 || status === 503,
};
log.debug("monitor", `[${monitor.name}] Axios Request: ${JSON.stringify(options)}`);
const res = await axios.request(options);
@ -40,6 +45,8 @@ class RabbitMqMonitorType extends MonitorType {
heartbeat.status = UP;
heartbeat.msg = "OK";
break;
} else if (res.status === 503) {
heartbeat.msg = res.data.reason;
} else {
heartbeat.msg = `${res.status} - ${res.statusText}`;
}

View file

@ -1,8 +1,8 @@
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { RabbitMQContainer } = require("@testcontainers/rabbitmq");
const { RabbitMqMonitorType } = require("../../../server/monitor-types/rabbitmq");
const { UP, DOWN, PENDING } = require("../../../src/util");
const { RabbitMqMonitorType } = require("../../server/monitor-types/rabbitmq");
const { UP, DOWN, PENDING } = require("../../src/util");
describe("RabbitMQ Single Node", {
skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),