Loading default alloy config via http

Hi there!

I’m trying to figure out how to load a default Alloy config via http (import.http?) and apply some variables from a local file on top of that, but I just don’t get how to do it.

Is there maybe a Big Brain out there who can explain? :slight_smile:

You can load a default config and load variables into it. You need to do it by first importing the config, then use custom module to load variables. See Modules | Grafana Alloy documentation and Custom components | Grafana Alloy documentation.

Here is an example.Say you have a default config that has a generic mimir endpoint, and you want to load a custom scrape configuration from an HTTP endpoint into it, you might do something like this (mock config, not tested):

config.alloy:

prometheus.remote_write "_mimir_forwarder" {
  endpoint {
    url = "<MIMIR_URL>"
        
    basic_auth {
      username = "USERNAME"
      password = "PASSWORD"
    }
  }
}

remote.http "my_custom_config" {
  path           = "<PATH>"
  poll_frequency = "10m"
}

import.string "my_custom_config_import" {
  content = remote.http.my_custom_config.content
}

my_custom_config_import.my_custom_config "this" {
  metrics_output = [prometheus.remote_write._mimir_forwarder.receiver]
}

http config:

declare "my_app" {
  argument "metrics_output" {
    optional = false
    comment  = "Where to send collected metrics."
  }

  discovery.dns "my_app" {
    names = ["<DISCOVERY_RECORD>"]
    type  = "SRV"
  }

  prometheus.scrape "my_app" {
    scrape_interval = "10s"
    targets         = discovery.dns.my_app.targets
    forward_to      = [prometheus.relabel.my_app.receiver]
  }

  prometheus.relabel "my_app" {
    forward_to = argument.metrics_output.value

    rule {
      action       = "replace"
      replacement  = "my_app"
      target_label = "app"
    }
  }
}

It’s pretty neat, but honestly unless you have a very good reason to do this, I’d stick with some sort of configuration management solution instead so you can keep things simple and easy.