@@ -51,15 +51,16 @@ def TOPO(self):
51
51
52
52
def format_response (self , data : dict , jreq : dict ) -> List [dict ]:
53
53
respList = []
54
- for name , metric in data .items ():
54
+ metrics = set (data .values ())
55
+ for metric in metrics :
55
56
for st in metric .timeseries :
56
- res = SingleTimeSeriesResponse (jreq .get ('inputQuery' ), st . dps ,
57
+ res = SingleTimeSeriesResponse (jreq .get ('inputQuery' ),
57
58
jreq .get ('showQuery' ),
58
59
jreq .get ('globalAnnotations' ),
59
60
st .tags , st .aggregatedTags )
60
- cherrypy . response . headers [ 'Access-Control-Allow-Origin' ] = '*'
61
- self . logger . trace ( f'OpenTSDB queryResponse: { str ( res . __dict__ ) } ' )
62
- respList .append (res .__dict__ )
61
+ # self.logger.trace(f'OpenTSDB queryResponse for :
62
+ # {data.keys()[0]} with {len(st.dps)} datapoints ')
63
+ respList .append (res .to_dict ( st . dps ) )
63
64
return respList
64
65
65
66
def query (self , jreq : dict ) -> List [dict ]:
@@ -101,9 +102,9 @@ def query(self, jreq: dict) -> List[dict]:
101
102
self .logger .trace ('Finished custom thread %r.' % collector .thread .name )
102
103
103
104
coll_resp = self .format_response (collector .metrics , request_data )
104
- cherrypy .response .headers ['Access-Control-Allow-Origin' ] = '*'
105
+ # cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
105
106
resp .extend (coll_resp )
106
-
107
+ cherrypy . response . headers [ 'Access-Control-Allow-Origin' ] = '*'
107
108
return resp
108
109
109
110
def build_collector (self , jreq : dict ) -> SensorCollector :
@@ -371,16 +372,26 @@ def parse_result_tags(self, identifiersMap):
371
372
self .results .append (d )
372
373
373
374
374
- class SingleTimeSeriesResponse ():
375
+ class SingleTimeSeriesResponse (object ):
375
376
376
- def __init__ (self , inputQuery , dps , showQuery = False ,
377
+ def __init__ (self , inputQuery , showQuery = False ,
377
378
globalAnnotations = False , tags : dict = None ,
378
379
aggrTags : list = None ):
379
380
self .metric = inputQuery .get ('metric' )
380
- self .dps = dps
381
+ self .dps = defaultdict ()
381
382
if showQuery :
382
383
self .query = inputQuery
383
384
if globalAnnotations :
384
385
self .globalAnnotations = []
385
386
self .tags = tags or defaultdict (list )
386
387
self .aggregatedTags = aggrTags or []
388
+
389
+ def to_dict (self , dps : dict = None ):
390
+ ''' Converts the SingleTimeSeriesResponse object to dict. '''
391
+ res = self .__dict__
392
+ # Since a single Timeseries might have a huge number of datapoints (dps),
393
+ # first convert object to dict and then fetch the dict of dps to it
394
+ if dps :
395
+ res ['dps' ] = dps
396
+ return res
397
+
0 commit comments