pyroscope.relabel
公开预览:这是一个公开预览组件。公开预览组件可能会发生破坏性变更,并可能被覆盖相同用例的等效功能替代。必须将
stability.level
标志设置为public-preview
或更低才能使用此组件。
pyroscope.relabel
组件通过应用一个或多个 Relabeling 规则来重写传递给其接收器的每个性能剖析的标签集,并将结果转发给接收器列表。
如果没有定义规则或某些性能剖析不适用任何规则,则这些性能剖析将原封不动地转发给组件参数中传递的每个接收器。如果在应用 Relabeling 规则后没有标签残留,则该性能剖析将被丢弃。
pyroscope.relabel
最常见的用途是过滤性能剖析或标准化传递给一个或多个下游接收器的标签集。rule
块按照它们在配置文件中出现的顺序应用于每个性能剖析的标签集。
用法
pyroscope.relabel "<LABEL>" {
forward_to = <RECEIVER_LIST>
rule {
...
}
...
}
参数
您可以对 pyroscope.relabel
使用以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
forward_to | list(pyroscope.Appendable) | 重写标签后转发性能剖析的接收器列表 | 是 | |
max_cache_size | number | 标签缓存中的最大条目数 | 10000 | 否 |
块
您可以对 pyroscope.relabel
使用以下块
名称 | 描述 | 必需 |
---|---|---|
rule | 应用于接收到的性能剖析条目的 Relabeling 规则。 | 否 |
rule
rule
块包含可以应用于输入指标的 Relabeling 规则的定义。如果定义了多个 rule
块,则转换按从上到下的顺序应用。
可以使用以下参数配置 rule
。所有参数都是可选的。省略的字段采用其默认值。
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
action | string | 要执行的 Relabeling 操作。 | replace | 否 |
modulus | uint | 用于计算哈希源标签值的模数的正整数。 | 否 | |
regex | string | 一个有效的 RE2 表达式,支持带括号的捕获组。用于匹配从 source_label 和 separator 字段组合中提取的值,或在 labelkeep/labeldrop/labelmap 操作期间过滤标签。 | (.*) | 否 |
replacement | string | 如果正则表达式匹配提取的值,则执行正则表达式替换所用的值。支持先前捕获的组。 | "$1" | 否 |
separator | string | 用于连接 source_labels 中存在的值的分隔符。 | ; | 否 |
source_labels | list(string) | 要选择其值的标签列表。它们的内容使用 separator 连接,并与 regex 匹配。 | 否 | |
target_label | string | 结果值将写入的标签。 | 否 |
您可以使用以下操作
drop
- 丢弃regex
匹配使用source_labels
和separator
提取的字符串的指标。dropequal
- 丢弃连接的source_labels
与target_label
匹配的目标。hashmod
- 对连接的标签进行哈希处理,计算其模modulus
,并将结果写入target_label
。keep
- 保留regex
匹配使用source_labels
和separator
提取的字符串的指标。keepequal
- 丢弃连接的source_labels
与target_label
不匹配的目标。labeldrop
- 将regex
与所有标签名称匹配。任何匹配的标签都将从指标的标签集中删除。labelkeep
- 将regex
与所有标签名称匹配。任何不匹配的标签都将从指标的标签集中删除。labelmap
- 将regex
与所有标签名称匹配。任何匹配的标签将根据replacement
字段的内容进行重命名。lowercase
- 将target_label
设置为连接的source_labels
的小写形式。replace
- 将regex
与连接的标签匹配。如果匹配,则使用replacement
字段的内容替换target_label
的内容。uppercase
- 将target_label
设置为连接的source_labels
的大写形式。
注意
可以使用
$CAPTURE_GROUP_NUMBER
或${CAPTURE_GROUP_NUMBER}
符号引用正则表达式捕获组。
导出的字段
以下字段被导出,可以被其他组件引用
名称 | 类型 | 描述 |
---|---|---|
receiver | ProfilesReceiver | 一个接受性能剖析进行 Relabeling 的接收器。 |
rules | []relabel.Config | Relabeling 规则列表。 |
组件健康状况
如果配置无效,则 pyroscope.relabel
会被报告为不健康。
调试指标
pyroscope_relabel_cache_hits
(counter): 缓存命中总数。pyroscope_relabel_cache_misses
(counter): 缓存未命中总数。pyroscope_relabel_cache_size
(gauge): Relabel 缓存的总大小。pyroscope_relabel_profiles_dropped
(counter): 因 Relabeling 规则丢弃的性能剖析总数。pyroscope_relabel_profiles_processed
(counter): 已处理的性能剖析总数。pyroscope_relabel_profiles_written
(counter): 已转发的性能剖析总数。
示例
pyroscope.receive_http "default" {
forward_to = [pyroscope.relabel.filter_profiles.receiver]
http {
listen_address = "0.0.0.0"
listen_port = 9999
}
}
pyroscope.relabel "filter_profiles" {
forward_to = [pyroscope.write.staging.receiver]
// This creates a consistent hash value (0 or 1) for each unique combination of labels
// Using multiple source labels provides better sampling distribution across your profiles
rule {
source_labels = ["env"]
target_label = "__tmp_hash"
action = "hashmod"
modulus = 2
}
// This effectively samples ~50% of profile series
// The same combination of source label values will always hash to the same number,
// ensuring consistent sampling
rule {
source_labels = ["__tmp_hash"]
action = "drop"
regex = "^1$"
}
}
pyroscope.write "staging" {
endpoint {
url = "http://pyroscope-staging:4040"
}
}
兼容组件
pyroscope.relabel
可以接受来自以下组件的参数
- 导出 Pyroscope
ProfilesReceiver
的组件
pyroscope.relabel
具有可以被以下组件使用的导出
- 使用 Pyroscope
ProfilesReceiver
的组件
注意
连接某些组件可能没有意义,或者组件可能需要进一步配置才能使连接正常工作。请参阅链接的文档以获取更多详细信息。