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 datadog java tracer and APM options #43

Merged
merged 3 commits into from
Aug 31, 2023
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
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ RUN mkdir -p /usr/src/awsclizip "${LABKEY_HOME}/awsclibin" "${LABKEY_HOME}/aws-c
&& rm -rf /usr/src/awsclizip \
&& chown -R labkey:labkey "${LABKEY_HOME}/awsclibin" "${LABKEY_HOME}/aws-cli"

# install datadog tracing agent
RUN mkdir -p datadog \
&& wget -q -O datadog/dd-java-agent.jar https://dtdg.co/latest-java-tracer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to pin this to a particular version or always grab that latest? I know we generally want to stay current, but sometimes it's painful to not have more explicit control.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been allowing cloud deployments to always pull the latest version of the main datadog agent and tracer for most of a year without an issue. I feel like their dev/release processes are very robust and would rather take that risk than have one more thing to version bump. If it broke it would probably fail the teamcity build anyway (if we enable all the datadog features in the build job, which seems prudent).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!


# refrain from using shell significant characters in HEALTHCHECK_HEADER_*
ENV HEALTHCHECK_INTERVAL="6s" \
HEALTHCHECK_TIMEOUT="10s" \
Expand Down
10 changes: 7 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ services:
- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- DD_COLLECT_APM=${DD_COLLECT_APM-false}
- SLEEP=${SLEEP:-0}

pg-community:
Expand Down Expand Up @@ -192,7 +193,8 @@ services:
- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- DD_COLLECT_APM=${DD_COLLECT_APM-false}
- SLEEP=${SLEEP:-0}

pg-allpg:
Expand Down Expand Up @@ -300,7 +302,8 @@ services:
- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- DD_COLLECT_APM=${DD_COLLECT_APM-false}
- SLEEP=${SLEEP:-0}

pg-enterprise:
Expand Down Expand Up @@ -409,6 +412,7 @@ services:
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- DD_COLLECT_APM=${DD_COLLECT_APM-false}
- SLEEP=${SLEEP:-0}

pg-lims_starter:
Expand Down
18 changes: 17 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ LABKEY_CUSTOM_PROPERTIES_S3_URI="${LABKEY_CUSTOM_PROPERTIES_S3_URI:=none}"
LABKEY_DEFAULT_PROPERTIES_S3_URI="${LABKEY_DEFAULT_PROPERTIES_S3_URI:=none}"

# set below to 'server/labkeywebapp/WEB-INF/classes/log4j2.xml' to use embedded tomcat version
LOG4J_CONFIG_FILE="${LOG4J_CONFIG_FILE:='log4j2.xml'}"
LOG4J_CONFIG_FILE="${LOG4J_CONFIG_FILE:=log4j2.xml}"

# below assumes using local log4j2.xml file, as the embedded version is not available for edits until after server is running
JSON_OUTPUT="${JSON_OUTPUT:-false}"

# for ecs/datadog, optionally enable APM metrics
DD_COLLECT_APM="${DD_COLLECT_APM:-false}"

SLEEP="${SLEEP:=0}"

main() {
Expand Down Expand Up @@ -226,6 +229,17 @@ main() {
echo "saw JSON_OUTPUT=$JSON_OUTPUT and LOG4J_CONFIG_FILE=$LOG4J_CONFIG_FILE"
fi

export DD_JAVA_AGENT=""
if [ "$DD_COLLECT_APM" = "true" ]; then
echo "DD_COLLECT_APM==true , so adding EC2 host's private IP to env vars as DD_AGENT_HOST"
export TOKEN=$(curl --max-time 3 -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600");
export DD_AGENT_HOST=$(curl --max-time 3 -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-ipv4);

echo "Adding -javaagent to java command"
export DD_JAVA_AGENT="-javaagent:./datadog/dd-java-agent.jar -Ddd.profiling.enabled=true -Ddd.logs.injection=true -XX:FlightRecorderOptions=stackdepth=256"

fi

# shellcheck disable=SC2086
exec java \
\
Expand Down Expand Up @@ -261,6 +275,8 @@ main() {
-DsynchronousStartup=true \
-DterminateOnStartupFailure=true \
\
${DD_JAVA_AGENT} \
\
${JAVA_PRE_JAR_EXTRA} \
\
-jar app.jar \
Expand Down
8 changes: 4 additions & 4 deletions log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@

<!-- only show errors from PipelineJob output -->
<Logger name="org.labkey.api.pipeline.PipelineJob" level="error">
<AppenderRef ref="CONSOLE"/>
<!-- <AppenderRef ref="CONSOLE"/> -->
</Logger>

<!-- don't need to log PDFBox errors (e.g., FlateFilter, PDCIDFontType2) -->
Expand Down Expand Up @@ -272,7 +272,7 @@

<Logger name="org.labkey.audit.event" level="OFF">
<AppenderRef ref="LABKEY_AUDIT"/>
<AppenderRef ref="CONSOLE"/>
<!-- <AppenderRef ref="CONSOLE"/> -->
</Logger>

<!--
Expand Down Expand Up @@ -305,13 +305,13 @@
-->
<Logger name="org.labkey.audit.event.UserAuditEvent" additivity="false" level="OFF">
<AppenderRef ref="LABKEY_AUDIT"/>
<AppenderRef ref="CONSOLE"/>
<!-- <AppenderRef ref="CONSOLE"/> -->
</Logger>

<Logger name="NoOpLogger" level="OFF" additivity="false"/>

<Root level="${env:LOG_LEVEL_DEFAULT:-FATAL}">
<AppenderRef ref="CONSOLE"/>
<!-- <AppenderRef ref="CONSOLE"/> -->
<AppenderRef ref="ERRORS"/>
</Root>
</Loggers>
Expand Down