【发布时间】:2021-03-11 09:57:37
【问题描述】:
有一个正在运行的 AKS 连接到 Azure 中的 Log Analytics。 我正在尝试使用以下查询 sn-p 查看命名 POD 的日志:
let KubePodLogs = (clustername:string, podnameprefix:string) {
let ContainerIdList = KubePodInventory
| where ClusterName =~ clustername
| where Name startswith strcat(podnameprefix, "-")
| where strlen(ContainerID)>0
| distinct ContainerID;
ContainerLog
| where ContainerID in (ContainerIdList)
| join (KubePodInventory | project ContainerID, Name, PodLabel, Namespace, Computer) on ContainerID
| project TimeGenerated, Node=Computer, Namespace, PodName=Name1, PodLabel, ContainerID, LogEntry
};
KubePodLogs('aks-my-cluster', 'my-service') | order by TimeGenerated desc
上述查询确实返回了匹配 POD 的行,但并非所有实际可用的行。
尝试通过检查 POD 详细信息来获取部分查询的结果:
KubePodInventory
| where ClusterName =~ 'aks-my-cluster'
| where Name startswith 'my-service-'
| where strlen(ContainerID)>0
| distinct ContainerID;
给我一个容器 ID。现在将此容器 ID 输入另一个查询显示更多 结果然后是上面的组合查询。为什么?
ContainerLog
| where ContainerID == "aec001...fc31"
| order by TimeGenerated desc
| project TimeGenerated, ContainerID, LogEntry
我注意到的一件事是,后面的简单查询结果包含从 POD 的 JSON 格式输出解析的 LogEntry 字段的日志结果。在结果中,我可以将 LogEntry 扩展为与该 POD 日志输出的原始 JSON 数据相对应的更多字段。
即似乎组合查询(带有连接)跳过了那些 JSON LogEntry ContainerLog 条目,但为什么呢?
据我所知,组合查询不会以任何方式过滤 LogEntry 字段。
【问题讨论】:
-
嗯,我刚刚注意到组合查询的结果显示所有行的相同 LogEntry 数据。也许与以下“项目”的“加入”是错误的?
标签: azure kubernetes azure-aks azure-log-analytics