From 66b0128112235c01414cf9916282a2119d7836d5 Mon Sep 17 00:00:00 2001 From: zhu-yuncheng Date: Sat, 23 Dec 2023 18:18:37 +0800 Subject: [PATCH] add connection error catch when connecting prometheus (cherry picked from commit e45aa8ab578a32ed65966ce1cab4e1850a844ecc) --- 0002-add-error-catch-when-connect-pro.patch | 41 +++++++++++++++++++++ aops-vulcanus.spec | 7 +++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 0002-add-error-catch-when-connect-pro.patch diff --git a/0002-add-error-catch-when-connect-pro.patch b/0002-add-error-catch-when-connect-pro.patch new file mode 100644 index 0000000..094c2c9 --- /dev/null +++ b/0002-add-error-catch-when-connect-pro.patch @@ -0,0 +1,41 @@ +From dfd2f38fd34d300448ed9231377fcf4a0be7d367 Mon Sep 17 00:00:00 2001 +From: zhu-yuncheng +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 diff --git a/aops-vulcanus.spec b/aops-vulcanus.spec index 9123a6c..198a0ad 100644 --- a/aops-vulcanus.spec +++ b/aops-vulcanus.spec @@ -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 - v1.3.1-3 +- add Http connection error catch when connecting to prometheus + * Thu Dec 21 2023 wenxin - v1.3.1-2 - add IPV4 validation method to ValidateRules -- Gitee