Trace a component reference
Read the following example to trace how one component’s export supplies another component’s argument. You don’t need to run this configuration.
local.file "example" {
filename = sys.env("HOME") + "/file.txt"
}
prometheus.remote_write "local_prom" {
endpoint {
url = "http://localhost:9090/api/v1/write"
basic_auth {
username = "admin"
password = local.file.example.content
}
}
}This example has two components. You already met local.file, which reads a file and exports its contents. prometheus.remote_write sends metrics to a Prometheus-compatible endpoint. Inside it, endpoint and basic_auth are nested argument blocks that group related settings.
Start with the local.file "example" block:
local.fileis the component name.exampleis the component label.filenameis an argument.sys.env("HOME") + "/file.txt"is an expression that produces the filename.
As in the previous milestone, this component type also provides a content export. That export isn’t written in the block. Other components reference it.
Now find that reference in the sample. The password argument inside basic_auth is set to local.file.example.content.
Read that expression from left to right:
local.fileidentifies the component type.exampleidentifies the labeled instance.contentidentifies the export.
The component type and label together, local.file.example, are the component’s fully qualified name.
That reference means Alloy evaluates local.file.example first, then supplies its content export as the password argument. This single reference creates a dependency from prometheus.remote_write.local_prom to local.file.example.
You can now trace a component reference by finding where an export is used as an argument, then reading the component name, label, and export in that expression.