菜单
公开预览 开源

pyroscope.relabel

公开预览:这是一个公开预览组件。公开预览组件可能会发生破坏性变更,并可能被覆盖相同用例的等效功能替代。必须将 stability.level 标志设置为 public-preview 或更低才能使用此组件。

pyroscope.relabel 组件通过应用一个或多个 Relabeling 规则来重写传递给其接收器的每个性能剖析的标签集,并将结果转发给接收器列表。

如果没有定义规则或某些性能剖析不适用任何规则,则这些性能剖析将原封不动地转发给组件参数中传递的每个接收器。如果在应用 Relabeling 规则后没有标签残留,则该性能剖析将被丢弃。

pyroscope.relabel 最常见的用途是过滤性能剖析或标准化传递给一个或多个下游接收器的标签集。rule 块按照它们在配置文件中出现的顺序应用于每个性能剖析的标签集。

用法

alloy
pyroscope.relabel "<LABEL>" {
    forward_to = <RECEIVER_LIST>

    rule {
        ...
    }

    ...
}

参数

您可以对 pyroscope.relabel 使用以下参数

名称类型描述默认值必需
forward_tolist(pyroscope.Appendable)重写标签后转发性能剖析的接收器列表
max_cache_sizenumber标签缓存中的最大条目数10000

您可以对 pyroscope.relabel 使用以下块

名称描述必需
rule应用于接收到的性能剖析条目的 Relabeling 规则。

rule

rule 块包含可以应用于输入指标的 Relabeling 规则的定义。如果定义了多个 rule 块,则转换按从上到下的顺序应用。

可以使用以下参数配置 rule。所有参数都是可选的。省略的字段采用其默认值。

名称类型描述默认值必需
actionstring要执行的 Relabeling 操作。replace
modulusuint用于计算哈希源标签值的模数的正整数。
regexstring一个有效的 RE2 表达式,支持带括号的捕获组。用于匹配从 source_labelseparator 字段组合中提取的值,或在 labelkeep/labeldrop/labelmap 操作期间过滤标签。(.*)
replacementstring如果正则表达式匹配提取的值,则执行正则表达式替换所用的值。支持先前捕获的组。"$1"
separatorstring用于连接 source_labels 中存在的值的分隔符。;
source_labelslist(string)要选择其值的标签列表。它们的内容使用 separator 连接,并与 regex 匹配。
target_labelstring结果值将写入的标签。

您可以使用以下操作

  • drop - 丢弃 regex 匹配使用 source_labelsseparator 提取的字符串的指标。
  • dropequal - 丢弃连接的 source_labelstarget_label 匹配的目标。
  • hashmod - 对连接的标签进行哈希处理,计算其模 modulus,并将结果写入 target_label
  • keep - 保留 regex 匹配使用 source_labelsseparator 提取的字符串的指标。
  • keepequal - 丢弃连接的 source_labelstarget_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} 符号引用正则表达式捕获组。

导出的字段

以下字段被导出,可以被其他组件引用

名称类型描述
receiverProfilesReceiver一个接受性能剖析进行 Relabeling 的接收器。
rules[]relabel.ConfigRelabeling 规则列表。

组件健康状况

如果配置无效,则 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): 已转发的性能剖析总数。

示例

alloy
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.relabel 具有可以被以下组件使用的导出

注意

连接某些组件可能没有意义,或者组件可能需要进一步配置才能使连接正常工作。请参阅链接的文档以获取更多详细信息。