add connection error catch when connecting prometheus

(cherry picked from commit e45aa8ab578a32ed65966ce1cab4e1850a844ecc)
This commit is contained in:
zhu-yuncheng 2023-12-23 18:18:37 +08:00 committed by openeuler-sync-bot
parent b28ea577a5
commit 66b0128112
2 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,41 @@
From dfd2f38fd34d300448ed9231377fcf4a0be7d367 Mon Sep 17 00:00:00 2001
From: zhu-yuncheng <zhuyuncheng@huawei.com>
Date: Sat, 23 Dec 2023 17:43:18 +0800
Subject: [PATCH] add httpconnection error catch when connect prometheus
---
vulcanus/database/proxy.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/vulcanus/database/proxy.py b/vulcanus/database/proxy.py
index 94e9883..5753066 100644
--- a/vulcanus/database/proxy.py
+++ b/vulcanus/database/proxy.py
@@ -16,9 +16,9 @@ Author:
Description: Database proxy
"""
from functools import wraps
-import math
from datetime import datetime
from urllib3.exceptions import LocationValueError
+from requests.exceptions import ConnectionError
import sqlalchemy
from sqlalchemy.exc import SQLAlchemyError, DisconnectionError
@@ -543,8 +543,12 @@ class PromDbProxy(DataBaseProxy):
Returns:
bool: connect succeed or fail
"""
-
- return self._prom.check_prometheus_connection()
+ connected = False
+ try:
+ connected = self._prom.check_prometheus_connection()
+ except ConnectionError as error:
+ LOGGER.error(error)
+ return connected
def query(self, host, time_range, metric, label_config=None):
"""
--
Gitee

View File

@ -1,12 +1,12 @@
Name: aops-vulcanus
Version: v1.3.1
Release: 2
Release: 3
Summary: A basic tool libraries of aops, including logging, configure and response, etc.
License: MulanPSL2
URL: https://gitee.com/openeuler/%{name}
Source0: %{name}-%{version}.tar.gz
Patch0001: 0001-update-ValidateRules.patch
Patch0002: 0002-add-error-catch-when-connect-pro.patch
BuildRequires: python3-setuptools
@ -62,6 +62,9 @@ cp -r scripts %{buildroot}/opt/aops/
%changelog
* Sat Dec 23 2023 zhuyuncheng<zhuyuncheng@huawei.com> - v1.3.1-3
- add Http connection error catch when connecting to prometheus
* Thu Dec 21 2023 wenxin<wenxin32@foxmail.com> - v1.3.1-2
- add IPV4 validation method to ValidateRules