[英]Have Log-Based Metric Automatically Determine Labels from JSON Payload of Filtered Logs
Background (skip to "The Problem" for end goal)背景(跳到“问题”以获得最终目标)
Take an example endpoint /process-batch
that processes a batch of items given a single request.以端点
/process-batch
为例,它处理给定单个请求的一批项目。 Upon receiving that request, it logs the following line:收到该请求后,它会记录以下行:
{"endpoint_type": "process-batch", "batch_size": <integer>, "are_there_warnings": <boolean>}
I can configure a logs-based metric for this via:我可以通过以下方式为此配置基于日志的指标:
Then I can create a line chart (changing the "Resource & Metric" to be the logs-based metric created above, specifying that it can be emitted from anywhere globally):然后我可以创建一个折线图(将“资源和指标”更改为上面创建的基于日志的指标,指定它可以从全球任何地方发出):
Resulting dashboard looks like this:生成的仪表板如下所示:
The issue is that batch_size
and are_there_warnings
don't automatically appear as fields that I can use to manipulate the line graph.问题是
batch_size
和are_there_warnings
不会自动显示为我可以用来操作折线图的字段。 See "Group By" and "Add Filter" below:请参阅下面的“分组依据”和“添加过滤器”:
To enable those fields, I can add a label for each of them (let's call this the "explicit labeling" step for future reference):要启用这些字段,我可以为每个字段添加一个 label(我们称此为“显式标记”步骤以供将来参考):
After confirming those labels are added:确认添加了这些标签后:
I can go back to the dashboard and see that "Group By" and "Add Filter" have been updated accordingly:我可以 go 返回到仪表板,看到“分组依据”和“添加过滤器”已相应更新:
And can manipulate the dashboard to use those fields:并且可以操纵仪表板来使用这些字段:
The Problem问题
When trying to improve observability for an existing codebase, I have to add all the existing fields already logged as explicit labels on the GCP side, instead of GCP inferring that the logged fields are labels based on their name and type.在尝试提高现有代码库的可观察性时,我必须在 GCP 端添加所有已记录为显式标签的现有字段,而不是 GCP 根据其名称和类型推断记录的字段是标签。 And for the rare cases when I add a new field (such as
cost
to the log lines emitted by /process-batch
), I have to do explicit labeling on the GCP Monitoring and Logging side instead of GCP inferring that the newly added field should be a new implicitly added label in group by and filter.对于我添加新字段的极少数情况(例如
/process-batch
发出的日志行的cost
),我必须在 GCP 监控和日志记录端进行显式标记,而不是 GCP 推断新添加的字段应该在 group by 和 filter 中是一个新的隐式添加的 label。
Is it possible for GCP to automatically treat all fields part of jsonPayload
as labels? GCP 是否可以自动将
jsonPayload
的所有字段部分视为标签? Here are some reasonable defaults I had in mind:以下是我想到的一些合理的默认值:
jsonPayload.<log-metric-name>
. jsonPayload.<log-metric-name>
。 If this is not possible, I'd also appreciate any reasoning if implicitly treating jsonPayload
fields as labels is a bad idea.如果这是不可能的,如果隐含地将
jsonPayload
字段视为标签是一个坏主意,我也会很感激任何推理。 In my eyes, it would significantly reduce the effort to have functional dashboards.在我看来,这将大大减少拥有功能性仪表板的工作量。
Upon checking, This kind of feature is not yet available.经查,暂无此类功能。 However we already raise this request.
但是我们已经提出了这个要求。 This request does not have an ETA but we can monitor this using below link.
此请求没有预计到达时间,但我们可以使用以下链接对其进行监控。
You can star the public issue tracker feature requests and add 'Me too' in the thread.您可以为公共问题跟踪器功能请求加注星标,并在主题中添加“我也是”。 This will bring more attention to the request as more users request support for it.
随着更多用户请求支持,这将使该请求受到更多关注。
Feature Request Tracker: Autodetect Labels from JSON Payload功能请求跟踪器:自动检测来自 JSON 负载的标签
As of now below are some guides that can help you.截至目前,以下是一些可以为您提供帮助的指南。
Google Cloud fluentd output plugin configuration Google Cloud fluentd output 插件配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.