2
This commit is contained in:
@@ -39,13 +39,27 @@ function createClient(baseUrl) {
|
|||||||
async function testConnection(url) {
|
async function testConnection(url) {
|
||||||
const normalized = normalizeUrl(url);
|
const normalized = normalizeUrl(url);
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${normalized}/api/v1/status/buildinfo`, {
|
// Using native fetch to avoid follow-redirects/axios "protocol mismatch" issues in some Node environments
|
||||||
timeout: QUERY_TIMEOUT,
|
const controller = new AbortController();
|
||||||
httpAgent,
|
const timer = setTimeout(() => controller.abort(), QUERY_TIMEOUT);
|
||||||
httpsAgent
|
|
||||||
|
// Node native fetch - handles http/https automatically
|
||||||
|
const res = await fetch(`${normalized}/api/v1/status/buildinfo`, {
|
||||||
|
signal: controller.signal
|
||||||
});
|
});
|
||||||
return res.data?.data?.version || 'unknown';
|
|
||||||
|
clearTimeout(timer);
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Prometheus returned HTTP ${res.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
return data?.data?.version || 'unknown';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.name === 'AbortError') {
|
||||||
|
throw new Error('Connection timed out');
|
||||||
|
}
|
||||||
console.error(`[Prometheus] Connection test failed for ${normalized}:`, err.message);
|
console.error(`[Prometheus] Connection test failed for ${normalized}:`, err.message);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user