Attributes, blocks, and expressions for mastering alloy configuration (alloy config) via alloy river.
1. Configuration blocks #
Attributes, blocks and expressions in River language.
Anatomy of a block #
Available in: ✓ OSS ✓ Enterprise ✓ Cloud
// component name: prometheus.scrape label: "app"
prometheus.scrape "app" {
// attribute: a value
scrape_interval = "30s"
// reference to another component's export
targets = discovery.relabel.pods.output
forward_to = [prometheus.remote_write.mimir.receiver]
// nested block: a structured setting
basic_auth {
username = "collecte"
password = sys.env("SCRAPE_PASSWORD")
}
}
discovery.relabel "pods" {
targets = []
}
prometheus.remote_write "mimir" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}| Element | Role | Example |
|---|---|---|
| Component name | The type, in dotted notation | prometheus.scrape |
| Label | Distinguishes two instances of a type; required | "app" |
| Attribute | A value, with = | scrape_interval = "30s" |
| Nested block | A structured setting, with no = | basic_auth { … } |
| Reference | A value exported by another component | discovery.relabel.pods.output |
Attribute or nested block? #
Each component's documentation states which, and the mistake is common: endpoint = { … } fails because endpoint is a block. targets, on the other hand, is an attribute expecting an array of objects.
General configuration blocks #
A few blocks are not components: they have no label and configure Alloy itself.
logging {
level = "info"
format = "logfmt"
}
livedebugging {
enabled = true
}livedebugging enables live data observation in the UI. Remember to disable it outside diagnostic phases.Commas #
In a multi-line array or object, add a comma after the last element: Alloy accepts it, and later additions change only one line in Git. alloy fmt then aligns everything.
Raw strings #
Expressions containing quotes, such as OTTL statements, are more readable in backticks: nothing needs escaping.
otelcol.processor.transform "noms" {
error_mode = "ignore"
trace_statements {
context = "span"
statements = [
`set(name, "GET /produits/{id}") where IsMatch(name, "^GET /produits/[0-9]+$")`,
]
}
output {
traces = []
}
}Useful commands:alloy fmt -w config.alloyto format,alloy validate config.alloyto check without running.
My progress
Sign in to track your progress and take notes. Sign in
💬 Recent discussions about this course
- Alloy : recevoir de l'OTLP et l'envoyer vers Tempo et Mimir✓ solved · 1 reply(ies)
Ask a question about this lesson →See all discussions about this course
Course Glossary
Grafana Alloy
An open-source, vendor-neutral telemetry collector designed to replace Grafana Agent, fully compatible with OpenTelemetry (OTel).
Recommended Articles
Grafana Alloy best practices: optimizing your telemetry collection
Discover the golden rules for configuring Grafana Alloy robustly: modularity, secrets management,...
Grafana Alloy environment variables: GOMEMLIMIT, sys.env and OTEL_RESOURCE_ATTRIBUTES
Which variables does Grafana Alloy actually read? GOMEMLIMIT, HTTP_PROXY, sys.env, OTEL_RESOURCE_...
Grafana Alloy: collecting system metrics and local logs
Learn how to configure Grafana Alloy to monitor the server it runs on, with a focus on configurat...
Grafana Alloy: The importance of Self-Monitoring
Discover why and how to configure Grafana Alloy so that it monitors itself, collecting its own lo...
Grafana Alloy: collecting and transforming telemetry
Learn how to use Grafana Alloy to collect, transform and route logs, metrics and traces. Discover...
Grafana Alloy components reference
A complete reference guide to all the components available in Grafana Alloy, organized by categor...
OpenTelemetry Collector, Grafana Alloy and Bindplane: comparing three approaches to telemetry pipelines
Detailed comparison of three ways to manage telemetry pipelines: the OpenTelemetry Collector in Y...
Grafana Alloy vs OpenTelemetry Collector: Which One Should You Choose?
A detailed comparison between Grafana Alloy and the OpenTelemetry Collector. Discover the strengt...
The LGTM stack (Loki, Grafana, Tempo, Mimir): architecture and setup
Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces, Mimir for m...