22 Jan 2025 09:00 AM - edited 22 Jan 2025 09:01 AM
Hi,
I am trying to transform the message "There are no records" in my tile to a single 0 (or an array of zeros).
I have tried using union:true, nonempty:true, and the coalesce function but none of them seem to work. I assume this is because the query uses 2 timeseries joined.
Is there a way to achieve this?
Here is my DQL:
timeseries count = sum(dt.service.request.count, default:0), by: { dt.entity.service }, filter: { failed == true }
| join [ timeseries count = sum(dt.service.request.count, default:0), by: { dt.entity.service } ], on: { dt.entity.service }, fields: { operand = count }
| filter { ( in(dt.entity.service, classicEntitySelector("type(service),tag(\"Kubernetes_ClusterName:payments\")"))) }
| fieldsAdd expression = count[] / operand[]
| fieldsRemove operand, count
| summarize { expression = avg(expression[] ) }, by: { interval, timeframe }
| sort arrayAvg(expression) desc
Thanks in advance!
Solved! Go to Solution.
23 Jan 2025 11:11 AM
"There are no records" message appears instead of chart in 2 cases:
To avoid this we need to make sure that there is always a result and it contains data. Null is valid value of timeseries which means no data, but it this it may be caused as a result of division of 0 by 0
Additionally there is another problem with join in this query: left query (timeseries with "failed == true" condition) will not return a timeseries for a specific service when there is no failed requests and this cause that a service will not be present in the final data at all.
Final query can look like this:
timeseries total = sum(dt.service.request.count, default:0), nonempty:true, by: { dt.entity.service }
, filter: { ( in(dt.entity.service, classicEntitySelector("type(service),tag(\"Kubernetes_ClusterName:payments\")"))) }
| fieldsAdd key=record(dt.entity.service)
| join [
timeseries failed = sum(dt.service.request.count, default:0), nonempty:true, by: { dt.entity.service }
, filter: { failed == true and ( in(dt.entity.service, classicEntitySelector("type(service),tag(\"Kubernetes_ClusterName:payments\")"))) }
| fieldsAdd key=record(dt.entity.service)
], on: { key }, fields: { failed }, kind:leftOuter
| fieldsAdd failed = coalesce(failed, icollectArray(total[]*0) )
| fieldsAdd expression = failed[] / total[]
| summarize { expression = avg(expression[] ) }, by: { interval, timeframe }
| fieldsAdd expression = coalesce(expression[],0)
| sort arrayAvg(expression) desc
What are the components of it:
| fieldsAdd key=record(dt.entity.service)
| fieldsAdd failed = coalesce(failed, icollectArray(total[]*0) )
makes sure we have array of zeroes instead
| fieldsAdd expression = coalesce(expression[],0)