Skip to content

Commit 5eff2f6

Browse files
committed
Edit doc
1 parent 41a556b commit 5eff2f6

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

cmd/otelcol/main_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
package main
1717

1818
import (
19+
"fmt"
20+
"log"
1921
"os"
22+
"os/exec"
2023
"testing"
24+
25+
"github.com/stretchr/testify/assert"
26+
"github.com/stretchr/testify/require"
2127
)
2228

2329
func TestContains(t *testing.T) {
@@ -142,3 +148,34 @@ func TestSetMemoryLimit(t *testing.T) {
142148

143149
HelperTestSetMemoryLimit("200", t)
144150
}
151+
152+
func TestConfigPathAndYamlEnvVarsTogetherNotAllowed(t *testing.T) {
153+
expectedErr := fmt.Sprintf("Specifying env vars %s and %s simultaneously is not allowed", configEnvVarName, configYamlEnvVarName)
154+
stdErr, exitCode := getExecErr(t, "TestConfigPathAndYamlEnvVarsTogetherNotAllowed", func(t *testing.T) {
155+
// Setting both config file path and config YAML env vars
156+
os.Setenv(configYamlEnvVarName, "service: \\nextensions: \\n- health_check")
157+
os.Setenv(configEnvVarName, "path/to/config/file")
158+
setConfigSource()
159+
})
160+
161+
require.NotZero(t, exitCode)
162+
assert.Containsf(t, stdErr, expectedErr, "Standard error does not contain the expected error")
163+
}
164+
165+
// getExecErr should be called once in a test at the beginning and the failing code placed in func failingCode.
166+
// getExecErr runs the test in a subprocess then returns the output of executing failingCode.
167+
func getExecErr(t *testing.T, testName string, failingCode func(*testing.T)) (string, int) {
168+
if os.Getenv(testName) == "1" {
169+
failingCode(t)
170+
os.Exit(0)
171+
}
172+
path, arg := os.Args[0], "-test.run="+testName
173+
cmd := exec.Command(path, arg)
174+
cmd.Env = append(os.Environ(), testName+"=1")
175+
stdErr, err := cmd.CombinedOutput()
176+
exitErr := err.(*exec.ExitError)
177+
if exitErr.ExitCode() == 0 {
178+
log.Fatal("Failing code exited with zero exit code")
179+
}
180+
return string(stdErr), exitErr.ExitCode()
181+
}

docs/getting-started/linux-manual.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ $ docker run --rm -e SPLUNK_ACCESS_TOKEN=12345 -e SPLUNK_REALM=us0 \
140140
### Custom Configuration
141141

142142
When changes to the default configuration file is needed, a custom
143-
configuration file can specified and used instead. Use the `SPLUNK_CONFIG`
144-
environment variable or the `--config` command line argument to provide a
145-
custom configuration.
143+
configuration file can be specified and used instead. Use the `SPLUNK_CONFIG`
144+
environment variable or the `--config` command line argument to provide the
145+
path to a YAML file containing the custom configuration. Environment variable
146+
`SPLUNK_CONFIG_YAML` can be used provide the custom configuration YAML directly
147+
to the exclusion of `SPLUNK_CONFIG`.
146148

147149
> Command line arguments take precedence over environment variables. This
148150
> applies to `--config` and `--mem-ballast-size-mib`.
@@ -160,11 +162,29 @@ $ docker run --rm -e SPLUNK_ACCESS_TOKEN=12345 -e SPLUNK_REALM=us0 \
160162

161163
> Use of a SemVer tag over `latest` is highly recommended.
162164
163-
In the case of Docker, a volume mount may be required to load custom
164-
configuration as shown above.
165+
In the case of Docker, a volume mount may be required to store the custom
166+
configuration file as shown above.
165167

166168
If the custom configuration includes a `memory_limiter` processor then the
167169
`ballast_size_mib` parameter should be the same as the
168170
`SPLUNK_BALLAST_SIZE_MIB` environment variable. See
169171
[gateway_config.yaml](../../cmd/otelcol/config/collector/gateway_config.yaml)
170172
as an example.
173+
174+
Using `SPLUNK_CONFIG_YAML` instead of `SPLUNK_CONFIG` would be something like:
175+
176+
```bash
177+
$ SPLUNK_CONFIG_YAML="extensions:\n health_check:\n endpoint: 0.0.0.0:13133"
178+
179+
$ docker run --rm -e SPLUNK_ACCESS_TOKEN=12345 -e SPLUNK_REALM=us0 \
180+
-e SPLUNK_CONFIG_YAML=${SPLUNK_CONFIG_YAML} -p 13133:13133 -p 14250:14250 \
181+
-p 14268:14268 -p 4317:4317 -p 6060:6060 -p 7276:7276 -p 8888:8888 \
182+
-p 9080:9080 -p 9411:9411 -p 9943:9943 \
183+
--name otelcol quay.io/signalfx/splunk-otel-collector:latest
184+
```
185+
Where `SPLUNK_CONFIG_YAML` is the one-line version of the multi-line configuration YAML below:
186+
```yaml
187+
extensions:
188+
health_check:
189+
endpoint: 0.0.0.0:13133
190+
```

0 commit comments

Comments
 (0)