简体   繁体   English

让基于日志的指标自动确定来自 JSON 过滤日志有效负载的标签

[英]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_sizeare_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:以下是我想到的一些合理的默认值:

  • "Log metric name" takes on the name of the field itself. “日志指标名称”采用字段本身的名称。
  • "Description" would be left empty. “描述”将留空。
  • "Label type" would be determined from the type of the field. “标签类型”将根据字段类型确定。
  • "Field name" would be 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 插件配置

Configuring the agent 配置代理

Processing payloads 处理负载

Special fields in structured payloads 结构化有效载荷中的特殊字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置基于日志的指标以对日志消息中的某些值求和? - How do I configure a logs-based metric to sum some values from log messages? 如何在 Terraform 中设置基于 GCP 监控日志的警报? - How to set up a GCP Monitoring log-based alert in Terraform? 在 GCP 中,如何从不同存储桶中的日志创建基于日志的指标? - In GCP, How to create a logs-based metric from logs in a different bucket? 仅当最后一条消息符合两个条件时才基于 GCP 日志发出警报 - GCP log-based alert only if the last message matches two conditions 使用 Google Cloud Logging Python 库发送带有标签的 JSON 有效负载 - Send a JSON Payload with labels using Google Cloud Logging Python library 如何将基于日志的指标与监控策略相关联? - How to relate a log-based-metric to a monitoring policy? 如何从日志组指标过滤器创建 CloudWatch 警报 - How to create a CloudWatch alarm from log group metric filter 如何通过 log4js-node 将标签传递给 Google Cloud Logs Explorer? - How do you pass labels to Google Cloud Logs Explorer through log4js-node? 如何使用 Google Cloud SDK 创建基于日志的指标警报(电子邮件通知)? - How to create log-based-metric alert (email notification) with Google Cloud SDK? 如何在 AWS 中搜索引发指标警报的日志? - How to search for a logs that raised metric alarm in AWS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM