|
18 | 18 |
|
19 | 19 | from oslo_config import cfg |
20 | 20 | from oslo_log import log |
| 21 | +from voluptuous import All |
21 | 22 | from voluptuous import In |
22 | 23 | from voluptuous import Optional |
23 | 24 | from voluptuous import Required |
|
83 | 84 | 'changes', 'delta', 'deriv', |
84 | 85 | 'idelta', 'irange', 'irate', |
85 | 86 | 'rate' |
86 | | - ]) |
| 87 | + ]), |
| 88 | + Optional('query_prefix', default=''): All(str), |
| 89 | + Optional('query_suffix', default=''): All(str), |
87 | 90 | } |
88 | 91 | } |
89 | 92 |
|
@@ -159,6 +162,8 @@ def fetch_all(self, metric_name, start, end, scope_id, q_filter=None): |
159 | 162 | 'range_function') |
160 | 163 | groupby = self.conf[metric_name].get('groupby', []) |
161 | 164 | metadata = self.conf[metric_name].get('metadata', []) |
| 165 | + query_prefix = self.conf[metric_name]['extra_args']['query_prefix'] |
| 166 | + query_suffix = self.conf[metric_name]['extra_args']['query_suffix'] |
162 | 167 | period = tzutils.diff_seconds(end, start) |
163 | 168 | time = end |
164 | 169 |
|
@@ -198,6 +203,14 @@ def fetch_all(self, metric_name, start, end, scope_id, q_filter=None): |
198 | 203 | ', '.join(groupby + metadata) |
199 | 204 | ) |
200 | 205 |
|
| 206 | + # Add custom query prefix |
| 207 | + if query_prefix: |
| 208 | + query = "{0} {1}".format(query_prefix, query) |
| 209 | + |
| 210 | + # Add custom query suffix |
| 211 | + if query_suffix: |
| 212 | + query = "{0} {1}".format(query, query_suffix) |
| 213 | + |
201 | 214 | try: |
202 | 215 | res = self._conn.get_instant( |
203 | 216 | query, |
|
0 commit comments