Understand components
A component is an Alloy building block that performs one task, such as retrieving a secret, collecting metrics, processing data, or sending telemetry.
You create a component with a labeled block:
COMPONENT_NAME "LABEL" {
// Component arguments go here.
}The component name selects the type of work. The label identifies this instance of the component and distinguishes it from other instances of the same type.
For example, this local.file component reads a file from disk:
local.file "example" {
filename = "/tmp/example.txt"
}local.fileis a component name available in Alloy."example"is the label for this instance.filenameis an argument that configures which file to read.
Every component has two main parts:
- Arguments configure the component’s behavior. They are the attributes and nested blocks you write inside the component block.
- Exports are values that the running component makes available for other components to reference. You don’t declare exports in the configuration. The component type provides them.
Optional arguments can have defaults. A component can have zero or more exports. For the local.file example above, you only wrote the filename argument. The local.file component type also provides a content export that holds the latest contents of that file.
When one component uses another component’s export as an argument, the reference creates a connection between them. These connections are how components become pipelines that collect, process, and send telemetry. The next milestone traces one of those references.
The logging block from the previous milestone isn’t a component: it’s a special configuration block for Alloy itself. Component blocks use component names available in Alloy, such as local.file, and require a label. Special configuration blocks like logging don’t use a label.
You can now distinguish a component’s inputs from its outputs: arguments tell a component how to behave, and exports let other components use values that it provides.