otelcol.processor.groupbyattrs
otelcol.processor.groupbyattrs
接受来自其他 otelcol
组件的 span、指标和追踪,并将它们分组到相同的资源下。
注意
otelcol.processor.groupbyattrs
是对上游 OpenTelemetry Collectorgroupbyattrs
处理器的封装。如有必要,错误报告或功能请求将被重定向到上游仓库。
我们建议您将 groupbyattrs 处理器与 otelcol.processor.batch 一起使用,作为连续的步骤。这将通过将记录分组到匹配的资源/Instrumentation Library 下来减少数据的碎片化。
您可以通过为多个 otelcol.processor.groupbyattrs
组件赋予不同的标签来指定它们。
用法
otelcol.processor.groupbyattrs "LABEL" {
output {
metrics = [...]
logs = [...]
traces = [...]
}
}
参数
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
keys | list(string) | 将用于将 span、日志记录或指标数据点分组在一起的键。 | [] | 否 |
keys
是一个字符串数组,用于对数据进行分组。如果为空,则处理器执行压缩并将所有 span 重新关联到匹配的 Resource 和 InstrumentationLibrary。
块
在 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 | 否 |
level | 字符串 | 控制包装的收集器发出的指标的详细程度。 | "detailed" | 否 |
disable_high_cardinality_metrics
是 Grafana Alloy 中与 OpenTelemetry Collector 中的 telemetry.disableHighCardinalityMetrics
功能门等效的项。它会删除可能导致高基数指标的属性。例如,HTTP 和 gRPC 连接指标中包含 IP 地址和端口号的属性将被删除。
注意
如果配置了
disable_high_cardinality_metrics
,则仅适用于otelcol.exporter.*
和otelcol.receiver.*
组件。
level
是 Alloy 中与 OpenTelemetry Collector 中的 telemetry.metrics.level
功能门等效的项。可能的值为 "none"
、"basic"
、"normal"
和 "detailed"
。
导出的字段
以下字段已导出,可供其他组件引用
名称 | 类型 | 描述 |
---|---|---|
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) 指标的 DataPoints 最初在 2 个 Metric 实例下拆分,并在输出中合并。mixed-type
(GAUGE) 和mixed-type
(SUM) 指标的 DataPoints 未在同一 Metric 下合并,因为它们的数据类型不同。dont-move
指标 DataPoints 没有host.name
属性,因此保留在原始资源下。- 新的资源继承了原始资源 (
source="prom"
) 的属性,以及来自处理后的指标的指定属性 (host.name="host-A"
或host.name="host-B"
)。 - 在新的资源上设置的指定的“分组”属性也会从指标 DataPoints 中删除。
- 虽然在上面的示例中未显示,但处理器还会合并匹配的 InstrumentationLibrary 下的记录集合。
压缩
有时,遥测数据可能会由于多个重复的 ResourceSpans/ResourceLogs/ResourceMetrics 对象而变得碎片化。这会导致额外的内存消耗、增加的处理成本、低效的序列化和导出请求的增加。在这种情况下,可以使用 otelcol.processor.groupbyattrs
来压缩具有匹配的 Resource 和 InstrumentationLibrary 属性的数据。
例如,考虑以下输入数据
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
具有可供以下组件使用的导出
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。有关更多详细信息,请参阅链接的文档。