Skip to content

Commit ba68622

Browse files
committed
handle no metric case
Signed-off-by: hwassman <[email protected]>
1 parent 91a5772 commit ba68622

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

source/opentsdb.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def format_response(self, data: dict, jreq: dict) -> List[dict]:
5757
if jreq.get('start') == 'last':
5858
for metric in metrics:
5959
for st in metric.timeseries:
60-
timestmp =''
61-
val = 'null'
60+
timestmp = ''
61+
val = 'null'
6262
if len(st.dps) > 0:
6363
timestmp = list(st.dps.keys())[0]
6464
val = st.dps[timestmp]
@@ -323,14 +323,16 @@ def GET(self, **params):
323323
self.logger.error(MSG['QueryError'].format('empty'))
324324
raise cherrypy.HTTPError(400, ERR[400])
325325

326-
queries = []
326+
queries = []
327327
timeseries = params.get('timeseries')
328328
if not isinstance(timeseries, list):
329329
timeseries = [timeseries]
330330
for timeserie in timeseries:
331331
try:
332332
metricDict = {}
333333
params_list = re.split(r'\{(.*)\}', timeserie.strip())
334+
if len(params_list[0]) == 0:
335+
break
334336
metricDict['metric'] = params_list[0]
335337

336338
if len(params_list) > 1:
@@ -342,6 +344,8 @@ def GET(self, **params):
342344
except Exception as e:
343345
self.logger.exception(MSG['IntError'].format(str(e)))
344346
raise cherrypy.HTTPError(500, MSG[500])
347+
if len(queries) == 0:
348+
raise cherrypy.HTTPError(400, ERR[400])
345349
jreq['start'] = 'last'
346350
jreq['queries'] = queries
347351

0 commit comments

Comments
 (0)