Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discovery mode #5781

Merged
merged 17 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/splunk-ta-otel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
distribute-ta:
name: "distribute-ta" # what gets run to package in gitlab
runs-on: ubuntu-24.04
needs: [setup-environment, check_changes]
needs: [setup-environment, check_changes, test-discovery]
if: needs.check_changes.outputs.ta_packaging_change == 'true' || needs.check_changes.outputs.ta_workflow_change == 'true'
steps:
- name: Check out the codebase.
Expand All @@ -106,3 +106,27 @@ jobs:
run: |
set -o pipefail
PLATFORM="all" make -e distribute-ta

test-discovery:
name: test-discovery
runs-on: ubuntu-24.04
needs: [setup-environment, test]
strategy:
matrix:
PLATFORM: ["all"]
steps:
- name: Check out the codebase.
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: '**/go.sum'

- name: Build & Package TA
run: |
set -o pipefail
make -e bundle.d otelcol generate-technical-addon copy-local-build-to-ta package-ta
make -e discovery-test-ta

9 changes: 9 additions & 0 deletions packaging/technical-addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ smoketest-ta:
PLATFORM="$(PLATFORM)" \
$(SOURCE_DIR)/packaging-scripts/cicd-tests/smoketests/smoketest.sh

.PHONY: discovery-test-ta
discovery-test-ta:
SOURCE_DIR="$(SOURCE_DIR)" \
BUILD_DIR="$(BUILD_DIR)" \
ARCH="$(ARCH)" \
PLATFORM="$(PLATFORM)" \
$(SOURCE_DIR)/packaging-scripts/cicd-tests/discovery/discovery-docker-test.sh


.PHONY: update-ta-deps
update-ta-deps:
SOURCE_DIR="$(SOURCE_DIR)" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ splunk_config = <value>
* Value to use for the `SPLUNK_CONFIG` environment variable (default `$SPLUNK_OTEL_TA_HOME/config/ta_agent_config.yaml`)

splunk_config_dir = <value>
* Value to use for the `SPLUNK_CONFIG_DIR` environment variable (default `$SPLUNK_OTEL_TA_HOME/config/`)
* Value to use for the `SPLUNK_CONFIG_DIR` environment variable (default `$SPLUNK_OTEL_TA_HOME/config/`). Same as `--configd` parameter as defined in https://github.com/signalfx/splunk-otel-collector/blob/v0.114.0/internal/confmapprovider/discovery/README.md?plain=1#L47

splunk_debug_config_server = <value>
* Value to use for the `SPLUNK_DEBUG_CONFIG_SERVER` environment variable
Expand All @@ -50,3 +50,12 @@ splunk_ingest_url = <value>

splunk_realm = <value>
* Splunk Observability realm to use for the `SPLUNK_REALM` environment variable (ex us0)

discovery = <value>
* Boolean, if `true` will enable `--discovery`

