Skip to content

Commit 80650c0

Browse files
Populate memory ballast size from SPLUNK_BALLAST_SIZE_MIB env variable. (open-telemetry#31)
The value of memory ballast can be now provided via SPLUNK_BALLAST_SIZE_MIB env variable. It will override the value provided via --mem-ballast-size-mib command line flag. The SPLUNK_BALLAST_SIZE_MIB env variable can be accessed from the config file. This is particularly useful for the memorylimiter processor and helps to avoid specifying the ballast size twice.
1 parent 10feb09 commit 80650c0

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ which requires the following environment variables:
2020

2121
- `${SPLUNK_REALM}`: Which realm to send the data to (for example: `us0`)
2222
- `${SPLUNK_ACCESS_TOKEN}`: Access token to authenticate requests
23-
- `${SPLUNK_BALLAST}`: How much memory to allocate to the ballast. This should be set to 1/3 to 1/2 of configured memory.
23+
- `${SPLUNK_BALLAST_SIZE_MIB}`: How much memory to allocate to the ballast. This should be set to 1/3 to 1/2 of configured memory.
2424

2525
Deploy the collector as outlined in the below. More information
2626
about deploying and configuring the collector can be found
@@ -32,10 +32,9 @@ Deploy from a Docker container (replace `0.1.0-otel-0.11.0` with the latest
3232
stable version number if necessary):
3333

3434
```bash
35-
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST=683 \
35+
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST_SIZE_MIB=683 \
3636
docker run -p 7276:7276 -p 8888:8888 -p 9943:9943 -p 55679:55679 -p 55680:55680 -p 9411:9411 \
37-
--name otelcol signalfx/splunk-otel-collector:0.1.0-otel-0.11.0 \
38-
--mem-ballast-size-mib=683
37+
--name otelcol signalfx/splunk-otel-collector:0.1.0-otel-0.11.0
3938
```
4039

4140
### Kubernetes
@@ -50,8 +49,8 @@ file on GitHub.
5049

5150
```bash
5251
$ make otelcol
53-
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST=683 \
54-
./bin/otelcol --mem-ballast-size-mib=${SPLUNK_BALLAST}
52+
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST_SIZE_MIB=683 \
53+
./bin/otelcol
5554
```
5655

5756
## Custom Configuration
@@ -62,9 +61,13 @@ be provided.
6261
For example in Docker:
6362

6463
```bash
65-
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST=683 \
64+
$ SPLUNK_REALM=us0 SPLUNK_ACCESS_TOKEN=12345 SPLUNK_BALLAST_SIZE_MIB=683 \
6665
docker run -p 7276:7276 -p 8888:8888 -p 9943:9943 -p 55679:55679 -p 55680:55680 -p 9411:9411 \
6766
-v collector.yaml:/etc/collector.yaml:ro \
6867
--name otelcol signalfx/splunk-otel-collector:0.1.0-otel-0.11.0 \
69-
--config /etc/collector.yaml --mem-ballast-size-mib=683
68+
--config /etc/collector.yaml
7069
```
70+
71+
Note that if the configuration includes a memorylimiter processor then it must set the
72+
value of `ballast_size_mib` setting of the processor to the env variable SPLUNK_BALLAST_SIZE_MIB.
73+
See for example splunk_config.yaml on how to do it.

cmd/otelcol/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ COPY --from=otelcol /otelcol /
1313
COPY config/collector/splunk_config.yaml /etc/otel/collector/splunk_config.yaml
1414
COPY config/collector/otlp_config.yaml /etc/otel/collector/otlp_config.yaml
1515
ENTRYPOINT ["/otelcol"]
16-
CMD ["--config", "/etc/otel/collector/splunk_config.yaml", "--mem-ballast-size-mib", "${SPLUNK_BALLAST}"]
16+
CMD ["--config", "/etc/otel/collector/splunk_config.yaml"]
1717
EXPOSE 13133 14250 14268 55678 55679 55680 7276 9411 9443

cmd/otelcol/config/collector/otlp_config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ processors:
4141
# The configuration below assumes 2GB of memory. In general, the ballast
4242
# should be set to 1/3 of the collector's memory, the limit should be 90% of
4343
# the collector's memory up to 2GB, and the spike should be 25% of the
44-
# collector's memory up to 2GB. In addition, the "--mem-ballast-size-mib" CLI
45-
# flag must be set to the same value as the "ballast_size_mib". For more
46-
# information, see
44+
# collector's memory up to 2GB. The simplest way to specify the ballast size is
45+
# set the value of SPLUNK_BALLAST_SIZE_MIB env variable. This will overrides
46+
# the value of --mem-ballast-size-mib command line flag. If SPLUNK_BALLAST_SIZE_MIB
47+
# is not defined then --mem-ballast-size-mib command line flag must be manually specified.
48+
# For more information about memory limiter, see
4749
# https://github.com/open-telemetry/opentelemetry-collector/blob/master/processor/memorylimiter/README.md
4850
memory_limiter:
49-
ballast_size_mib: ${SPLUNK_BALLAST}
51+
ballast_size_mib: ${SPLUNK_BALLAST_SIZE_MIB}
5052
check_interval: 2s
5153
limit_percentage: 90
5254
spike_limit_percentage: 25

cmd/otelcol/config/collector/splunk_config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ processors:
4141
# The configuration below assumes 2GB of memory. In general, the ballast
4242
# should be set to 1/3 of the collector's memory, the limit should be 90% of
4343
# the collector's memory up to 2GB, and the spike should be 25% of the
44-
# collector's memory up to 2GB. In addition, the "--mem-ballast-size-mib" CLI
45-
# flag must be set to the same value as the "ballast_size_mib". For more
46-
# information, see
44+
# collector's memory up to 2GB. The simplest way to specify the ballast size is
45+
# set the value of SPLUNK_BALLAST_SIZE_MIB env variable. This will overrides
46+
# the value of --mem-ballast-size-mib command line flag. If SPLUNK_BALLAST_SIZE_MIB
47+
# is not defined then --mem-ballast-size-mib command line flag must be manually specified.
48+
# For more information about memory limiter, see
4749
# https://github.com/open-telemetry/opentelemetry-collector/blob/master/processor/memorylimiter/README.md
4850
memory_limiter:
49-
ballast_size_mib: ${SPLUNK_BALLAST}
51+
ballast_size_mib: ${SPLUNK_BALLAST_SIZE_MIB}
5052
check_interval: 2s
5153
limit_percentage: 90
5254
spike_limit_percentage: 25

cmd/otelcol/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package main
2020
import (
2121
"fmt"
2222
"log"
23+
"os"
24+
"strconv"
2325

2426
"go.opentelemetry.io/collector/component"
2527
"go.opentelemetry.io/collector/service"
@@ -28,6 +30,8 @@ import (
2830
"github.com/signalfx/splunk-otel-collector/internal/version"
2931
)
3032

33+
const ballastEnvVarName = "SPLUNK_BALLAST_SIZE_MIB"
34+
3135
func main() {
3236
factories, err := components.Get()
3337
if err != nil {
@@ -41,11 +45,29 @@ func main() {
4145
GitHash: version.GitHash,
4246
}
4347

48+
useBallastSizeFromEnvVar()
49+
4450
if err := run(service.Parameters{ApplicationStartInfo: info, Factories: factories}); err != nil {
4551
log.Fatal(err)
4652
}
4753
}
4854

55+
func useBallastSizeFromEnvVar() {
56+
57+
// Check if the ballast is specified via the env var.
58+
ballastSize := os.Getenv(ballastEnvVarName)
59+
if ballastSize != "" {
60+
// Check if it is a numeric value.
61+
_, err := strconv.Atoi(ballastSize)
62+
if err != nil {
63+
log.Fatalf("Expected a number in %s env variable but got %s", ballastEnvVarName, ballastSize)
64+
}
65+
66+
// Inject the command line flag that controls the ballast size.
67+
os.Args = append(os.Args, "--mem-ballast-size-mib="+ballastSize)
68+
}
69+
}
70+
4971
func runInteractive(params service.Parameters) error {
5072
app, err := service.New(params)
5173
if err != nil {

internal/buildscripts/packaging/fpm/splunk_env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ SPLUNK_ACCESS_TOKEN=12345
1818
SPLUNK_REALM=us0
1919

2020
# How much memory to allocate to the ballast. This should be set to 1/3 to 1/2 of configured memory.
21-
SPLUNK_BALLAST=683
21+
SPLUNK_BALLAST_SIZE_MIB=683

0 commit comments

Comments
 (0)