@@ -59,6 +59,23 @@ def my_setup():
5959 }
6060
6161
62+ def query_last_setup ():
63+ global key1 , col1 , labels , filtersMap , dps1 , ts1 , metricTS , data , jreq
64+
65+ key1 = Key ._from_string ('scale-16|CPU|cpu_user' , '' )
66+ col1 = ColumnInfo (name = 'cpu_user' , semType = 1 , keys = (key1 ,), column = 0 )
67+ filtersMap = [{'node' : 'scale-11' }, {'node' : 'scale-12' }, {'node' : 'scale-13' }, {'node' : 'scale-14' }, {'node' : 'scale-15' }, {'node' : 'scale-16' }]
68+ labels = ['node' ]
69+ dps1 = {1737321193 : 3.0 }
70+ ts1 = TimeSeries (col1 , dps1 , filtersMap , labels )
71+ metricTS = MetricTimeSeries ('cpu_user' , '' )
72+ metricTS .timeseries = [ts1 ]
73+ data = {'cpu_user' : metricTS }
74+ jreq = {'start' : 'last' , 'inputQuery' : {'metric' : 'cpu_user' ,
75+ 'tags' : {'node' : 'scale-16' },
76+ 'index' : 0 }}
77+
78+
6279@with_setup (my_setup )
6380def test_case01 ():
6481 ts = TimeSeries (col3 , dps2 , filtersMap , labels )
@@ -109,3 +126,16 @@ def test_case04():
109126 response = profiler .stats (os .path .join (profiler .path , "profiling_format_response.prof" ))
110127 assert response is not None
111128 print ('\n ' .join (response ) + '\n ' )
129+
130+
131+ @with_setup (query_last_setup )
132+ def test_case05 ():
133+ with mock .patch ('source.metadata.MetadataHandler' ) as md :
134+ md_instance = md .return_value
135+ logger = logging .getLogger (__name__ )
136+ opentsdb = OpenTsdbApi (logger , md_instance , '9999' )
137+ resp = opentsdb .format_response (data , jreq )
138+ assert set (resp [0 ].keys ()) == set (['metric' ,'timestamp' ,'value' ,'tags' ])
139+ assert resp [0 ].get ('metric' ) == "cpu_user"
140+ assert 'gpfs_fs_name' not in resp [0 ].get ('tags' )
141+ assert 'node' in resp [0 ].get ('tags' )
0 commit comments