Skip to content

Commit d051e85

Browse files
authored
add option to disable smart agent bundle use (#5)
1 parent f8a7ddd commit d051e85

File tree

4 files changed

+178
-18
lines changed

4 files changed

+178
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ git push heroku main
9797
Use the following environment variables to configure this buildpack
9898

9999
| Environment Variable | Required | Default | Description |
100-
| ---------------------- | -------- | ------- | ------------------------------------------------------------------------- |
100+
|---------------------------|----------|-----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
101+
| `SFX_AGENT_DISABLED` | No | `false` | Whether to disable installing the smart agent as part of the buildpack. |
101102
| `SPLUNK_ACCESS_TOKEN` | Yes | | [Splunk access token](https://docs.splunk.com/Observability/admin/authentication-tokens/org-tokens.html#admin-org-tokens). |
102103
| `SPLUNK_REALM` | Yes | | [Splunk realm](https://dev.splunk.com/observability/docs/realms_in_endpoints/). |
103104
| `SPLUNK_API_URL` | No | `https://api.SPLUNK_REALM.signalfx.com` | The Splunk API base URL. |

bin/compile

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ if [ -f "$ENV_DIR/SFX_AGENT_VERSION" ]; then
3939
fi
4040
signalfx_agent_tar="signalfx-agent-$SFX_AGENT_VERSION.tar.gz"
4141

42+
# Check if the SignalFx Agent download is explicitly disabled
43+
SFX_AGENT_DISABLED=false
44+
if [ -f "$ENV_DIR/SFX_AGENT_DISABLED" ]; then
45+
SFX_AGENT_DISABLED=$(cat "$ENV_DIR/SFX_AGENT_DISABLED")
46+
fi
47+
4248
SPLUNK_CONFIG_DIR="$BUILD_DIR/.splunk"
4349
cp "$BUILDPACK_DIR/setup/config.yaml" "$SPLUNK_CONFIG_DIR"
4450

@@ -52,19 +58,24 @@ if [ $? -ne 0 ]; then
5258
exit 1;
5359
fi
5460

55-
echo "-----> Downloading SignalFx Agent Bundle $SFX_AGENT_VERSION ($signalfx_agent_tar)"
56-
wget -P "$SPLUNK_CONFIG_DIR/" "https://github.com/signalfx/signalfx-agent/releases/download/v$SFX_AGENT_VERSION/$signalfx_agent_tar" -o $signalfx_agent_tar > /dev/null 2>&1
57-
#curl -L "https://github.com/signalfx/signalfx-agent/releases/download/v$SFX_AGENT_VERSION/$signalfx_agent_tar" -o $SPLUNK_CONFIG_DIR/$signalfx_agent_tar > /dev/null 2>&1
58-
if [ $? -ne 0 ]; then
59-
echo "Downloading agent tarball failed" | indent
60-
echo "$SFX_AGENT_VERSION may not be a valid version of the SignalFx Agent." | indent
61-
echo "Find valid versions here: https://github.com/signalfx/signalfx-agent/tags" | indent
62-
exit 1;
61+
if [ "${SFX_AGENT_DISABLED}" = "true" ]; then
62+
echo "-----> Skipping installing the SignalFx Agent Bundle"
63+
else
64+
echo "-----> Downloading SignalFx Agent Bundle $SFX_AGENT_VERSION ($signalfx_agent_tar)"
65+
wget -P "$SPLUNK_CONFIG_DIR/" "https://github.com/signalfx/signalfx-agent/releases/download/v$SFX_AGENT_VERSION/$signalfx_agent_tar" -o $signalfx_agent_tar > /dev/null 2>&1
66+
#curl -L "https://github.com/signalfx/signalfx-agent/releases/download/v$SFX_AGENT_VERSION/$signalfx_agent_tar" -o $SPLUNK_CONFIG_DIR/$signalfx_agent_tar > /dev/null 2>&1
67+
if [ $? -ne 0 ]; then
68+
echo "Downloading agent tarball failed" | indent
69+
echo "$SFX_AGENT_VERSION may not be a valid version of the SignalFx Agent." | indent
70+
echo "Find valid versions here: https://github.com/signalfx/signalfx-agent/tags" | indent
71+
exit 1;
72+
fi
73+
74+
echo "-----> Extracting SignalFx Agent Bundle"
75+
tar -xf "$SPLUNK_CONFIG_DIR/$signalfx_agent_tar" -C "$SPLUNK_CONFIG_DIR"
76+
rm -f "$SPLUNK_CONFIG_DIR/$signalfx_agent_tar"
6377
fi
6478

65-
echo "-----> Extracting SignalFx Agent Bundle"
66-
tar -xf "$SPLUNK_CONFIG_DIR/$signalfx_agent_tar" -C "$SPLUNK_CONFIG_DIR"
67-
rm -f "$SPLUNK_CONFIG_DIR/$signalfx_agent_tar"
6879

6980
mkdir -p "$BUILD_DIR/.profile.d"
7081
cp "$BUILDPACK_DIR/setup/agent.sh" "$BUILD_DIR/.profile.d/"

setup/agent.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ fi
2121
# Set configuration file
2222

2323
export SPLUNK_CONFIG_DIR="$HOME/.splunk"
24-
export SPLUNK_COLLECTD_CONFIG_DIR="$SPLUNK_CONFIG_DIR/signalfx-agent/var/run/collectd"
25-
mkdir -p "$SPLUNK_COLLECTD_CONFIG_DIR"
24+
if [[ "${SFX_AGENT_DISABLED}" == "true" ]]; then
25+
export FALLBACK_AGENT_CONFIG="$SPLUNK_CONFIG_DIR/config_without_sa.yaml"
26+
else
27+
export SPLUNK_COLLECTD_CONFIG_DIR="$SPLUNK_CONFIG_DIR/signalfx-agent/var/run/collectd"
28+
mkdir -p "$SPLUNK_COLLECTD_CONFIG_DIR"
29+
30+
export FALLBACK_AGENT_CONFIG="$SPLUNK_CONFIG_DIR/config.yaml"
31+
fi
2632

27-
export FALLBACK_AGENT_CONFIG="$SPLUNK_CONFIG_DIR/config.yaml"
2833
export DEFAULT_APP_CONFIG="$HOME/config.yaml"
2934

3035
if [[ -f "$DEFAULT_APP_CONFIG" ]]; then
@@ -46,17 +51,19 @@ if [[ -z "$SPLUNK_TRACE_URL" ]]; then
4651
export SPLUNK_TRACE_URL="https://ingest.$SPLUNK_REALM.signalfx.com/v2/trace"
4752
fi
4853

49-
export SPLUNK_BUNDLE_DIR="$SPLUNK_CONFIG_DIR/signalfx-agent"
5054

5155
if [[ -z "$SPLUNK_LOG_FILE" ]]; then
5256
export SPLUNK_LOG_FILE=/dev/stdout
5357
else
5458
mkdir -p $(dirname $SPLUNK_LOG_FILE)
5559
fi
5660

57-
# Start the splunk otel collector
61+
if [[ "${SFX_AGENT_DISABLED}" != "true" ]]; then
5862

59-
(cd $SPLUNK_CONFIG_DIR/signalfx-agent/ && bin/patch-interpreter $SPLUNK_CONFIG_DIR/signalfx-agent/)
63+
export SPLUNK_BUNDLE_DIR="$SPLUNK_CONFIG_DIR/signalfx-agent"
64+
65+
(cd $SPLUNK_CONFIG_DIR/signalfx-agent/ && bin/patch-interpreter $SPLUNK_CONFIG_DIR/signalfx-agent/)
66+
fi
6067

6168
chmod a+x $SPLUNK_CONFIG_DIR/otelcol_linux_amd64
6269
$SPLUNK_CONFIG_DIR/otelcol_linux_amd64 > $SPLUNK_LOG_FILE 2>&1&

setup/config_without_sa.yaml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
config_sources:
2+
env:
3+
defaults:
4+
HEROKU_DYNO_ID: "unset"
5+
HEROKU_APP_ID: "unset"
6+
HEROKU_APP_NAME: "unset"
7+
8+
extensions:
9+
health_check:
10+
endpoint: 0.0.0.0:13133
11+
http_forwarder:
12+
ingress:
13+
endpoint: 0.0.0.0:6060
14+
egress:
15+
endpoint: "${SPLUNK_API_URL}"
16+
# Use instead when sending to gateway
17+
#endpoint: "${SPLUNK_GATEWAY_URL}"
18+
zpages:
19+
#endpoint: 0.0.0.0:55679
20+
21+
receivers:
22+
jaeger:
23+
protocols:
24+
grpc:
25+
endpoint: 0.0.0.0:14250
26+
thrift_binary:
27+
endpoint: 0.0.0.0:6832
28+
thrift_compact:
29+
endpoint: 0.0.0.0:6831
30+
thrift_http:
31+
endpoint: 0.0.0.0:14268
32+
otlp:
33+
protocols:
34+
grpc:
35+
endpoint: 0.0.0.0:4317
36+
http:
37+
endpoint: 0.0.0.0:4318
38+
# This section is used to collect the OpenTelemetry Collector metrics
39+
# Even if just a Splunk APM customer, these metrics are included
40+
prometheus/internal:
41+
config:
42+
scrape_configs:
43+
- job_name: 'otel-collector'
44+
scrape_interval: 10s
45+
static_configs:
46+
- targets: ['0.0.0.0:8888']
47+
metric_relabel_configs:
48+
- source_labels: [ __name__ ]
49+
regex: '.*grpc_io.*'
50+
action: drop
51+
signalfx:
52+
endpoint: 0.0.0.0:9943
53+
zipkin:
54+
endpoint: 0.0.0.0:9411
55+
56+
processors:
57+
batch:
58+
# Enabling the memory_limiter is strongly recommended for every pipeline.
59+
# Configuration is based on the amount of memory allocated to the collector.
60+
# In general, the ballast should be set to 1/3 of the collector's memory, the limit
61+
# should be 90% of the collector's memory up to 2GB. The simplest way to specify the
62+
# ballast size is set the value of SPLUNK_BALLAST_SIZE_MIB env variable. Alternatively, the
63+
# --mem-ballast-size-mib command line flag can be passed and take priority.
64+
# For more information about memory limiter, see
65+
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md
66+
memory_limiter:
67+
ballast_size_mib: ${SPLUNK_BALLAST_SIZE_MIB}
68+
check_interval: 2s
69+
limit_mib: ${SPLUNK_MEMORY_LIMIT_MIB}
70+
attributes/heroku:
71+
actions:
72+
- action: insert
73+
key: dyno_id
74+
value: ${env:HEROKU_DYNO_ID}
75+
- action: insert
76+
key: app_id
77+
value: ${env:HEROKU_APP_ID}
78+
- action: insert
79+
key: app_name
80+
value: ${env:HEROKU_APP_NAME}
81+
metricstransform/heroku:
82+
transforms:
83+
- include: .*
84+
match_type: regexp
85+
action: update
86+
operations:
87+
- action: add_label
88+
new_label: dyno_id
89+
new_value: ${env:HEROKU_DYNO_ID}
90+
- action: add_label
91+
new_label: app_id
92+
new_value: ${env:HEROKU_APP_ID}
93+
- action: add_label
94+
new_label: app_name
95+
new_value: ${env:HEROKU_APP_NAME}
96+
# Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and
97+
# traces when it's not populated by instrumentation libraries.
98+
# If enabled, make sure to enable this processor in the pipeline below.
99+
#resource/add_environment:
100+
#attributes:
101+
#- action: insert
102+
#key: deployment.environment
103+
#value: staging/production/...
104+
105+
exporters:
106+
# Traces
107+
sapm:
108+
access_token: "${SPLUNK_ACCESS_TOKEN}"
109+
endpoint: "${SPLUNK_TRACE_URL}"
110+
# Metrics + Events
111+
signalfx:
112+
access_token: "${SPLUNK_ACCESS_TOKEN}"
113+
api_url: "${SPLUNK_API_URL}"
114+
ingest_url: "${SPLUNK_INGEST_URL}"
115+
# Send to gateway
116+
#otlp:
117+
# endpoint: "${SPLUNK_GATEWAY_URL}:4317"
118+
# insecure: true
119+
# Debug
120+
logging:
121+
loglevel: debug
122+
123+
service:
124+
extensions: [health_check, http_forwarder, zpages]
125+
pipelines:
126+
traces:
127+
receivers: [jaeger, otlp, zipkin]
128+
processors:
129+
- memory_limiter
130+
- batch
131+
- attributes/heroku
132+
#- resource/add_environment
133+
exporters: [sapm, signalfx]
134+
metrics:
135+
receivers: [otlp, signalfx]
136+
processors: [memory_limiter, batch, metricstransform/heroku]
137+
exporters: [signalfx]
138+
metrics/internal:
139+
receivers: [prometheus/internal]
140+
processors: [memory_limiter, batch, metricstransform/heroku]
141+
exporters: [signalfx]

0 commit comments

Comments
 (0)