fix python3-prometheus-api-client import error
This commit is contained in:
parent
731461b6ef
commit
f6ed870d95
134
0006-fix-python3-prometheus-api-client-import-error.patch
Normal file
134
0006-fix-python3-prometheus-api-client-import-error.patch
Normal file
@ -0,0 +1,134 @@
|
||||
From 53cbfd342bcc39a98f0be257a70fefde3fe404eb Mon Sep 17 00:00:00 2001
|
||||
From: gongzt <gong_zhengtang@163.com>
|
||||
Date: Wed, 18 Oct 2023 17:22:26 +0800
|
||||
Subject: fix python3-prometheus-api-client import error
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
---
|
||||
vulcanus/database/proxy.py | 101 -------------------------------------
|
||||
1 file changed, 101 deletions(-)
|
||||
|
||||
diff --git a/vulcanus/database/proxy.py b/vulcanus/database/proxy.py
|
||||
index 94e9883..c1ff0fe 100644
|
||||
--- a/vulcanus/database/proxy.py
|
||||
+++ b/vulcanus/database/proxy.py
|
||||
@@ -24,7 +24,6 @@ import sqlalchemy
|
||||
from sqlalchemy.exc import SQLAlchemyError, DisconnectionError
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from elasticsearch import Elasticsearch, ElasticsearchException, helpers, TransportError, NotFoundError
|
||||
-from prometheus_api_client import PrometheusConnect, PrometheusApiClientException
|
||||
import redis
|
||||
from redis import Redis, ConnectionPool
|
||||
from vulcanus.log.log import LOGGER
|
||||
@@ -516,106 +515,6 @@ class ElasticsearchProxy(DataBaseProxy):
|
||||
return query_body
|
||||
|
||||
|
||||
-class PromDbProxy(DataBaseProxy):
|
||||
- """
|
||||
- Proxy of prometheus time series database
|
||||
- """
|
||||
-
|
||||
- def __init__(self, host=None, port=None):
|
||||
- """
|
||||
- Init Prometheus time series database proxy
|
||||
-
|
||||
- Args:
|
||||
- host (str)
|
||||
- port (int)
|
||||
- """
|
||||
- self._host = host or configuration.prometheus.get('IP')
|
||||
- self._port = port or configuration.prometheus.get('PORT')
|
||||
- self._prom = PrometheusConnect(url="http://%s:%s" % (self._host, self._port), disable_ssl=True)
|
||||
- if not self.connected:
|
||||
- raise DatabaseConnectionFailed("Promethus connection failed.")
|
||||
-
|
||||
- @property
|
||||
- def connected(self):
|
||||
- """
|
||||
- Make a connect to database connection pool
|
||||
-
|
||||
- Returns:
|
||||
- bool: connect succeed or fail
|
||||
- """
|
||||
-
|
||||
- return self._prom.check_prometheus_connection()
|
||||
-
|
||||
- def query(self, host, time_range, metric, label_config=None):
|
||||
- """
|
||||
- query a metric's data of a host during a time range
|
||||
- Args:
|
||||
- host (str): host ip
|
||||
- time_range (list): list of datetime.datetime
|
||||
- metric (str): data type of prometheus
|
||||
- label_config (dict): label config of metric
|
||||
-
|
||||
- Returns:
|
||||
- tuple: (bool, dict)
|
||||
- """
|
||||
- start_time = datetime.fromtimestamp(time_range[0])
|
||||
- end_time = datetime.fromtimestamp(time_range[1])
|
||||
-
|
||||
- # metric of a host's all exporters
|
||||
- # e.g. metric "up" of localhost: up{instance=127.0.0.1\\d{1,5}}
|
||||
- host_condition = 'instance=~"%s:\\\\d{1,5}"' % host
|
||||
- combined_condition = PromDbProxy._combine_condition(label_config, host_condition)
|
||||
-
|
||||
- metric_with_condition = metric + combined_condition
|
||||
-
|
||||
- try:
|
||||
- data = self._prom.get_metric_range_data(
|
||||
- metric_name=metric_with_condition,
|
||||
- start_time=start_time,
|
||||
- end_time=end_time,
|
||||
- )
|
||||
-
|
||||
- if not data:
|
||||
- LOGGER.warning(
|
||||
- "Query result is empty. Exporter of host %s doesn't record the " "metric '%s' during [%s, %s].",
|
||||
- host,
|
||||
- metric,
|
||||
- start_time,
|
||||
- end_time,
|
||||
- )
|
||||
-
|
||||
- return True, data
|
||||
-
|
||||
- except (ValueError, TypeError, PrometheusApiClientException) as error:
|
||||
- LOGGER.error("Prometheus query failed. %s", error)
|
||||
- failed_item = {
|
||||
- "host_id": host,
|
||||
- "name": metric,
|
||||
- "label": label_config,
|
||||
- }
|
||||
- return False, [failed_item]
|
||||
-
|
||||
- @staticmethod
|
||||
- def _combine_condition(label_config, *args):
|
||||
- """
|
||||
- Combine condition together
|
||||
- Args:
|
||||
- label_config: label config of metric
|
||||
- *args (str/list): one or multiple string of condition
|
||||
-
|
||||
- Returns:
|
||||
- str
|
||||
- """
|
||||
- condition_list = list(args)
|
||||
-
|
||||
- if label_config:
|
||||
- for key, value in label_config.items():
|
||||
- condition_list.append(str(key) + "=" + '"' + value + '"')
|
||||
-
|
||||
- combined_condition = "{" + ",".join(condition_list) + "}"
|
||||
- return combined_condition
|
||||
-
|
||||
-
|
||||
@singleton
|
||||
class RedisProxy(DataBaseProxy):
|
||||
"""
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -10,12 +10,13 @@ Patch0002: 0002-fix-systemctl-startup-service-error.patch
|
||||
Patch0003: 0003-update-aops-basedatabase.patch
|
||||
Patch0004: 0004-fix-information-path-incorrect.patch
|
||||
Patch0005: 0005-suitable-for-version-2003-sp3.patch
|
||||
Patch0006: 0006-fix-python3-prometheus-api-client-import-error.patch
|
||||
|
||||
|
||||
BuildRequires: python3-setuptools
|
||||
Requires: python3-concurrent-log-handler python3-xmltodict python3-pyyaml python3-marshmallow >= 3.13.0
|
||||
Requires: python3-requests python3-xlrd python3-prettytable python3-pygments python3-sqlalchemy
|
||||
Requires: python3-elasticsearch >= 7 python3-prometheus-api-client python3-urllib3 python3-werkzeug
|
||||
Requires: python3-elasticsearch >= 7 python3-urllib3 python3-werkzeug
|
||||
Requires: python3-flask python3-flask-restful python3-PyMySQL python3-kafka-python
|
||||
Requires: python-jwt python3-redis
|
||||
Provides: aops-vulcanus
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user