Skip to content
This repository was archived by the owner on Jul 28, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ac15116
Merge main -> dev.dynamic_configuration (#1270)
mattdurham Jan 13, 2022
cc2350e
Main merge dynamic (#1305)
mattdurham Jan 24, 2022
57f934b
Main merge dynamic (#1307)
mattdurham Jan 24, 2022
d74fe82
[RFC] Dynamic Documentation (#1308)
mattdurham Feb 3, 2022
935116d
Code to support dynamic configuration. (#1360)
mattdurham Feb 24, 2022
4c2e077
Dyn main merge (#1423)
mattdurham Feb 25, 2022
801d5e8
Main merge 2 (#1426)
mattdurham Feb 25, 2022
8fac860
Main merge 2 (#1427)
mattdurham Feb 25, 2022
3013658
merging again
mattdurham Feb 25, 2022
fc5130d
Merge main 2 (#1428)
mattdurham Feb 25, 2022
1cff117
Merge branch 'dev.dynamic_configuration' of github.com:grafana/agent …
mattdurham Feb 25, 2022
e21cb89
Revert "Dyn main merge (#1423)"
mattdurham Feb 25, 2022
87df751
Merge pull request #1430 from grafana/revert_change
mattdurham Feb 25, 2022
1153a02
main merge
mattdurham Feb 25, 2022
3bf336a
Merges from main
mattdurham Feb 25, 2022
7b46383
Linting errors fixed
mattdurham Feb 25, 2022
aa17a8b
Merge pull request #1431 from grafana/dev_merge
mattdurham Feb 25, 2022
7120f01
Doc movement
mattdurham Feb 25, 2022
3810531
Merge pull request #1433 from grafana/dev_merge
mattdurham Feb 25, 2022
90bd7f1
Play with page file. (#1434)
mattdurham Mar 1, 2022
ec4bbfe
Revert "Play with page file. (#1434)"
mattdurham Mar 1, 2022
67ba39a
Merge pull request #1441 from grafana/revert-1434-dev_merge
mattdurham Mar 1, 2022
cfe29ac
Merge branch 'main' into merge_cadvisor_changes
mattdurham Mar 1, 2022
8d7f392
Merge cadvisor
mattdurham Mar 1, 2022
792edb9
Merge pull request #1442 from grafana/merge_cadvisor_changes
mattdurham Mar 1, 2022
4babc3b
Adding remote_write test back
mattdurham Mar 1, 2022
4385b52
Merge pull request #1443 from grafana/merge_cadvisor_changes
mattdurham Mar 1, 2022
a99183d
Update CHANGELOG.md
mattdurham Mar 1, 2022
442c6ba
Merge pull request #1444 from grafana/update_changelog
mattdurham Mar 1, 2022
9bd63e2
Merge branch 'main' into merge_changelog
mattdurham Mar 1, 2022
586eb65
Merge pull request #1445 from grafana/merge_changelog
mattdurham Mar 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
name: Test
strategy:
matrix:
platform: [macos-latest, windows-latest]
platform: [macos-latest, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go 1.17
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

- [ENHANCEMENT] Upgrade to loki v2.4.2. The following metrics will now be prefixed with `agent_dskit_` instead of `cortex_`: `cortex_kv_request_duration_seconds`, `cortex_member_consul_heartbeats_total`, `cortex_member_ring_tokens_owned`, `cortex_member_ring_tokens_to_own`, `cortex_ring_member_ownership_percent`, `cortex_ring_members`, `cortex_ring_oldest_member_timestamp`, `cortex_ring_tokens_owned`, `cortex_ring_tokens_total`. (@rlankfo)

- [ENHANCEMENT] Introduce EXPERIMENTAL support for dynamic configuration. (@mattdurham)

- [FEATURE] Added config read API support to GrafanaAgent Custom Resource Definition.

- [FEATURE] Added consulagent_sd to target discovery. (@chuckyz)

- [BUGFIX] Ensure singleton integrations are honored in v2 integrations (@mattdurham)

# v0.23.0 (2022-01-13)

- [ENHANCEMENT] Go 1.17 is now used for all builds of the Agent. (@tpaschalis)
Expand Down
37 changes: 37 additions & 0 deletions cmd/agentctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"gopkg.in/yaml.v2"

// Adds version information
_ "github.com/grafana/agent/pkg/build"
"github.com/grafana/agent/pkg/client/grafanacloud"
Expand Down Expand Up @@ -60,6 +62,7 @@ func main() {
samplesCmd(),
operatorDetachCmd(),
cloudConfigCmd(),
templateDryRunCmd(),
)

_ = cmd.Execute()
Expand Down Expand Up @@ -474,6 +477,40 @@ config that may be used with this agent.`,
return cmd
}

func templateDryRunCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "template-parse [directory]",
Short: "dry run dynamic configuration",
Long: `This will load the dynamic configuration, load configs, run templates and then output the full config as yaml`,
Args: cobra.ExactArgs(1),

RunE: func(_ *cobra.Command, args []string) error {
cmf, err := config.NewDynamicLoader()
if err != nil {
return err
}
c := &config.Config{}
err = cmf.LoadConfigByPath(args[0])
if err != nil {
return err
}
err = cmf.ProcessConfigs(c)
if err != nil {
return fmt.Errorf("error processing config templates %s", err)
}

outBytes, err := yaml.Marshal(c)
if err != nil {
return err
}
fmt.Println(string(outBytes))
return nil
},
}

return cmd
}

func must(err error) {
if err != nil {
panic(err)
Expand Down
127 changes: 127 additions & 0 deletions docs/user/configuration/dynamic-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Dynamic Configuration - Experimental

**This is experimental and subject to change at anytime, feedback is much appreciated. This is a feature that MAY NOT make it production.**

Dynamic Configuration is the combination of two things:

* Loading from multiple files
* Using templates and datasources

Both of these make heavy use of the excellent [gomplate](https://github.com/hairyhenderson/gomplate). The goal is
that as the configuration grows that it can be split it up into smaller segments to allow better readability and handling.
The configurations cannot be patched in any order and instead are allowed at several levels.

The second goal is to allow the use of templating, functions for [gomplate doc](https://docs.gomplate.ca/) go into detail
on what functions are available.

## Configuration

Location of the dynamic configuration is used via the feature flag `dynamic-config`, then it will use `-config.dynamic-config-path` to
load the configuration for dynamic configuration.

```yaml
# Sources to pull template values
datasources:
[- <sources_config>]

# Locations to use searching for templates, the system does NOT look into subdirectories. Follows gomplate schema
# from [gomplate datasources](https://docs.gomplate.ca/datasources/). File and S3/GCP templates are currently supported
template_paths:
[ - string ]

# Filters allow you to override the default naming convention

agent_filter: string # defaults to agent-*.yml
server_filter: string # defaults to server-*.yml
metrics_filter: string # defaults to metrics-*.yml
metrics_instance_filter: string # defaults to metrics_instances-*.yml
integrations_filter: string # defaults to integrations-*.yml
logs_filter: string # defaults to logs-*.yml
traces_filter: string # defaults to traces-*.yml
```

### sources_config
```yaml
# Name of the source to use when templating
name: string

# Path to datasource using schema from [gomplate datasources](https://docs.gomplate.ca/datasources/)
url: string

```

## Templates

Note when adding a template you MUST NOT add the type as the top level yaml field. For instance if using traces:

Incorrect

```yaml
traces:
configs:
- name: default
automatic_logging:
backend: loki
loki_name: default
spans: true
```

Correct

```yaml
configs:
- name: default
automatic_logging:
backend: loki
loki_name: default
spans: true
```

Configurations are loaded in the order as they are listed below.

### Agent


Agent template is the standard agent configuration file in its entirety. The default filter is `agent-*.yml`. Only
one file is supported. This is processed first then any subsequent configurations found REPLACE the values here, it is
not additive.

Reference {{< relref "./" >}})

### Server

The default filter is `server-*.yml`, only ONE server file is supported.

Reference {{< relref "./server-config.md" >}})


### Metrics

The default filter is `metrics-*.yml`, only ONE metrics file is supported.

Reference {{< relref "./metrics-config.md" >}})

### Metric Instances

The default filter is `metrics_instances-*.yml`. Any metric instances are appended to the instances defined in Metrics above. Any number of metric instance files are supporter.

Reference {{< relref "./metrics-config.md#metrics_instance_config" >}}) in the metrics instance


### Integrations

The default filter is `integrations-*.yml`, these support more than one file, and multiple integrations can be defined in a file. Do not assume any order of loading for integrations. For any integration that is a singleton, loading multiple of those will result in an error.

Reference {{< relref "./integrations/" >}})

### Traces

The default filter is `traces-*.yml`. This supports ONE file.

Reference {{< relref "./traces-config.md" >}})

### Logs

The default filter is `logs-*.yml`. This supports ONE file.

Reference {{< relref "./logs-config.md" >}})
64 changes: 64 additions & 0 deletions docs/user/cookbook/dynamic-configuration/01_Basics/01_Structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 01 Structure

Dynamic Configuration uses a series of files to load templates. This example will show how they all combine together. Running the below command will combine all the templates into the final.yml. Any failure while loading the config will revert to the original config, or if this is the initial load Grafana Agent will quit.

`docker run -v ${PWD}/:/etc/grafana grafana/agentctl:latest template-parse file:///etc/grafana/01_config.yml`

## Dynamic Configuration

[config.yml](01_config.yml)

```yaml
template_paths:
- "file:///etc/grafana/01_assets"
```

Tells the Grafana Agent where to load files from. It is important to note that dynamic configuration does NOT traverse directories. It will look at the directory specified only, if you need more directories then add them to the `template_paths` array. NOTE, if no protocol specified ie `file://` above, then file access will be assumed. `file:///etc/grafana/01_assets` is equivalent to `//etc/grafana/01_assets`

## Agent

Dynamic Configuration will find the first file matching pattern `agent-*.yml` and load that as the base. You can only have one agent template. If multiple matching templates are found then the configuration will fail to load.

[agent-1.yml](01_assets/agent-1.yml)

```yaml
server:
http_listen_port: 12345
log_level: debug
metrics:
wal_directory: /tmp/grafana-agent-normal
global:
scrape_interval: 60s
remote_write:
- url: https://prometheus-us-central1.grafana.net/api/prom/push
basic_auth:
username: 12345
password: secretpassword
integrations:
node_exporter:
enabled: true
agent:
enabled: true
```

## Server

Dynamic configuration will find the first file matching pattern `server-*.yml` and replace the `Server` config block in
the Agent Configuration. Note that you do NOT include the `server:` tag, dynamic configuration knows by the name that it
is a configuration block.

You can only have 1 server template.

[server-1.yml](01_assets/server-1.yml)


```yaml
http_listen_port: 12345
log_level: info
```

## Final

[final.yml](01_assets/final.yml)

In the above example the `log_level: debug` block will be replaced with `log_level: info` from the server-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server:
http_listen_port: 12345
log_level: debug
metrics:
wal_directory: /tmp/grafana-agent-normal
global:
scrape_interval: 60s
remote_write:
- url: https://prometheus-us-central1.grafana.net/api/prom/push
basic_auth:
username: 12345
password: secretpassword
integrations:
node_exporter:
autoscrape:
enable: true
agent:
autoscrape:
enable: true
Loading