discovery_properties = <value>
* String, same as `--discovery-properties` parameter. See [properties reference](https://github.com/signalfx/splunk-otel-collector/blob/v0.114.0/internal/confmapprovider/discovery/README.md?plain=1#L175)

configd = <value>
* Boolean, if `true` will enable `--configd`
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash


# script args related vars
splunk_TA_otel_num_args="$#"
splunk_TA_otel_args=("$@")
Expand All @@ -17,8 +16,16 @@ if [ -z "$SPLUNK_HOME" ]; then
SPLUNK_HOME="$(realpath "$SPLUNK_OTEL_TA_HOME/../../../")"
fi

SPLUNK_OTEL_FLAGS=""
#SPLUNK_OTEL_TA_DEBUG="DEBUG"

# Begin autogenerated code
configd_name="configd"
configd_value=""
discovery_name="discovery"
discovery_value=""
discovery_properties_name="discovery_properties"
discovery_properties_value=""
gomemlimit_name="gomemlimit"
gomemlimit_value=""
splunk_api_url_name="splunk_api_url"
Expand Down Expand Up @@ -112,6 +119,27 @@ splunk_TA_otel_read_configs() {
splunk_TA_otel_log_msg "DEBUG" "line: $line"

# Begin autogenerated code
has_configd="$(echo "$line" | grep "$configd_name")"
if [ "$has_configd" ] ; then
splunk_TA_otel_log_msg "DEBUG" "reading $configd_name from line $has_configd"
configd_value="$(echo "$has_configd" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')"
splunk_TA_otel_log_msg "DEBUG" "Set $configd_name to $configd_value"
fi

has_discovery="$(echo "$line" | grep "$discovery_name")"
if [ "$has_discovery" ] ; then
splunk_TA_otel_log_msg "DEBUG" "reading $discovery_name from line $has_discovery"
discovery_value="$(echo "$has_discovery" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')"
splunk_TA_otel_log_msg "DEBUG" "Set $discovery_name to $discovery_value"
fi

has_discovery_properties="$(echo "$line" | grep "$discovery_properties_name")"
if [ "$has_discovery_properties" ] ; then
splunk_TA_otel_log_msg "DEBUG" "reading $discovery_properties_name from line $has_discovery_properties"
discovery_properties_value="$(echo "$has_discovery_properties" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')"
splunk_TA_otel_log_msg "DEBUG" "Set $discovery_properties_name to $discovery_properties_value"
fi

has_gomemlimit="$(echo "$line" | grep "$gomemlimit_name")"
if [ "$has_gomemlimit" ] ; then
splunk_TA_otel_log_msg "DEBUG" "reading $gomemlimit_name from line $has_gomemlimit"
Expand Down Expand Up @@ -274,6 +302,8 @@ splunk_TA_otel_run_agent() {
splunk_collectd_dir_value="$(Splunk_TA_otel_expand_config_param "$splunk_collectd_dir_value")"
splunk_otel_log_file_value="$(Splunk_TA_otel_expand_config_param "$splunk_otel_log_file_value")"
splunk_access_token_file_value="$(Splunk_TA_otel_expand_config_param "$splunk_access_token_file_value")"
discovery_properties_value="$(Splunk_TA_otel_expand_config_param "$discovery_properties_value")"
splunk_config_dir_value="$(Splunk_TA_otel_expand_config_param "$splunk_config_dir_value")"

get_access_token
if [[ $? == 1 ]] ; then
Expand Down Expand Up @@ -307,11 +337,13 @@ splunk_TA_otel_run_agent() {
fi
if [ "$splunk_config_value" ] ; then
export SPLUNK_CONFIG="$splunk_config_value"
SPLUNK_OTEL_FLAGS="$SPLUNK_OTEL_FLAGS --config=$splunk_config_value"
else
splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_config_name"
fi
if [ "$splunk_config_dir_value" ] ; then
export SPLUNK_CONFIG_DIR="$splunk_config_dir_value"
SPLUNK_OTEL_FLAGS="$SPLUNK_OTEL_FLAGS --config-dir=$splunk_config_dir_value"
else
splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_config_dir_name"
fi
Expand Down Expand Up @@ -370,6 +402,21 @@ splunk_TA_otel_run_agent() {
else
splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_realm_name"
fi
if [ "$configd_value" ] ; then
SPLUNK_OTEL_FLAGS="$SPLUNK_OTEL_FLAGS --configd"
else
splunk_TA_otel_log_msg "INFO" "BOOLEAN PARAM NOT SET: $configd_name"
fi
if [ "$discovery_value" ] ; then
SPLUNK_OTEL_FLAGS="$SPLUNK_OTEL_FLAGS --discovery"
else
splunk_TA_otel_log_msg "INFO" "BOOLEAN PARAM NOT SET: $discovery_name"
fi
if [ "$discovery_properties_value" ] ; then
SPLUNK_OTEL_FLAGS="$SPLUNK_OTEL_FLAGS --discovery-properties=$discovery_properties_value"
else
splunk_TA_otel_log_msg "INFO" "STRING PARAM NOT SET: $discovery_properties_name"
fi
if [ "$splunk_access_token_file_value" ] ; then
export SPLUNK_ACCESS_TOKEN_FILE="$splunk_access_token_file_value"
else
Expand Down Expand Up @@ -410,7 +457,7 @@ splunk_TA_otel_run_agent() {
LD_PRELOAD="$LD_PRELOAD" \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
SPLUNK_OTEL_TA_PLATFORM_HOME="$SPLUNK_OTEL_TA_PLATFORM_HOME" \
"$otel_path" > "$splunk_otel_log_file_value" 2>&1 &
"$otel_path" "$SPLUNK_OTEL_FLAGS" > "$splunk_otel_log_file_value" 2>&1 &
splunk_TA_otel_pid="$!"
is_splunk_TA_otel_agent_running "$splunk_TA_otel_pid"
if [[ $? == 1 ]] ; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ set "splunk_otel_common_ps_name=Splunk_TA_otel_utils.ps1"
set "SPLUNK_OTEL_TA_HOME="
set "SPLUNK_OTEL_TA_PLATFORM_HOME="


set "SPLUNK_OTEL_FLAGS="
:: BEGIN AUTOGENERATED CODE
set "configd_name=configd"
set "configd_value="
set "discovery_name=discovery"
set "discovery_value="
set "discovery_properties_name=discovery_properties"
set "discovery_properties_value="
set "gomemlimit_name=gomemlimit"
set "gomemlimit_value="
set "splunk_api_url_name=splunk_api_url"
Expand Down Expand Up @@ -109,11 +115,13 @@ if "%splunk_bundle_dir_value%" == "" (
if "%splunk_config_value%" == "" (
call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_config_name% not set"
) else (
set "SPLUNK_OTEL_FLAGS=%SPLUNK_OTEL_FLAGS% --config=%splunk_config_value%"
set "SPLUNK_CONFIG=%splunk_config_value%"
)
if "%splunk_config_dir_value%" == "" (
call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_config_dir_name% not set"
) else (
set "SPLUNK_OTEL_FLAGS=%SPLUNK_OTEL_FLAGS% --config-dir=%splunk_config_dir_value%"
set "SPLUNK_CONFIG_DIR=%splunk_config_dir_value%"
)
if "%splunk_collectd_dir_value%" == "" (
Expand Down Expand Up @@ -176,13 +184,28 @@ if "%splunk_access_token_file_value%" == "" (
) else (
set "SPLUNK_ACCESS_TOKEN_FILE=%splunk_access_token_file_value%"
)
if "%configd_value%" == "true" (
set "SPLUNK_OTEL_FLAGS=%SPLUNK_OTEL_FLAGS% --configd"
) else (
call :splunk_TA_otel_log_msg "DEBUG" "Optional flag %configd_name% not set"
)
if "%discovery_value%" == "true" (
set "SPLUNK_OTEL_FLAGS=%SPLUNK_OTEL_FLAGS% --discovery"
) else (
call :splunk_TA_otel_log_msg "DEBUG" "Optional flag %discovery_name% not set"
)
if "%discovery_properties_value%" != "" (
set "SPLUNK_OTEL_FLAGS=%SPLUNK_OTEL_FLAGS% --discovery-properties=%discovery_properties_value%"
) else (
call :splunk_TA_otel_log_msg "DEBUG" "Optional flag %discovery_properties_name% not set"
)
:: END AUTOGENERATED CODE

:: Extract agent bundle
call :extract_bundle

set "command_line=%splunk_TA_otel_app_directory%%splunk_otel_process_name%"
start /B "" "%command_line%" > "%splunk_otel_log_file_value%" 2>&1
start /B "" "%command_line%" "%SPLUNK_OTEL_FLAGS%" > "%splunk_otel_log_file_value%" 2>&1
set "splunk_otel_common_ps=%splunk_TA_otel_app_directory%%splunk_otel_common_ps_name%"
start /B "" /I /WAIT powershell "& '%splunk_otel_common_ps%' '%splunk_otel_process_name%' '%splunk_TA_otel_log_file%'"

Expand Down Expand Up @@ -212,7 +235,12 @@ exit /B 0
:splunk_TA_otel_read_configs
echo "INFO grabbing config from stdin..."

for /F "tokens=1,2 delims==" %%I in ('powershell -noninteractive -noprofile -command "$input | Select-String -Pattern '.*?(%gomemlimit_name%|%splunk_api_url_name%|%splunk_bundle_dir_name%|%splunk_config_name%|%splunk_config_dir_name%|%splunk_collectd_dir_name%|%splunk_debug_config_server_name%|%splunk_config_yaml_name%|%splunk_gateway_url_name%|%splunk_hec_url_name%|%splunk_listen_interface_name%|%splunk_memory_limit_mib_name%|%splunk_memory_total_mib_name%|%splunk_otel_log_file_name%|%splunk_ingest_url_name%|%splunk_realm_name%|%splunk_access_token_file_name%|session_key).*?>(.*?)<' | ForEach-Object { $_.Matches.Groups[1].Value + '=' + $_.Matches.Groups[2].Value }"') do (


for /F "tokens=1,2 delims==" %%I in ('powershell -noninteractive -noprofile -command "$input | Select-String -Pattern '.*?(%configd_name%|%discovery_name%|%discovery_properties_name%|%gomemlimit_name%|%splunk_access_token_file_name%|%splunk_api_url_name%|%splunk_ballast_size_mib_name%|%splunk_bundle_dir_name%|%splunk_collectd_dir_name%|%splunk_config_name%|%splunk_config_dir_name%|%splunk_config_yaml_name%|%splunk_debug_config_server_name%|%splunk_gateway_url_name%|%splunk_hec_url_name%|%splunk_ingest_url_name%|%splunk_listen_interface_name%|%splunk_memory_limit_mib_name%|%splunk_memory_total_mib_name%|%splunk_otel_log_file_name%|%splunk_realm_name%).*?>(.*?)<' | ForEach-Object { $_.Matches.Groups[1].Value + '=' + $_.Matches.Groups[2].Value }"') do (
if "%%I"=="%configd_name%" set "configd_value=%%J"
if "%%I"=="%discovery_name%" set "discovery_value=%%J"
if "%%I"=="%discovery_properties_name%" set "discovery_properties_value=%%J"
if "%%I"=="%gomemlimit_name%" set "gomemlimit_value=%%J"
if "%%I"=="%splunk_api_url_name%" set "splunk_api_url_value=%%J"
if "%%I"=="%splunk_bundle_dir_name%" set "splunk_bundle_dir_value=%%J"
Expand Down Expand Up @@ -339,6 +367,16 @@ for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splu
set "splunk_otel_log_file_value=%%i"
)

:: expand params in discovery_properties_value
for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%discovery_properties_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do (
set "discovery_properties_value=%%i"
)
for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%discovery_properties_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do (
set "discovery_properties_value=%%i"
)
for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%discovery_properties_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do (
set "discovery_properties_value=%%i"
)
:: END AUTOGENERATED CODE

:get_access_token
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash -eu
set -o pipefail

[[ -z "$BUILD_DIR" ]] && echo "BUILD_DIR not set" && exit 1
[[ -z "$SOURCE_DIR" ]] && echo "SOURCE_DIR not set" && exit 1

source "${SOURCE_DIR}/packaging-scripts/cicd-tests/add-access-token.sh"
TA_FULLPATH="$(repack_with_access_token "foobar" "$BUILD_DIR/out/distribution/Splunk_TA_otel.tgz" | tail -n 1)"
REPACKED_TA_NAME="$(basename "$TA_FULLPATH")"
ADDON_DIR="$(realpath "$(dirname "$TA_FULLPATH")")"
rm -rf "$ADDON_DIR/$REPACKED_TA_NAME"

# Set discovery specific config & repackage TA
echo 'discovery=true' >> "$ADDON_DIR/Splunk_TA_otel/local/inputs.conf"
echo 'discovery_properties=$SPLUNK_OTEL_TA_HOME/configs/kafkametrics.discovery.properties.yaml' >> "$ADDON_DIR/Splunk_TA_otel/local/inputs.conf"
echo 'splunk_config=$SPLUNK_OTEL_TA_HOME/configs/docker_observer_without_ssl_kafkametrics_config.yaml' >> "$ADDON_DIR/Splunk_TA_otel/local/inputs.conf"
DISCOVERY_SOURCE_DIR="${SOURCE_DIR}/packaging-scripts/cicd-tests/discovery"
cp "$DISCOVERY_SOURCE_DIR/docker_observer_without_ssl_kafkametrics_config.yaml" "$ADDON_DIR/Splunk_TA_otel/configs/"
cp "$DISCOVERY_SOURCE_DIR/kafkametrics.discovery.properties.yaml" "$ADDON_DIR/Splunk_TA_otel/configs/"
tar -C "$ADDON_DIR" -hcz --file "$TA_FULLPATH" "Splunk_TA_otel"

echo "Testing with hot TA $TA_FULLPATH ($ADDON_DIR and $REPACKED_TA_NAME)"

DOCKER_COMPOSE_CONFIG="$SOURCE_DIR/packaging-scripts/cicd-tests/discovery/docker-compose.yml"
REPACKED_TA_NAME=$REPACKED_TA_NAME ADDON_DIR=$ADDON_DIR docker compose --file "$DOCKER_COMPOSE_CONFIG" up --build --force-recreate --wait --detach --timestamps

# If there's an error in the app, you can try manually installing it or modifying files
# Lines are for debugging only, until we get better testing documentation
#docker exec -u splunk discovery-ta-test-discovery-1 cp -r "/tmp/local-tas/Splunk_TA_otel" "/opt/splunk/etc/apps"
#docker exec -u splunk discovery-ta-test-discovery-1 /opt/splunk/bin/splunk restart
#sleep 1m # If restarting splunk for debugging, wait a bit
#docker exec -u root -it discovery-ta-test-discovery-1 bash

docker exec -u root discovery-ta-test-discovery-1 /opt/splunk/bin/splunk btool check --debug | grep -qi "Invalid key in stanza" && exit 1

MAX_ATTEMPTS=6
DELAY=10
ATTEMPT=1
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
if docker exec -u root discovery-ta-test-discovery-1 grep -qi "Everything is ready. Begin running and processing data." /opt/splunk/var/log/splunk/otel.log; then
break
else
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
echo "Failed to see success message in otel.log after $MAX_ATTEMPTS attempts."
cat /opt/splunk/var/log/splunk/otel.log
exit 1
fi
echo "sucess message not found in otel.log Retrying in $DELAY seconds"
ATTEMPT=$((ATTEMPT + 1))
sleep $DELAY
fi
done

# Ensure command line flags were passed properly
docker exec -u root discovery-ta-test-discovery-1 pgrep -f 'discovery'
docker exec -u root discovery-ta-test-discovery-1 pgrep -f 'discovery-properties'
docker exec -u root discovery-ta-test-discovery-1 pgrep -f 'kafkametrics.discovery.properties.yaml'
docker exec -u root discovery-ta-test-discovery-1 test -d /opt/splunk/etc/apps/Splunk_TA_otel/configs/discovery/config.d.linux

sleep 15s # Give discovery receiver some time to discover things after the collector is up
docker exec -u root discovery-ta-test-discovery-1 grep -qi "9092" /opt/splunk/var/log/splunk/otel.log
docker exec -u root discovery-ta-test-discovery-1 grep -qi "kafkametrics receiver is working" /opt/splunk/var/log/splunk/otel.log

# Should trap this
REPACKED_TA_NAME=$REPACKED_TA_NAME BUILD_DIR=$BUILD_DIR ADDON_DIR=$ADDON_DIR docker compose --file "$DOCKER_COMPOSE_CONFIG" down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# See https://splunk.github.io/docker-splunk/advanced/APP_INSTALL.html#apps-on-filesystem
services:
ta-test-discovery:
image: ${SPLUNK_IMAGE:-splunk/splunk:9.2.1}
network_mode: "host"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/en-US/account/login"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
environment:
# If there's a bug in the TA, you may comment out this line and use docker exec via cp and splunk restart
# in the test script to manually debug the TA
- SPLUNK_APPS_URL=/tmp/local-tas/$REPACKED_TA_NAME
- SPLUNK_START_ARGS=--accept-license
- SPLUNK_PASSWORD=Chang3d!
volumes:
- $ADDON_DIR:/tmp/local-tas:rwz
depends_on:
kafka-kraft-single:
condition: service_started
kafka-kraft-single:
image: apache/kafka:3.7.0
# following configuration is taken DIRECTLY from
# kafka examples in the upstream apache (licensed + hosted) repo
# Thanks all from the Kafka team!
# https://github.com/apache/kafka/blob/3.7.0/docker/examples/jvm/single-node/plaintext/docker-compose.yml
network_mode: "host"
environment:
KAFKA_NODE_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT'
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT_HOST://localhost:9092,PLAINTEXT://localhost:19092'
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@localhost:29093'
KAFKA_LISTENERS: 'CONTROLLER://:29093,PLAINTEXT_HOST://:9092,PLAINTEXT://:19092'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
CLUSTER_ID: '4L6g3nShT-eMCtK--X86sx'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_LOG_DIRS: '/tmp/kraft-combined-logs'
Loading