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