otelcol.processor.groupbyattrs
otelcol.processor.groupbyattrs
接受来自其他 otelcol
组件的 span(链路段)、指标和链路追踪,并将它们分组到相同的资源下。
注意
otelcol.processor.groupbyattrs
是上游 OpenTelemetry Collectorgroupbyattrs
处理器的包装。如有必要,错误报告或功能请求将重定向到上游仓库。
我们建议您将 groupbyattrs 处理器与 otelcol.processor.batch 一起使用,作为后续步骤。这将通过在匹配的资源/插桩库下将记录分组在一起,减少数据碎片化。
您可以通过赋予不同的标签来指定多个 otelcol.processor.groupbyattrs
组件。
用法
otelcol.processor.groupbyattrs "LABEL" {
output {
metrics = [...]
logs = [...]
traces = [...]
}
}
参数
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
keys | list(string) | 用于将 span(链路段)、日志记录或指标数据点分组到一起的键。 | [] | 否 |
keys
是一个用于分组数据的字符串数组。如果为空,处理器将执行压缩操作,并将所有具有匹配资源和插桩库的 span(链路段)重新关联。
块
在 otelcol.processor.groupbyattrs
的定义中支持以下块
层级 | 块 | 描述 | 必需 |
---|---|---|---|
output | output | 配置接收到的遥测数据发送到何处。 | 是 |
debug_metrics | debug_metrics | 配置此组件生成用于监控其状态的指标。 | 否 |
output 块
output
块配置一组组件来转发产生的遥测数据。
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
logs | list(otelcol.Consumer) | 发送日志到的消费者列表。 | [] | 否 |
metrics | list(otelcol.Consumer) | 发送指标到的消费者列表。 | [] | 否 |
traces | list(otelcol.Consumer) | 发送链路追踪到的消费者列表。 | [] | 否 |
您必须指定 output
块,但其所有参数都是可选的。默认情况下,遥测数据会被丢弃。相应地配置 metrics
、logs
和 traces
参数,将遥测数据发送到其他组件。
debug_metrics 块
debug_metrics
块配置此组件生成用于监控其状态的指标。
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
disable_high_cardinality_metrics | boolean | 是否禁用某些高基数指标。 | true | 否 |
disable_high_cardinality_metrics
是 Grafana Alloy 中相当于 OpenTelemetry Collector 中 telemetry.disableHighCardinalityMetrics
功能门的配置。它移除可能导致高基数指标的属性。例如,HTTP 和 gRPC 连接指标中包含 IP 地址和端口号的属性会被移除。
注意
如果配置,
disable_high_cardinality_metrics
仅适用于otelcol.exporter.*
和otelcol.receiver.*
组件。
导出的字段
导出以下字段,可被其他组件引用
名称 | 类型 | 描述 |
---|---|---|
input | otelcol.Consumer | 接受用于指标、日志或链路追踪的 otelcol.Consumer 数据。 |
input
接受任何遥测信号(指标、日志或链路追踪)的 otelcol.Consumer
数据。
组件健康状态
otelcol.processor.groupbyattrs
仅在给定无效配置时报告为不健康。
调试信息
otelcol.processor.groupbyattrs
不暴露任何组件特定的调试信息。
调试指标
otelcol.processor.groupbyattrs
不暴露任何组件特定的调试指标。
示例
对指标进行分组
考虑以下指标,所有指标最初都关联到同一个资源
Resource {host.name="localhost",source="prom"}
Metric "gauge-1" (GAUGE)
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-B",id="eth0"}
Metric "gauge-1" (GAUGE) // Identical to previous Metric
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-B",id="eth0"}
Metric "mixed-type" (GAUGE)
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-B",id="eth0"}
Metric "mixed-type" (SUM)
DataPoint {host.name="host-A",id="eth0"}
DataPoint {host.name="host-A",id="eth0"}
Metric "dont-move" (Gauge)
DataPoint {id="eth0"}
通过以下配置,groupbyattrs 将根据 host.name
属性的值,将指标重新关联到 host-A
或 host-B
。
otelcol.processor.groupbyattrs "default" {
keys = [ "host.name" ]
output {
metrics = [otelcol.exporter.otlp.default.input]
}
}
因此,处理器的输出将是
Resource {host.name="localhost",source="prom"}
Metric "dont-move" (Gauge)
DataPoint {id="eth0"}
Resource {host.name="host-A",source="prom"}
Metric "gauge-1"
DataPoint {id="eth0"}
DataPoint {id="eth0"}
DataPoint {id="eth0"}
DataPoint {id="eth0"}
Metric "mixed-type" (GAUGE)
DataPoint {id="eth0"}
DataPoint {id="eth0"}
Metric "mixed-type" (SUM)
DataPoint {id="eth0"}
DataPoint {id="eth0"}
Resource {host.name="host-B",source="prom"}
Metric "gauge-1"
DataPoint {id="eth0"}
DataPoint {id="eth0"}
Metric "mixed-type" (GAUGE)
DataPoint {id="eth0"}
此输出演示了 otelcol.processor.groupbyattrs
在各种情况下的工作方式
gauge-1
(GAUGE) 指标的数据点最初被拆分到 2 个指标实例下,并在输出中被合并。mixed-type
(GAUGE) 和mixed-type
(SUM) 指标的数据点未合并到同一个指标下,因为它们的数据类型不同。dont-move
指标的数据点没有host.name
属性,因此保留在原始资源下。- 新资源继承了原始资源的属性(
source="prom"
),以及来自已处理指标的指定属性(host.name="host-A"
或host.name="host-B"
)。 - 在新资源上设置的指定“分组”属性也从指标数据点中移除。
- 虽然在上述示例中未显示,但处理器也会将匹配插桩库下的记录集合合并。
压缩
有时遥测数据由于存在多个重复的 ResourceSpans/ResourceLogs/ResourceMetrics 对象而变得碎片化。这会导致额外的内存消耗、增加的处理成本、低效的序列化以及导出请求的增加。在这种情况下,可以使用 otelcol.processor.groupbyattrs
来压缩具有匹配资源和插桩库属性的数据。
例如,考虑此输入数据
Resource {host.name="localhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=1, ...}
InstrumentationLibrary {name="OtherLibrary"}
Spans
Span {span_id=2, ...}
Resource {host.name="localhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=3, ...}
Resource {host.name="localhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=4, ...}
Resource {host.name="otherhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=5, ...}
您可以使用其默认配置的 otelcol.processor.groupbyattrs
来压缩数据
otelcol.processor.groupbyattrs "default" {
output {
metrics = [otelcol.exporter.otlp.default.input]
}
}
输出将是
Resource {host.name="localhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=1, ...}
Span {span_id=3, ...}
Span {span_id=4, ...}
InstrumentationLibrary {name="OtherLibrary"}
Spans
Span {span_id=2, ...}
Resource {host.name="otherhost"}
InstrumentationLibrary {name="MyLibrary"}
Spans
Span {span_id=5, ...}
兼容组件
otelcol.processor.groupbyattrs
可以接受来自以下组件的参数
otelcol.processor.groupbyattrs
具有可由以下组件消费的导出
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。请参考链接文档了解更多详情。