Alloy configuration syntax
Grafana Alloy dynamically configures and connects components using the Alloy configuration syntax. Alloy collects, transforms, and delivers telemetry data. Each configuration component performs a specific task or defines data flow and component connections.

The following example demonstrates the basic concepts and how an Alloy configuration forms a pipeline.
The Alloy syntax reduces configuration errors by making files easier to read and write. It uses blocks, attributes, and expressions. You can copy and paste blocks from the documentation to get started quickly.
The Alloy syntax is declarative, so the order of components, blocks, and attributes doesn’t matter. The relationships between components determine the pipeline’s operation sequence.
Blocks
Use Blocks to configure components and groups of attributes. Each block can include attributes or nested blocks. Blocks represent steps in the pipeline.
prometheus.remote_write "default" {
endpoint {
url = "http://localhost:9009/api/prom/push"
}
}
The preceding example contains two blocks:
prometheus.remote_write "default"
: A labeled block that creates aprometheus.remote_write
component. The label is the string"default"
.endpoint
: An unlabeled block inside the component that configures an endpoint for sending metrics. This block sets theurl
attribute to specify the endpoint.
Attributes
Use Attributes to configure individual settings.
Attributes follow the format ATTRIBUTE_NAME = ATTRIBUTE_VALUE
.
The following example sets the log_level
attribute to "debug"
.
log_level = "debug"
Expressions
Use expressions to compute attribute values.
Simple expressions include constants like "debug"
, 32
, or [1, 2, 3, 4]
.
The Alloy syntax supports complex expressions, such as:
- Referencing component exports:
local.file.password_file.content
- Mathematical operations:
1 + 2
,3 * 4
,(5 * 6) + (7 + 8)
- Equality checks:
local.file.file_a.content == local.file.file_b.content
- Calling functions from the standard library:
sys.env("HOME")
retrieves theHOME
environment variable.
You can use expressions for any attribute in a component definition.
Reference component exports
The most common expression references a component’s exports, such as local.file.password_file.content
.
You form a reference by combining the component’s name (for example, local.file
), label (for example, password_file
), and export name (for example, content
), separated by periods.
Configuration syntax design goals
Alloy is:
- Fast: The configuration language is fast and the controller evaluates changes quickly.
- Simple: The configuration language is easy to read and write, reducing the learning curve.
- Easy to debug: The configuration language provides detailed error information.
The Alloy configuration syntax is a distinct language with custom syntax and features, such as first-class functions.
- Blocks group related settings and typically represent component creation.
Blocks have a name consisting of identifiers separated by
.
, an optional user label, and a body containing attributes and nested blocks. - Attributes appear within blocks and assign values to names.
- Expressions represent values, either literally or by referencing and combining other values. You use expressions to compute attribute values.
Tooling
You can use the following tools to write Alloy configuration files:
- Editor support for:
- Code formatting with the
alloy fmt
command