influxdata / influxdata/kapacitor

Cant extend array or object configuration via environment variables

Open
#1,344 6 comments 2 reactions 0 assignees View on GitHub
bug difficulty-easy difficulty-medium help wanted
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Currently users can only modify existing configuration elements.

The following test will panic:
```
func TestConfig_Parse_EnvOverrideAddArray(t *testing.T) {
// Parse configuration.
var c server.Config
if _, err := toml.Decode(`
[[influxdb]]
urls=["http://localhost:8086"]
`, &c); err != nil {
t.Fatal(err)
}

if err := os.Setenv("KAPACITOR_INFLUXDB_0_URLS_0", "http://localhost:18086"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}

if err := os.Setenv("KAPACITOR_INFLUXDB_1_URLS_0", "http://localhost:7076"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}

if err := c.ApplyEnvOverrides(); err != nil {
t.Fatalf("failed to apply env overrides: %v", err)
}

if c.InfluxDB[0].URLs[0] != "http://localhost:18086" {
t.Fatalf("unexpected url 0: %s", c.InfluxDB[0].URLs[0])
} else if c.InfluxDB[1].URLs[0] != "http://localhost:7076" {
t.Fatalf("unexpected url 0: %s", c.InfluxDB[0].URLs[0])
}
}
```

Users should be able to add additional configuration to Kapacitor through environment variables.

Contributor guide

Open the contributing guide

Research direction

Start by locating Config.ApplyEnvOverrides and the configuration parsing tests, then reproduce the behavior with TestConfig_Parse_EnvOverrideAddArray. Trace how KAPACITOR_INFLUXDB_0_URLS_0 and KAPACITOR_INFLUXDB_1_URLS_0 are handled; done means the test no longer panics and both URLs are available in c.InfluxDB with the expected values.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.