Skip to content

Commit

Permalink
NH-91598: set otlp metrics exporter configurations when enabled and c…
Browse files Browse the repository at this point in the history
…lean up ci runner disk.
  • Loading branch information
cleverchuk committed Sep 26, 2024
1 parent 53ece3b commit 45f8b67
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 30 deletions.
81 changes: 75 additions & 6 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
aws s3 cp custom/shared/src/main/resources/solarwinds-apm-config.json \
s3://$STAGE_BUCKET/apm/java/$AGENT_VERSION/solarwinds-apm-config.json \
--acl public-read
env:
AGENT_VERSION: ${{ steps.set_version.outputs.version }}

- name: Copy to S3(latest)
run: |
Expand Down Expand Up @@ -172,12 +174,34 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Free Disk Space before Build
run: |
echo "Disk space before pre-build cleanup:"
df -h
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
echo "Disk space after pre-build cleanup:"
df -h
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Set agent version
id: set_version
uses: ./.github/actions/version

- name: Set snapshot version
run: |
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
echo "AGENT_VERSION=${{ steps.set_version.outputs.version }}.$GIT_HASH" >> $GITHUB_ENV
- name: Build smoke-test
run: |
cd smoke-tests
Expand All @@ -186,12 +210,6 @@ jobs:
- name: Docker login
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin

- name: Set agent version env
run: |
./gradlew build -x test
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
echo "AGENT_VERSION=$(cd agent/build/libs && unzip -p solarwinds-apm-agent.jar META-INF/MANIFEST.MF | grep Implementation-Version | awk '{ print $2 }' | sed 's/[^a-z0-9.-]//g').$GIT_HASH" >> $GITHUB_ENV
- name: Execute smoke tests
run: |
cd smoke-tests
Expand All @@ -203,6 +221,20 @@ jobs:
path: smoke-tests/build/reports/tests/test
name: lambda-release-test

- name: Free Disk Space After Build
run: |
echo "Disk space before post-build cleanup:"
df -h
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf smoke-tests/build/
echo "Disk space after post-build cleanup:"
df -h
- name: Docker logout
if: always()
run: docker logout
Expand Down Expand Up @@ -381,6 +413,16 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Set agent version
id: set_version
uses: ./.github/actions/version

- name: Set snapshot version
shell: bash
run: |
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
echo "AGENT_VERSION=${{ steps.set_version.outputs.version }}.$GIT_HASH" >> $GITHUB_ENV
- name: Run application
working-directory: smoke-tests
run: |
Expand All @@ -397,6 +439,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Free Disk Space before Build
run: |
echo "Disk space before pre-build cleanup:"
df -h
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
echo "Disk space after pre-build cleanup:"
df -h
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -441,6 +496,20 @@ jobs:
path: smoke-tests/build/reports/tests/test
name: release-test

- name: Free Disk Space After Build
run: |
echo "Disk space before post-build cleanup:"
df -h
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf smoke-tests/build/
echo "Disk space after post-build cleanup:"
df -h
- name: Docker logout
if: always()
run: docker logout
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ subprojects {
opentelemetryJavaagent: "2.8.0",
bytebuddy : "1.12.10",
guava : "30.1-jre",
joboe : "10.0.11",
joboe : "10.0.12",
agent : "2.8.0", // the custom distro agent version
autoservice : "1.0.1",
caffeine : "2.9.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static void maybeFollowOtelConfigProperties(ConfigContainer configs) {
}
}

static void configOtelLogExport(ConfigContainer container) {
static void configureOtelLogExport(ConfigContainer container) {
Boolean exportLog = (Boolean) container.get(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED);
if (exportLog != null && exportLog) {
String serviceKey = (String) container.get(ConfigProperty.AGENT_SERVICE_KEY);
Expand All @@ -221,7 +221,7 @@ static void configOtelLogExport(ConfigContainer container) {
}
}

System.setProperty("otel.exporter.otlp.protocol", "grpc");
System.setProperty("otel.exporter.otlp.logs.protocol", "grpc");
System.setProperty("otel.logs.exporter", "otlp");
System.setProperty(
"otel.exporter.otlp.logs.headers", String.format("authorization=Bearer %s", apiKey));
Expand All @@ -232,6 +232,44 @@ static void configOtelLogExport(ConfigContainer container) {
}
}

static void configureOtelMetricExport(ConfigContainer container) {
Boolean exportMetrics = (Boolean) container.get(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED);
if (exportMetrics != null && exportMetrics) {
String serviceKey = (String) container.get(ConfigProperty.AGENT_SERVICE_KEY);
String apiKey = ServiceKeyUtils.getApiKey(serviceKey);

String dataCell = "na-01";
String env = "cloud";
String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR);

if (collectorEndpoint != null) {
if (collectorEndpoint.contains("appoptics.com")) {
return;
}
collectorEndpoint = collectorEndpoint.split(":")[0];
String[] fragments = collectorEndpoint.split("\\.");
if (fragments.length > 2) {
// This is based on knowledge of the SWO url format where the third name from the left in
// the domain is the data-cell name and assumes this format will stay stable.
dataCell = fragments[2];
}

if (fragments.length > 3) {
env = fragments[3];
}
}

System.setProperty("otel.exporter.otlp.metrics.protocol", "grpc");
System.setProperty("otel.metrics.exporter", "otlp");
System.setProperty(
"otel.exporter.otlp.metrics.headers", String.format("authorization=Bearer %s", apiKey));

System.setProperty(
"otel.exporter.otlp.metrics.endpoint",
String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env));
}
}

static Map<String, String> mergeEnvWithSysProperties(Map<String, String> env, Properties props) {
Map<String, String> res = new HashMap<>(env);

Expand Down Expand Up @@ -283,7 +321,8 @@ private static void loadConfigurations() throws InvalidConfigException {
config)); // initialize the logger factory as soon as the config is available
try {
processConfigs(configs);
configOtelLogExport(configs);
configureOtelLogExport(configs);
configureOtelMetricExport(configs);
} catch (InvalidConfigException e) {
// if there was a config read exception then processConfigs might throw exception due to
// incomplete config container.
Expand Down
Loading

0 comments on commit 45f8b67

Please sign in to comment.