RousselTMLEARNING

Article · Alloy: From Discovery to Expertise

Configuration Blocks

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"
  }
}
ElementRoleExample
Component nameThe type, in dotted notationprometheus.scrape
LabelDistinguishes two instances of a type; required"app"
AttributeA value, with =scrape_interval = "30s"
Nested blockA structured setting, with no =basic_auth { … }
ReferenceA value exported by another componentdiscovery.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.alloy to format, alloy validate config.alloy to check without running.

📄 Grafana Alloy: Syntax and Configuration (Alloy Language: River) →

My progress

  • ⏱ Estimated time : ≈ 7 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

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...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!