python impl. of metric-name-list for InfluxDB returns incomplete results
Change-Id: I269344f59684c74f9a8ad556620f1b786906cbc5 Closes-Bug: 1628798
This commit is contained in:
@@ -34,5 +34,5 @@ class NotificationsTypeV2API(object):
|
|||||||
def on_put(self, req, res):
|
def on_put(self, req, res):
|
||||||
res.status = '501 Not Implemented'
|
res.status = '501 Not Implemented'
|
||||||
|
|
||||||
def on_patch(self, req):
|
def on_patch(self, req, res):
|
||||||
res.status = '501 Not Implemented'
|
res.status = '501 Not Implemented'
|
||||||
|
@@ -33,7 +33,6 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -59,6 +58,15 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
|||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
def _build_show_measurements_query(self, dimensions, name, tenant_id, region):
|
||||||
|
|
||||||
|
where_clause = self._build_where_clause(dimensions, name, tenant_id,
|
||||||
|
region)
|
||||||
|
|
||||||
|
query = 'show measurements ' + where_clause
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
def _build_select_measurement_query(self, dimensions, name, tenant_id,
|
def _build_select_measurement_query(self, dimensions, name, tenant_id,
|
||||||
region, start_timestamp, end_timestamp,
|
region, start_timestamp, end_timestamp,
|
||||||
offset, limit):
|
offset, limit):
|
||||||
@@ -277,7 +285,6 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
|||||||
dimensions,
|
dimensions,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
end_timestamp):
|
end_timestamp):
|
||||||
|
|
||||||
metric = {u'id': str(metric_id),
|
metric = {u'id': str(metric_id),
|
||||||
u'name': series[u'name'],
|
u'name': series[u'name'],
|
||||||
u'dimensions': dimensions}
|
u'dimensions': dimensions}
|
||||||
@@ -287,17 +294,22 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
|||||||
|
|
||||||
return json_metric_list
|
return json_metric_list
|
||||||
|
|
||||||
def _build_serie_name_list(self, series_names):
|
def _build_measurement_name_list(self, measurement_names):
|
||||||
|
"""read measurement names from InfluxDB response
|
||||||
|
|
||||||
|
Extract the measurement names (InfluxDB terminology) from the SHOW MEASURMENTS result to yield metric names
|
||||||
|
:param measurement_names: result from SHOW MEASUREMENTS call (json-dict)
|
||||||
|
:return: list of metric-names (Monasca terminology)
|
||||||
|
"""
|
||||||
|
|
||||||
json_metric_list = []
|
json_metric_list = []
|
||||||
|
|
||||||
if not series_names:
|
if not measurement_names:
|
||||||
return json_metric_list
|
return json_metric_list
|
||||||
|
|
||||||
if 'series' in series_names.raw:
|
for name in measurement_names.raw.get(u'series', [{}])[0].get(u'values', []):
|
||||||
for series in series_names.raw['series']:
|
entry = {u'name': name[0]}
|
||||||
name = {u'name': series[u'name']}
|
json_metric_list.append(entry)
|
||||||
json_metric_list.append(name)
|
|
||||||
|
|
||||||
json_metric_list = sorted(json_metric_list)
|
json_metric_list = sorted(json_metric_list)
|
||||||
return json_metric_list
|
return json_metric_list
|
||||||
@@ -396,10 +408,12 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query = self._build_show_series_query(dimensions, None, tenant_id,
|
query = self._build_show_measurements_query(dimensions, None, tenant_id,
|
||||||
region)
|
region)
|
||||||
|
|
||||||
result = self.influxdb_client.query(query)
|
result = self.influxdb_client.query(query)
|
||||||
json_name_list = self._build_serie_name_list(result)
|
|
||||||
|
json_name_list = self._build_measurement_name_list(result)
|
||||||
return json_name_list
|
return json_name_list
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
Reference in New Issue
Block a user