Skip to content

Commit 4bd681a

Browse files
authored
Merge pull request #304 from Helene/opentsdb24_raw_data
Allow to query raw counters with OpenTSDB version 24
2 parents bc85d43 + 647fa77 commit 4bd681a

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

source/opentsdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def build_collector(self, jreq: dict) -> SensorCollector:
163163
if 'arrays' in jreq:
164164
args['dpsArrays'] = jreq['arrays']
165165

166-
args['rawData'] = q.get('explicitTags', False)
166+
args['rawData'] = q.get('explicitTags', False) or q.get('isCounter', False)
167167

168168
args['sensor'] = sensor
169169
args['period'] = period

tests/test_opentsdb.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,57 @@ def query_arrays_setup():
104104
}
105105

106106

107+
def query_raw_data_setup():
108+
global jreq, jreq1, jreq2, jreq3, jreq4
109+
110+
jreq = {'start': 1739214930519, 'end': 1739215230519, 'arrays': True,
111+
'inputQuery': {'aggregator': 'noop', 'downsample': '1m-avg',
112+
'filters': [
113+
{'filter': 'scale-11', 'groupBy': False,
114+
'tagk': 'node', 'type': 'pm_filter'
115+
}],
116+
'metric': 'cpu_system', 'index': 0,
117+
'shouldComputeRate': False, 'isCounter': False
118+
}
119+
}
120+
jreq1 = {'start': 1739214930519, 'end': 1739215230519, 'arrays': True,
121+
'inputQuery': {'aggregator': 'noop', 'downsample': '1m-avg',
122+
'filters': [
123+
{'filter': 'scale-11', 'groupBy': False,
124+
'tagk': 'node', 'type': 'pm_filter'
125+
}],
126+
'metric': 'cpu_system', 'index': 0,
127+
'shouldComputeRate': True, 'isCounter': False
128+
}
129+
}
130+
jreq2 = {'start': 1739214930519, 'end': 1739215230519, 'arrays': True,
131+
'inputQuery': {'aggregator': 'noop', 'downsample': '1m-avg',
132+
'filters': [
133+
{'filter': 'scale-11', 'groupBy': False,
134+
'tagk': 'node', 'type': 'pm_filter'
135+
}],
136+
'metric': 'cpu_system', 'index': 0,
137+
'shouldComputeRate': True, 'isCounter': True
138+
}
139+
}
140+
jreq3 = {'start': 1746277483949, 'end': None,
141+
'inputQuery': {'aggregator': 'noop', 'downsampleAggregator': 'avg',
142+
'downsampleFillPolicy': 'none',
143+
'metric': 'cpu_contexts',
144+
'disableDownsampling': True,
145+
'explicitTags': True, 'index': 0
146+
}
147+
}
148+
jreq4 = {'start': 1746277483949, 'end': None,
149+
'inputQuery': {'aggregator': 'noop', 'downsampleAggregator': 'avg',
150+
'downsampleFillPolicy': 'none',
151+
'metric': 'cpu_contexts',
152+
'disableDownsampling': True,
153+
'explicitTags': False, 'index': 0
154+
}
155+
}
156+
157+
107158
@with_setup(my_setup)
108159
def test_case01():
109160
ts = TimeSeries(col3, dps2, filtersMap, labels)
@@ -195,3 +246,27 @@ def test_case07():
195246
assert 'node' in resp[0].get('tags')
196247
assert isinstance(resp[0].get('dps'), list)
197248
assert len(resp[0].get('dps')) == 0
249+
250+
251+
@with_setup(query_raw_data_setup)
252+
def test_case08():
253+
q = jreq.get('inputQuery')
254+
args = {}
255+
args['rawData'] = q.get('explicitTags', False) or q.get('isCounter', False)
256+
assert args.get('rawData') == False
257+
q1 = jreq1.get('inputQuery')
258+
args1 = {}
259+
args1['rawData'] = q1.get('explicitTags', False) or q1.get('isCounter', False)
260+
assert args1.get('rawData') == False
261+
q2 = jreq2.get('inputQuery')
262+
args2 = {}
263+
args2['rawData'] = q2.get('explicitTags', False) or q2.get('isCounter', False)
264+
assert args2.get('rawData') == True
265+
q3 = jreq3.get('inputQuery')
266+
args3 = {}
267+
args3['rawData'] = q3.get('explicitTags', False) or q3.get('isCounter', False)
268+
assert args3.get('rawData') == True
269+
q4 = jreq4.get('inputQuery')
270+
args4 = {}
271+
args4['rawData'] = q4.get('explicitTags', False) or q4.get('isCounter', False)
272+
assert args4.get('rawData') == False

0 commit comments

Comments
 (0)