菜单
开源 此页面内容适用于开源版本。

引用组件导出

通过引用导出,Alloy 可以使用表达式动态配置和连接组件。虽然组件可以独立工作,但当一个组件的行为和数据流依赖于另一个组件的导出时,它们会更有效,从而创建依赖关系。

此类引用只能出现在另一个组件的参数或配置块的字段中。组件不能引用自身。

使用引用

通过将组件名称、标签和命名导出用点连接起来即可创建引用。

例如,您可以将标记为 `target` 的 `local.file` 组件导出的文件内容引用为 `local.file.target.content`。类似地,标记为 `onprem` 的 `prometheus.remote_write` 组件实例将其指标接收器暴露为 `prometheus.remote_write.onprem.receiver`。

以下示例演示了一些引用。

alloy
local.file "target" {
  filename = "/etc/alloy/target"
}

prometheus.scrape "default" {
  targets    = [{ "__address__" = local.file.target.content }]
  forward_to = [prometheus.remote_write.onprem.receiver]
}

prometheus.remote_write "onprem" {
  endpoint {
    url = "http://prometheus:9009/api/prom/push"
  }
}

在上面的示例中,您通过编写几个 Alloy 表达式创建了一个简单的管线。

Example of a pipeline

值解析后,必须与分配到的属性的类型匹配。虽然您只能使用基本的 Alloy 类型配置属性,但组件的导出可以使用特殊的内部 Alloy 类型,例如 Secrets 或 Capsules,它们提供附加功能。