Looking to centrally manage all alloy configuration files for my environment in a git repo for version control. I have windows and linux endpoints, some with docker containers running as well.
import.git works okay, but will cause alloy to crash if the matching file is not found.
The best I can come up with is to deploy alloy to my clients with a generic alloy.config like so:
logging {
level = info
}
import.http "main" {
url = "https://myserver.lan/" + contants.hostname + ".alloy"
}
main.config "default" { }
then the <hostname>.alloy wouldn’t exist yet, so my HTTP server would serve an “empty” config as a response, allowing it to import without error:
declare "config" { }
and when I update the repo to configure for that host (ex. a linux host):
declare "config" {
prometheus.exporter.unix "integrations_node_exporter" {
enable_collectors = ["meminfo"]
}
prometheus.scrape "integrations_node_exporter" {
scrape_interval = "15s"
targets = prometheus.exporter.unix.integrations_node_exporter.targets
forward_to = [prometheus.remote_write.local.receiver]
}
prometheus.remote_write "local" {
endpoint {
url = "http://prometheus:9090/api/v1/write"
}
}
}
which would then get pulled by the client and imported and ran if the syntax is all good, and if there is an error then it wouldn’t update, but also wouldn’t crash alloy.
Ideally I’d like to make all of this modular, since a lot of hosts would share the same components. Like if all linux hosts would import, say, a linux.alloy config as well, which would always have the prometheus.exporter.unix stuff. Then any custom configurations would be included in the <hostname>.alloy config like monitor custom log files or whatever.
How would one go about this? Do I just make one massive config.alloy with tons of declare blocks and then call the ones I need? Or do I make placeholders like so:
import.http "main" {
url = "https://myserver.lan/" + contants.hostname + ".alloy"
}
import.http "second" {
url = "https://myserver.lan/" + contants.hostname + "_2.alloy"
}
import.http "third" {
url = "https://myserver.lan/" + contants.hostname + "_3.alloy"
}
import.http "linux" {
url = "https://myserver.lan/linux.alloy"
}
main.config "stuff" { }
second.config "stuff" { }
third.config "stuff" { }
linux.config "stuff" { }
Maybe I am overlooking a feature that does this, or just overthinking the problem. Any guidance or ideas are welcome. Cheers!