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
24 commits
Select commit Hold shift + click to select a range
95fe287
Code to support dynamic configuration.
mattdurham Feb 4, 2022
2626227
Fix linting errors
mattdurham Feb 4, 2022
602e8c2
Fix issue with examples and add template parse
mattdurham Feb 4, 2022
7441d30
Fix windows issues
mattdurham Feb 4, 2022
6c4534c
Simplify tests
mattdurham Feb 4, 2022
125c0bd
Respond to PR feedback
mattdurham Feb 4, 2022
a1faa32
Simplify tests and remove setting default
mattdurham Feb 4, 2022
b5f3674
Move to unexported configshim
mattdurham Feb 4, 2022
1c96f21
Export configshims members for testing
mattdurham Feb 4, 2022
8cba358
Simplify singleton checking
mattdurham Feb 4, 2022
24bfa24
Add error around expand var
mattdurham Feb 7, 2022
2ef75e5
sever -> server
mattdurham Feb 9, 2022
ee012cf
Better error code
mattdurham Feb 10, 2022
3df83e0
Fix error when unmarshalling yaml which allowed unexporting fields
mattdurham Feb 18, 2022
87af4d6
Switch to using require.noerror instead of assert.
mattdurham Feb 18, 2022
2f5ef67
Split tests into two sections and remove redundant tests
mattdurham Feb 18, 2022
051aac9
Verbiage cleanup and var renaming
mattdurham Feb 23, 2022
4b15e44
PR feedback
mattdurham Feb 23, 2022
af640e2
PR feedback
mattdurham Feb 24, 2022
7e54ff3
Move singleton check to the controller instead
mattdurham Feb 24, 2022
3b87f41
Cleanup the read file code to MUCH more compact code.
mattdurham Feb 24, 2022
fd4218f
Remove EOF
mattdurham Feb 24, 2022
2f79606
PR feedback from session with rfratto, lots of changes to simplify th…
mattdurham Feb 24, 2022
68dae52
Fix misc feedback from PR
mattdurham Feb 24, 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- [ENHANCEMENT] Go 1.17 is now used for all builds of the Agent. (@tpaschalis)

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

- [BUGFIX] Fixed issue where Grafana Agent may panic if there is a very large
WAL loading while old WALs are being deleted or the `/agent/api/v1/targets`
endpoint is called. (@tpaschalis)
Expand Down
38 changes: 38 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,41 @@ 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 {
Comment thread
mattdurham marked this conversation as resolved.
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
5 changes: 5 additions & 0 deletions docs/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ The following flags will configure basic auth for requests made to HTTP/S remote
- `-config.url.basic-auth-password-file <file>`: path to a file containing the basic auth password

Note that this beta feature is subject to change in future releases.

## Dynamic Configuration (Experimental)

Dynamic Configuration is an experimental feature that allows loading configurations from a variety of sources and
running gomplate templates against the found file. Details can be found in the [dynamic configuration config]({{< relref "./dynamic-config.md" >}})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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 /etc/grafana/01_config.yml`
`docker run -v ${PWD}/:/etc/grafana grafana/agentctl:latest template-parse file:///etc/grafana/01_config.yml`

## Dynamic Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metrics:
password: secretpassword
integrations:
node_exporter:
enabled: true
autoscrape:
enable: true
agent:
enabled: true
autoscrape:
enable: true
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
template_paths:
- "/etc/grafana/01_assets"
- "file:///etc/grafana/01_assets"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Dynamic configuration allows multiple prometheus instances to be loaded with a parent metric. This uses
the same agent-1 and server-1 yml from 01.

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

## Dynamic Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ metrics:
username: 12345
password: secretpassword
integrations:
node_exporter:
enabled: true
agent:
enabled: true
node_exporter: {}
agent: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Dynamic configuration requires the use of `integrations-next` feature flag, to allow arrays of integrations. In this we will load integrations of various types. This is all built on the previous examples.

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

## Dynamic Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ metrics:
username: 12345
password: secretpassword
integrations:
node_exporter:
enabled: true
agent:
enabled: true
node_exporter: {}
agent: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Logs and Traces can also be templated. This is built ontop of the previous examples.

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

## Dynamic Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ metrics:
username: 12345
password: secretpassword
integrations:
node_exporter:
enabled: true
agent:
enabled: true
node_exporter: {}
agent: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The templating is based on the excellent [gomplate](https://docs.gomplate.ca/) library. Currently using a custom fork to allow loading gomplate as a library in addition to some new commands. This will NOT try to cover the full range of gomplate, would recommend reading the documentation for full knowledge.

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

## Looping

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Datasources are a powerful concept in gomplate. They allow you to reach out to other files, systems and resources to pull data.

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


## Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Datasources can also access objects.

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


## Config
Expand Down
Loading