Skip to content

Commit

Permalink
[DNM] Zero-config C code to inject environment variables for Java and…
Browse files Browse the repository at this point in the history
… Node.js (#3514)

* Remove sending a metric as part of auto-instrumentation (#3482)

* refactor the code to inject allowed env vars

* latest after pair programming

* latest after review and pairing

* only inject env vars for java and nodejs programs. Apply env vars from different files for java and nodejs

* remove docker interactive and tty flags

* wip

* use arch var to set the name of the file to copy

* make tests pass on arm64

* try to support arm

* build for the proper platform

* fix package build

* review with Jason, test for env vars overrides

* Make ALLOWED_ENV_VARS a single string defined through the preprocessor

* Update instrumentation/tests/java/Dockerfile

Co-authored-by: Jeff Cheng <83052155+jeffreyc-splunk@users.noreply.github.com>

* load preload file same way as java test

* move file locations to macros

* use n functions to handle strings when possible

---------

Co-authored-by: Jeff Cheng <83052155+jeffreyc-splunk@users.noreply.github.com>
  • Loading branch information
atoulme and jeffreyc-splunk committed Oct 16, 2023
1 parent 2df3f4c commit ad13d78
Show file tree
Hide file tree
Showing 40 changed files with 272 additions and 2,623 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/auto-instrumentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Build libsplunk.so
run: make -C instrumentation dist ARCH=${{ matrix.ARCH }}

- name: Run tests
run: make -C instrumentation tests ARCH=${{ matrix.ARCH }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ deployments/heroku/test/node_modules
/instrumentation/dist/
/instrumentation/obj/
/instrumentation/so/
/instrumentation/tests
/instrumentation/tests/java/libsplunk.so
/instrumentation/tests/nodejs/libsplunk.so
3 changes: 0 additions & 3 deletions instrumentation/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ RUN apt-get update && \
WORKDIR /libsplunk

COPY src /libsplunk/src
COPY testdata/instrumentation-default.conf /libsplunk/testdata/instrumentation-default.conf
COPY testdata/instrumentation-options.conf /libsplunk/testdata/instrumentation-options.conf
COPY install/instrumentation.conf /libsplunk/install/instrumentation.conf
COPY Makefile /libsplunk/Makefile
45 changes: 16 additions & 29 deletions instrumentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,19 @@ obj:
clean:
rm -f tests so/* obj/*

obj/logger.o: obj src/logger.c src/logger.h
gcc -c -Wall -Werror -fpic -o obj/logger.o src/logger.c
obj/main.o: obj src/main.c
gcc -c -Wall -Werror -fpic -o obj/main.o src/main.c

obj/config.o: obj src/config.c src/config.h
gcc -c -Wall -Werror -fpic -o obj/config.o src/config.c

obj/metrics_client.o: obj src/metrics_client.c src/metrics_client.h
gcc -c -Wall -Werror -fpic -o obj/metrics_client.o src/metrics_client.c

obj/splunk.o: obj src/splunk.c src/splunk.h
gcc -c -Wall -Werror -fpic -o obj/splunk.o src/splunk.c

obj/args.o: obj src/args.c src/args.h
gcc -c -Wall -Werror -fpic -o obj/args.o src/args.c

obj/cmdline_reader.o: obj src/cmdline_reader.c src/cmdline_reader.h
gcc -c -Wall -Werror -fpic -o obj/cmdline_reader.o src/cmdline_reader.c

so/libsplunk.so: obj so obj/logger.o obj/config.o obj/metrics_client.o obj/cmdline_reader.o obj/args.o obj/splunk.o
gcc -shared -o so/libsplunk.so obj/logger.o obj/config.o obj/metrics_client.o obj/cmdline_reader.o obj/args.o obj/splunk.o

tests: src/test_main.h src/test_main.c src/test_utils.h src/test_utils.c src/logger.h src/test_logger.c \
src/metrics_client.h src/cmdline_reader.h src/cmdline_reader_test.c obj/config.o obj/metrics_client.o obj/args.o obj/splunk.o
gcc -g -o tests src/test_main.c src/test_utils.c src/test_logger.c src/cmdline_reader_test.c obj/config.o obj/metrics_client.o obj/args.o obj/splunk.o

.PHONY: test
test: tests
./tests
so/libsplunk.so: obj so obj/main.o
gcc -shared -o so/libsplunk.so obj/main.o

.PHONY: dist
dist:
@mkdir -p dist
docker buildx build --platform linux/$(ARCH) --build-arg DOCKER_REPO=$(DOCKER_REPO) -o type=image,name=libsplunk-builder:$(ARCH),push=false .
docker rm -f libsplunk-builder 2>/dev/null || true
docker run -d --platform linux/$(ARCH) --name libsplunk-builder libsplunk-builder:$(ARCH) sleep inf
docker exec libsplunk-builder make test all
docker exec libsplunk-builder make all
docker cp libsplunk-builder:/libsplunk/so/libsplunk.so dist/libsplunk_$(ARCH).so
docker rm -f libsplunk-builder

Expand All @@ -70,7 +47,6 @@ endif
.PHONY: install
install: all uninstall
mkdir -p $(INSTALL_DIR)
cp install/instrumentation.conf $(INSTALL_DIR)
cp splunk-otel-javaagent.jar $(INSTALL_DIR)
cp so/libsplunk.so $(INSTALL_DIR)
echo $(INSTALL_DIR)/libsplunk.so > /etc/ld.so.preload
Expand All @@ -92,3 +68,14 @@ docker-build:
.PHONY: docker-run
docker-run:
docker run --rm -it -v `pwd`:/instr instr-devel

.PHONY: tests
tests: test-java test-nodejs

.PHONY: test-java
test-java: dist
(cd tests/java && ./test.sh)

.PHONY: test-nodejs
test-nodejs: dist
(cd tests/nodejs && ./test.sh)
181 changes: 0 additions & 181 deletions instrumentation/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions instrumentation/install/instrumentation.conf

This file was deleted.

7 changes: 0 additions & 7 deletions instrumentation/packaging/fpm/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ PKG_URL="https://github.com/signalfx/splunk-otel-collector"

LIBSPLUNK_INSTALL_PATH="/usr/lib/splunk-instrumentation/libsplunk.so"
JAVA_AGENT_INSTALL_PATH="/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar"
CONFIG_INSTALL_PATH="/usr/lib/splunk-instrumentation/instrumentation.conf"

JAVA_AGENT_RELEASE_PATH="${FPM_DIR}/../java-agent-release.txt"
JAVA_AGENT_RELEASE_URL="https://github.com/signalfx/splunk-otel-java/releases/"

POSTINSTALL_PATH="$FPM_DIR/postinstall.sh"
PREUNINSTALL_PATH="$FPM_DIR/preuninstall.sh"
CONFIG_PATH="$REPO_DIR/instrumentation/install/instrumentation.conf"

get_version() {
commit_tag="$( git -C "$REPO_DIR" describe --abbrev=0 --tags --exact-match --match 'v[0-9]*' 2>/dev/null || true )"
Expand Down Expand Up @@ -78,9 +76,4 @@ setup_files_and_permissions() {
cp -f "$java_agent" "$buildroot/$JAVA_AGENT_INSTALL_PATH"
sudo chown root:root "$buildroot/$JAVA_AGENT_INSTALL_PATH"
sudo chmod 755 "$buildroot/$JAVA_AGENT_INSTALL_PATH"

mkdir -p "$buildroot/$(dirname $CONFIG_INSTALL_PATH)"
cp -f "$CONFIG_PATH" "$buildroot/$CONFIG_INSTALL_PATH"
sudo chown root:root "$buildroot/$CONFIG_INSTALL_PATH"
sudo chmod 644 "$buildroot/$CONFIG_INSTALL_PATH"
}
1 change: 0 additions & 1 deletion instrumentation/packaging/fpm/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ sudo fpm -s dir -t deb -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
--deb-no-default-config-files \
--depends sed \
--depends grep \
--config-files "$CONFIG_INSTALL_PATH" \
"$buildroot/"=/

dpkg -c "${OUTPUT_DIR}/${PKG_NAME}_${VERSION}_${ARCH}.deb"
1 change: 0 additions & 1 deletion instrumentation/packaging/fpm/rpm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ sudo fpm -s dir -t rpm -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
--before-remove "$PREUNINSTALL_PATH" \
--depends sed \
--depends grep \
--config-files "$CONFIG_INSTALL_PATH" \
"$buildroot/"=/

rpm -qpli "${OUTPUT_DIR}/${PKG_NAME}-${VERSION}-1.${ARCH}.rpm"
8 changes: 0 additions & 8 deletions instrumentation/packaging/fpm/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ if ! grep -q "$LIBSPLUNK_INSTALL_PATH" /etc/ld.so.preload; then
echo "$LIBSPLUNK_INSTALL_PATH not found in /etc/ld.so.preload" >&2
exit 1
fi
if [ ! -f "$CONFIG_INSTALL_PATH" ]; then
echo "$CONFIG_INSTALL_PATH not found!" >&2
exit 1
fi

ldd "$LIBSPLUNK_INSTALL_PATH"

Expand All @@ -54,10 +50,6 @@ if ! grep -q "$LIBSPLUNK_INSTALL_PATH" /etc/ld.so.preload; then
echo "$LIBSPLUNK_INSTALL_PATH not found in /etc/ld.so.preload" >&2
exit 1
fi
if [ ! -f "$CONFIG_INSTALL_PATH" ]; then
echo "$CONFIG_INSTALL_PATH not found!" >&2
exit 1
fi

ldd "$LIBSPLUNK_INSTALL_PATH"

Expand Down
Loading

0 comments on commit ad13d78

Please sign in to comment.