对相似的列字符串值进行分组

Grouping similar column string values

我在 Azure Log Analytics 中有一个 table 用于记录消息。 实际上并没有很多不同的消息,但在每个消息中都有一个可变部分,如用户 ID 或时间戳。 我需要计算按一小时间隔分组的不同消息类型,忽略每条消息中的可变元素(在本例中为 UUID 和时间戳)。 我不知道所有的消息类型。 我不能碰其他任何东西,我被迫使用这个 table。

示例数据:

timestamp | message 
----------|--------------------------------------------------------
          | Message type A for user id 993215f6-c42a-4957-bd55-78d71306a8d0
          | Message type A for user id 60e7d02c-770a-4641-b379-6bd33fcd563c
          | Message type A for user id 5bf7646c-092b-4e20-ba43-de7fe01010ea
          | Another message type containing timestamp hh:mm:ss
          | Another message type containing timestamp hh:mm:ss
          | Another message type containing timestamp hh:mm:ss
          | Type C message <variable_string>

期望的输出:

timestamp                   | distinct_message                           | count 
----------------------------|--------------------------------------------|------
10/2/2019, 10:00:00.000 AM  | Message type A for user id                 | 25
10/2/2019, 10:00:00.000 AM  | Another message type containing timestamp  | 13
10/2/2019, 10:00:00.000 AM  | Type C message                             | 0
10/2/2019, 11:00:00.000 AM  | Message type A for user id                 | 4
10/2/2019, 11:00:00.000 AM  | Another message type containing timestamp  | 6
10/2/2019, 11:00:00.000 AM  | Type C message                             | 2

这是我设法创建的,但我对 KQL 的了解非常有限。

let regex_uid = "[[:xdigit:]]+-[[:xdigit:]]+-[[:xdigit:]]+-[[:xdigit:]]+-[[:xdigit:]]+";
traces 
| where timestamp > ago(1d) 
| extend message = replace(regex_uid, "", message) 
| extend message = replace("[0-9]+", "", message) 
| extend message = iif(message startswith "Type C message", "Type C message", message ) 
| project timestamp, message, operation_Name
| summarize count(operation_Name) by bin(timestamp, 1h), message

有更好的方法吗?

您可以考虑的另一个选择是使用 reduce 运算符:https://docs.microsoft.com/en-us/azure/kusto/query/reduceoperator

输出结果与您问题中的输出结果不同。虽然如果我正确理解你的意图,它遵循相同的原则。