Application Insights日志查询获取组中的最新行

时间:2018-11-03 03:01:44

标签: azure azure-application-insights

我正在尝试在Application Insights中查找组中每个成员的最新行。

以下是查询:

traces | 
where timestamp > ago(1h) | 
where message startswith "TEST DONE" | 
order by timestamp desc nulls last |  
extend json=parse_json(substring(message,10))  | 
summarize  any(timestamp, tostring(json.status)) by tostring(json.testKey)

它确实只返回一行,但这不是最新行,它是可能行集中的任意随机行。

2 个答案:

答案 0 :(得分:1)

我认为您正在寻找arg_max函数?

https://docs.microsoft.com/en-us/azure/kusto/query/arg-max-aggfunction

类似:

traces | 
where timestamp > ago(1h) | 
where message startswith "TEST DONE" | 
order by timestamp desc nulls last |  
extend json=parse_json(substring(message,10))  | 
extend testKey = tostring(json.testKey) |
extend status = tostring(json.status) |
summarize arg_max(timestamp, status) by testKey

答案 1 :(得分:0)

您可以使用makelist([column name],1)选择第一个。然后按索引引用它。使用这项技术能够解决我的数据集上的上述问题。

这是适应您的查询的

traces | 
where timestamp > ago(1h) | 
where message startswith "TEST DONE" | 
order by timestamp desc nulls last |  
extend json=parse_json(substring(message,10))  | 
extend testKey = tostring(json.testKey) |
summarize timeStampList=makelist(timestamp, 1), statusList=makelist(tostring(json.status), 1) by testKey |
project timeStampList[0], statusList[0], testKey