OpenTSDB Expressions not working in Grafana V8.2.x with Template Variables in Query

Hi Team,

Need you help in solving the below issue.

we are using Grafana : v8.2.0

We have integrated OpenTSDB(2.3) with Grafana.

I have created Some Template Variables and then I have created a query to visualize the data with the define template variables as below and it works fine

Attaching the QueryInspector content as well from OpenTSDB logs

Executing new query={“query”:{“start”:“1643563447286”,“end”:“1643658421332”,“timezone”:null,“options”:null,“padding”:false,“queries”:[{“aggregator”:“sum”,“metric”:“myMetric.M1”,“tsuids”:null,“downsample”:“1h-avg”,“rate”:false,“filters”:[{“tagk”:“ROOT”,“filter”:“ROOT”,“group_by”:true,“type”:“literal_or”},{“tagk”:“LEVEL1”,“filter”:“500001”,“group_by”:true,“type”:“literal_or”}],“percentiles”:null,“index”:0,“rateOptions”:null,“filterTagKs”:,“explicitTags”:false,“useFuzzyFilter”:true,“preAggregate”:false,“rollupUsage”:null,“rollupTable”:“raw”,“showHistogramBuckets”:false,“useMultiGets”:true,“histogramQuery”:false,“tags”:{“ROOT”:“literal_or(ROOT)”,“LEVEL1”:“literal_or(500001)”}}],“delete”:false,“showTSUIDs”:false,“msResolution”:false,“showQuery”:true,“showStats”:false,“showSummary”:false,“useCalendar”:false,“globalAnnotations”:true,“noAnnotations”:false},“exception”:“null”,“executed”:1,“user”:null,“requestHeaders”:{“Accept”:“application/json, text/plain, /”,“User-Agent”:“Grafana/8.2.0”,“X-Forwarded-For”:“172.17.0.1, 172.17.0.1”,“X-Grafana-Org-Id”:“1”,“Host”:“172.26.153.104:30404”,“Accept-Encoding”:“gzip, deflate”,“Accept-Language”:“en-GB,en;q=0.9,en-US;q=0.8”,“Content-Length”:“225”,“Content-Type”:“application/json”},“numRunningQueries”:1,“httpResponse”:null,“queryStartTimestamp”:1643790500251,“queryCompletedTimestamp”:0,“sentToClient”:false,“stats”:{}}

So far things are fine.

Now I am creating an expression with $A * 10 and then getting the expression request error.

Attaching the QueryInspector content as well from OpenTSDB logs

Executing new query={“query”:{“start”:“1643563447000”,“end”:“1643658421000”,“timezone”:null,“options”:null,“padding”:false,“queries”:[{“aggregator”:“sum”,“metric”:“myMetric.M1”,“tsuids”:null,“downsample”:“1h-avg”,“rate”:false,“filters”:[{“tagk”:“LEVEL1”,“filter”:"$LEVEL1",“group_by”:true,“type”:“literal_or”},{“tagk”:“ROOT”,“filter”:"$ROOT",“group_by”:true,“type”:“literal_or”}],“percentiles”:null,“index”:0,“rateOptions”:null,“filterTagKs”:,“explicitTags”:false,“useFuzzyFilter”:true,“preAggregate”:false,“rollupUsage”:null,“rollupTable”:“raw”,“showHistogramBuckets”:false,“useMultiGets”:true,“histogramQuery”:false,“tags”:{“ROOT”:“literal_or($ROOT)”,“LEVEL1”:“literal_or($LEVEL1)”}}],“delete”:false,“showTSUIDs”:false,“msResolution”:false,“showQuery”:false,“showStats”:false,“showSummary”:false,“useCalendar”:false,“globalAnnotations”:false,“noAnnotations”:false},“exception”:“null”,“executed”:1,“user”:null,“requestHeaders”:{“User-Agent”:“Grafana/8.2.0”,“Host”:“172.26.153.104:30404”,“Accept-Encoding”:“gzip”,“Content-Length”:“164”,“Content-Type”:“application/json”},“numRunningQueries”:1,“httpResponse”:null,“queryStartTimestamp”:1643790712972,“queryCompletedTimestamp”:0,“sentToClient”:false,“stats”:{}}


expression request error
Object
status:500
statusText:“Internal Server Error”
data:Object
message:“expression request error”
config:Object
url:“api/ds/query”
method:“POST”
data:Object
queries:Array[2]
range:Object
from:“1643563447286”
to:“1643658421332”
requestId:“Q210”
retry:0
headers:Object
X-Grafana-Org-Id:1
hideFromInspector:false
message:“expression request error”

I suspect that whenever expression is used, then template variables are not getting substituted in the Queries, because of this we are getting bad request error.

Thanks,
Manoj

welcome to the :grafana: forum, @manoja

in place of using expressions, try using a transformation like add field from calculation.

Transformations are more stable than expressions:

Hi mattabrams,

Thank you very much for your reply.

We have requirement to do calculations like Multiplying each query by some pre-defined numeric values.

Example. If we have two queries A and B.

we need output like 10 * A + 5 * B , 100 *( A + B) , 100 * (A / B) etc…

Is it possible using transformation ?

Thanks,
Manoj