Upgrade influxdb python from 2.3.0 to 2.8.0
Upgrade pbr. Change-Id: I3b452df88de4994fa46a9f30ea56a1e62de6bdf1
This commit is contained in:
parent
ff76745469
commit
baf70daaef
|
@ -16,12 +16,15 @@
|
|||
import json
|
||||
|
||||
from influxdb import client
|
||||
from influxdb.exceptions import InfluxDBClientError
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from monasca_api.common.repositories import exceptions
|
||||
from monasca_api.common.repositories import metrics_repository
|
||||
|
||||
MEASUREMENT_NOT_FOUND_MSG = "measurement not found"
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -173,11 +176,11 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
if not series_names:
|
||||
return json_metric_list
|
||||
|
||||
if 'series' in series_names.raw['results'][0]:
|
||||
if 'series' in series_names.raw:
|
||||
|
||||
id = 0
|
||||
|
||||
for series in series_names.raw['results'][0]['series']:
|
||||
for series in series_names.raw['series']:
|
||||
|
||||
for tag_values in series[u'values']:
|
||||
|
||||
|
@ -203,11 +206,11 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
if not series_names:
|
||||
return json_metric_list
|
||||
|
||||
if 'series' in series_names.raw['results'][0]:
|
||||
if 'series' in series_names.raw:
|
||||
|
||||
id = 0
|
||||
|
||||
for series in series_names.raw['results'][0]['series']:
|
||||
for series in series_names.raw['series']:
|
||||
id += 1
|
||||
|
||||
name = {u'id': str(id),
|
||||
|
@ -249,12 +252,7 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
if not result:
|
||||
return json_measurement_list
|
||||
|
||||
if 'error' in result.raw['results'][0]:
|
||||
if (result.raw['results'][0]['error'].startswith(
|
||||
"measurement not found")):
|
||||
return json_measurement_list
|
||||
|
||||
for serie in result.raw['results'][0]['series']:
|
||||
for serie in result.raw['series']:
|
||||
|
||||
if 'values' in serie:
|
||||
|
||||
|
@ -276,8 +274,35 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
return json_measurement_list
|
||||
|
||||
except exceptions.RepositoryException as ex:
|
||||
|
||||
if (isinstance(ex.message, InfluxDBClientError) and
|
||||
ex.message.message.startswith(MEASUREMENT_NOT_FOUND_MSG)):
|
||||
|
||||
return json_measurement_list
|
||||
|
||||
else:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
except InfluxDBClientError as ex:
|
||||
|
||||
if ex.message.startswith(MEASUREMENT_NOT_FOUND_MSG):
|
||||
|
||||
return json_measurement_list
|
||||
|
||||
else:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
except Exception as ex:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
def list_metric_names(self, tenant_id, region, dimensions, offset, limit):
|
||||
|
@ -333,17 +358,11 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
if not result:
|
||||
return json_statistics_list
|
||||
|
||||
if 'error' in result.raw['results'][0]:
|
||||
if (result.raw['results'][0]['error'].startswith(
|
||||
"measurement not found")):
|
||||
return json_statistics_list
|
||||
|
||||
for serie in result.raw['results'][0]['series']:
|
||||
for serie in result.raw['series']:
|
||||
|
||||
if 'values' in serie:
|
||||
columns = ([column.replace('mean', 'avg') for column in
|
||||
result.raw['results'][0]['series'][0][
|
||||
'columns']])
|
||||
serie['columns']])
|
||||
|
||||
stats_list = []
|
||||
for stats in serie['values']:
|
||||
|
@ -360,8 +379,35 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
return json_statistics_list
|
||||
|
||||
except exceptions.RepositoryException as ex:
|
||||
|
||||
if (isinstance(ex.message, InfluxDBClientError) and
|
||||
ex.message.message.startswith(MEASUREMENT_NOT_FOUND_MSG)):
|
||||
|
||||
return json_statistics_list
|
||||
|
||||
else:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
except InfluxDBClientError as ex:
|
||||
|
||||
if ex.message.startswith(MEASUREMENT_NOT_FOUND_MSG):
|
||||
|
||||
return json_statistics_list
|
||||
|
||||
else:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
except Exception as ex:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
||||
def _build_offset_clause(self, offset, limit):
|
||||
|
@ -424,17 +470,12 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
result = self.influxdb_client.query(query)
|
||||
|
||||
if 'error' in result.raw['results'][0]:
|
||||
if (result.raw['results'][0]['error'].startswith(
|
||||
"measurement not found")):
|
||||
return json_alarm_history_list
|
||||
|
||||
if not result:
|
||||
return json_alarm_history_list
|
||||
|
||||
if 'values' in result.raw['results'][0]['series'][0]:
|
||||
if 'values' in result.raw['series'][0]:
|
||||
|
||||
for point in result.raw['results'][0]['series'][0]['values']:
|
||||
for point in result.raw['series'][0]['values']:
|
||||
alarm_point = {u'timestamp': point[0],
|
||||
u'alarm_id': point[1],
|
||||
u'metrics': json.loads(point[2]),
|
||||
|
@ -459,5 +500,7 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
return json_alarm_history_list
|
||||
|
||||
except Exception as ex:
|
||||
|
||||
LOG.exception(ex)
|
||||
|
||||
raise exceptions.RepositoryException(ex)
|
||||
|
|
|
@ -31,19 +31,17 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
|||
def test_measurement_list(self, influxdb_client_mock):
|
||||
mock_client = influxdb_client_mock.return_value
|
||||
mock_client.query.return_value.raw = {
|
||||
"results": [{
|
||||
"series": [
|
||||
{
|
||||
"name": "dummy.series",
|
||||
"values": [
|
||||
[1, 2, None],
|
||||
[2, 2.5, ''],
|
||||
[3, 4.0, '{}'],
|
||||
[4, 4, '{"key": "value"}']
|
||||
]
|
||||
}
|
||||
]
|
||||
}]
|
||||
"series": [
|
||||
{
|
||||
"name": "dummy.series",
|
||||
"values": [
|
||||
[1, 2, None],
|
||||
[2, 2.5, ''],
|
||||
[3, 4.0, '{}'],
|
||||
[4, 4, '{"key": "value"}']
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
repo = influxdb_repo.MetricsRepository()
|
||||
|
@ -75,24 +73,22 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
|||
def test_list_metrics(self, influxdb_client_mock):
|
||||
mock_client = influxdb_client_mock.return_value
|
||||
mock_client.query.return_value.raw = {
|
||||
u'results': [{
|
||||
u'series': [{
|
||||
u'values': [[
|
||||
u'disk.space_used_perc,_region=region,_tenant_id='
|
||||
u'0b5e7d8c43f74430add94fba09ffd66e,device=rootfs,'
|
||||
'hostname=host0,hosttype=native,mount_point=/',
|
||||
u'region',
|
||||
u'0b5e7d8c43f74430add94fba09ffd66e',
|
||||
u'rootfs',
|
||||
u'host0',
|
||||
u'native',
|
||||
u'',
|
||||
u'/'
|
||||
]],
|
||||
u'name': u'disk.space_used_perc',
|
||||
u'columns': [u'_key', u'_region', u'_tenant_id', u'device',
|
||||
u'hostname', u'hosttype', u'extra', u'mount_point']
|
||||
}]
|
||||
u'series': [{
|
||||
u'values': [[
|
||||
u'disk.space_used_perc,_region=region,_tenant_id='
|
||||
u'0b5e7d8c43f74430add94fba09ffd66e,device=rootfs,'
|
||||
'hostname=host0,hosttype=native,mount_point=/',
|
||||
u'region',
|
||||
u'0b5e7d8c43f74430add94fba09ffd66e',
|
||||
u'rootfs',
|
||||
u'host0',
|
||||
u'native',
|
||||
u'',
|
||||
u'/'
|
||||
]],
|
||||
u'name': u'disk.space_used_perc',
|
||||
u'columns': [u'_key', u'_region', u'_tenant_id', u'device',
|
||||
u'hostname', u'hosttype', u'extra', u'mount_point']
|
||||
}]
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ oslo.log
|
|||
oslo.serialization
|
||||
oslo.utils
|
||||
pastedeploy>=1.3.3
|
||||
pbr>=0.6,!=0.7,<1.0
|
||||
pbr>=1.6.0,<2.0
|
||||
python-dateutil>=1.5
|
||||
six>=1.7.0
|
||||
ujson>=1.33
|
||||
pyparsing>=2.0.3
|
||||
voluptuous>=0.8.7
|
||||
MySQL-python>=1.2.5
|
||||
influxdb==2.3.0
|
||||
influxdb==2.8.0
|
||||
eventlet
|
||||
kafka-python>=0.9.2,<0.9.3
|
||||
simplejson
|
||||
|
|
Loading…
Reference in New Issue