cmd: change prefix for environment variables to AKVORADO_CFG

Otherwise, this may clash with automatically set environment variables
by various solutions, including Kubernetes.
This commit is contained in:
Vincent Bernat
2023-07-29 09:13:14 +02:00
parent 284ab8d081
commit 28bfd84b3f
4 changed files with 20 additions and 17 deletions

View File

@@ -105,16 +105,16 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
continue continue
} }
kk := strings.Split(kv[0], "_") kk := strings.Split(kv[0], "_")
if len(kk) < 3 || kk[0] != "AKVORADO" || kk[1] != strings.ToUpper(component) { if len(kk) < 4 || kk[0] != "AKVORADO" || kk[1] != "CFG" || kk[2] != strings.ToUpper(component) {
continue continue
} }
// From AKVORADO_CMP_SQUID_PURPLE_QUIRK=47, we // From AKVORADO_CFG_CMP_SQUID_PURPLE_QUIRK=47, we
// build a map "squid -> purple -> quirk -> // build a map "squid -> purple -> quirk ->
// 47". From AKVORADO_CMP_SQUID_3_PURPLE=47, we // 47". From AKVORADO_CFG_CMP_SQUID_3_PURPLE=47, we
// build "squid[3] -> purple -> 47" // build "squid[3] -> purple -> 47"
var rawConfig interface{} var rawConfig interface{}
rawConfig = kv[1] rawConfig = kv[1]
for i := len(kk) - 1; i > 1; i-- { for i := len(kk) - 1; i > 2; i-- {
if index, err := strconv.Atoi(kk[i]); err == nil { if index, err := strconv.Atoi(kk[i]); err == nil {
newRawConfig := make([]interface{}, index+1) newRawConfig := make([]interface{}, index+1)
newRawConfig[index] = rawConfig newRawConfig[index] = rawConfig

View File

@@ -203,21 +203,21 @@ module2:
// Environment // Environment
clean := func() { clean := func() {
for _, env := range os.Environ() { for _, env := range os.Environ() {
if strings.HasPrefix(env, "AKVORADO_DUMMY_") { if strings.HasPrefix(env, "AKVORADO_CFG_DUMMY_") {
os.Unsetenv(strings.Split(env, "=")[0]) os.Unsetenv(strings.Split(env, "=")[0])
} }
} }
} }
clean() clean()
defer clean() defer clean()
os.Setenv("AKVORADO_DUMMY_MODULE1_LISTEN", "127.0.0.1:9000") os.Setenv("AKVORADO_CFG_DUMMY_MODULE1_LISTEN", "127.0.0.1:9000")
os.Setenv("AKVORADO_DUMMY_MODULE1_TOPIC", "something") os.Setenv("AKVORADO_CFG_DUMMY_MODULE1_TOPIC", "something")
os.Setenv("AKVORADO_DUMMY_MODULE2_DETAILS_INTERVALVALUE", "10m") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_DETAILS_INTERVALVALUE", "10m")
os.Setenv("AKVORADO_DUMMY_MODULE2_STUFF", "bye") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_STUFF", "bye")
os.Setenv("AKVORADO_DUMMY_MODULE2_ELEMENTS_0_NAME", "something") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_ELEMENTS_0_NAME", "something")
os.Setenv("AKVORADO_DUMMY_MODULE2_ELEMENTS_0_GAUGE", "18") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_ELEMENTS_0_GAUGE", "18")
os.Setenv("AKVORADO_DUMMY_MODULE2_ELEMENTS_1_NAME", "something else") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_ELEMENTS_1_NAME", "something else")
os.Setenv("AKVORADO_DUMMY_MODULE2_ELEMENTS_1_GAUGE", "7") os.Setenv("AKVORADO_CFG_DUMMY_MODULE2_ELEMENTS_1_GAUGE", "7")
c := cmd.ConfigRelatedOptions{ c := cmd.ConfigRelatedOptions{
Path: configFile, Path: configFile,

View File

@@ -14,7 +14,7 @@ written using strings like `10h20m` or `5s`. Valid time units are `ms`, `s`,
It is also possible to override configuration settings using It is also possible to override configuration settings using
environment variables. You need to remove any `-` from key names and environment variables. You need to remove any `-` from key names and
use `_` to handle nesting. Then, put `AKVORADO_ORCHESTRATOR_` as a use `_` to handle nesting. Then, put `AKVORADO_CFG_ORCHESTRATOR_` as a
prefix. For example, let's consider the following configuration file: prefix. For example, let's consider the following configuration file:
```yaml ```yaml
@@ -30,9 +30,9 @@ kafka:
It can be translated to: It can be translated to:
```sh ```sh
AKVORADO_ORCHESTRATOR_HTTP_LISTEN=127.0.0.1:8081 AKVORADO_CFG_ORCHESTRATOR_HTTP_LISTEN=127.0.0.1:8081
AKVORADO_ORCHESTRATOR_KAFKA_TOPIC=test-topic AKVORADO_CFG_ORCHESTRATOR_KAFKA_TOPIC=test-topic
AKVORADO_ORCHESTRATOR_KAFKA_BROKERS=192.0.2.1:9092,192.0.2.2:9092 AKVORADO_CFG_ORCHESTRATOR_KAFKA_BROKERS=192.0.2.1:9092,192.0.2.2:9092
``` ```
The orchestrator service has its own configuration, as well as the The orchestrator service has its own configuration, as well as the

View File

@@ -13,6 +13,9 @@ identified with a specific icon:
## Unreleased ## Unreleased
- 💥 *cmd*: use `AKVORADO_CFG_` as a prefix for environment variables used to
modify configuration (`AKVORADO_CFG_ORCHESTRATOR_HTTP_LISTEN` instead of
`AKVORADO_ORCHESTRATOR_HTTP_LISTEN`)
- 💥 *inlet*: `inlet``metadata``provider(snmp)``ports` is now a map from - 💥 *inlet*: `inlet``metadata``provider(snmp)``ports` is now a map from
exporter subnets to ports, instead of a map from agent subnets to ports. This exporter subnets to ports, instead of a map from agent subnets to ports. This
is aligned with how `communities` and `security-parameters` options behave. is aligned with how `communities` and `security-parameters` options behave.