Skip to content

Commit

Permalink
setup project
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Jun 21, 2024
1 parent 2fb6034 commit a7b01db
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 71 deletions.
7 changes: 7 additions & 0 deletions .github/scripts/update-sdk-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e
# script to update the OpenTelemetry SDK version

# version, which should be used for the SDK
version=$1

sed -Ei "s/(opentelemetrySdk *: )\"[^\"]*\"/\1\"$version\"/" build.gradle
18 changes: 18 additions & 0 deletions .github/scripts/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -e
# script to update the OpenTelemetry Java agent version


# version, which should be used for the java agent
version=$1

if [[ $version == *-SNAPSHOT ]]; then
alpha_version=${version//-SNAPSHOT/-alpha-SNAPSHOT}
else
alpha_version=${version}-alpha
fi

sed -Ei "s/(opentelemetryJavaagent *: )\"[^\"]*\"/\1\"$version\"/" build.gradle
sed -Ei "s/(opentelemetryJavaagentAlpha *: )\"[^\"]*\"/\1\"$alpha_version\"/" build.gradle

sed -Ei "s/(io.opentelemetry.instrumentation.muzzle-generation\" version )\"[^\"]*\"/\1\"$alpha_version\"/" build.gradle
sed -Ei "s/(io.opentelemetry.instrumentation.muzzle-check\" version )\"[^\"]*\"/\1\"$alpha_version\"/" build.gradle
14 changes: 8 additions & 6 deletions .github/workflows/ci-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Feature Branch Continous Integration

on:
push:
branches: [ "feature/**" ]

branches:
- "feature/**"
- master
pull_request:

jobs:
build-and-test:
name: "Build and test extension"
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -27,19 +31,17 @@ jobs:

- name: Build
run: ./gradlew extendAgent

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: Package
path: build/libs

dependency-submission:

dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
Expand Down
33 changes: 3 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
# Extension
This extension is used as a showcase for VHV in order to demonstrate that we can move inspectit's
agent logic to opentelemetry agent enhanced via an extension.

Use `./gradlew extendAgent` (no tests) or `./gradlew build` to build an agent jar with your current
# inspectIT Gepard Extension
Extension for the OpenTelemetry Java agent.
Use `./gradlew extendedAgent` (no tests) or `./gradlew build` to build an agent jar with your current
changes.

## TODOs / next steps
* otel agent wants to export spans.
* Find out where otel wants to report spans to. Jaeger? Something else?
* Do we want to use that? Do we want to disable it?
* Is it easy to change it to an url provided by the config server?
* this extension sends an additional http header named `X-OCELOT-AGENT-TYPE` to the config server. Use it over there to display a different icon in the config server's UI
* tests do not work
* Probably not that important

# Documentation
This extension calls the agent configuration endpoint of the configuration server. For your local
installation this is typically available at http://localhost:8090/v1/api/agent/configuration. The
endpoint of the server is defined in class `rocks.inspectit.ocelot.rest.agent.AgentController` of inspectit-ocelot.

Calling that endpoint serves the following purposes:
* First call registers Agent with configuration server
* uses query parameter `service` to display something meaningful in the UI. Currently, hardcoded to `otel-extension`
* Regularly polls configuration server to fetch potentially updated configurations
* Transmits by each call the health state of the agent
* Send an `X-OCELOT-AGENT-TYPE` to distinguish inspectit-ocelot-agent and this agent

Currently, you can influence the target url via SystemProperty named `inspectit.config.http.url`.

Polling of configuration is handled in classes `ConfigurationPolling` and `HttpConfiguration`.

# Original Readme
The following is the original content from which this work is derived.
Source: https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/extension
Expand Down
66 changes: 32 additions & 34 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ plugins {
See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
*/
id "com.github.johnrengelman.shadow" version "8.1.1"
id "com.diffplug.spotless" version "6.17.0"
id "com.diffplug.spotless" version "6.25.0"

id "io.opentelemetry.instrumentation.muzzle-generation" version "1.31.0-alpha"
id "io.opentelemetry.instrumentation.muzzle-check" version "1.31.0-alpha"
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.5.0-alpha"
id "io.opentelemetry.instrumentation.muzzle-check" version "2.5.0-alpha"

id "pl.allegro.tech.build.axion-release" version "1.11.0"
id "pl.allegro.tech.build.axion-release" version "1.17.2"

}

group 'rocks.inspectit.gepard.agent'
version = scmVersion.version
version = "0.0.1-SNAPSHOT"

sourceCompatibility = "17"
targetCompatibility = "17"

ext {
versions = [
// this line is managed by .github/scripts/update-sdk-version.sh
opentelemetrySdk : "1.38.0",
opentelemetrySdk : "1.39.0",

// these lines are managed by .github/scripts/update-version.sh
opentelemetryJavaagent : "2.3.0",
opentelemetryJavaagentAlpha: "2.3.0-alpha",
opentelemetryJavaagent : "2.5.0",
opentelemetryJavaagentAlpha: "2.5.0-alpha",

junit : "5.9.2"
junit : "5.10.2"
]

deps = [
autoservice: dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.0.1')
autoservice: dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1')
]
}

Expand Down Expand Up @@ -73,13 +73,11 @@ dependencies {
// these serve as a test of the instrumentation boms
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:${versions.opentelemetryJavaagent}"))
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${versions.opentelemetryJavaagentAlpha}"))
implementation("org.apache.httpcomponents:httpclient:4.5.14")
implementation("commons-codec:commons-codec:1.15")
implementation("ch.qos.logback:logback-classic:1.3.6")
implementation("org.slf4j:jcl-over-slf4j:2.0.4")

// For instrumentation, same version as OpenTelemetry
implementation("net.bytebuddy:byte-buddy:1.14.12")
// inspectit-gepard dependencies
implementation("net.bytebuddy:byte-buddy:1.14.15")
implementation("ch.qos.logback:logback-classic:1.5.6")
implementation("org.slf4j:jcl-over-slf4j:2.0.13")

/*
Interfaces and SPIs that we implement. We use `compileOnly` dependency because during
Expand All @@ -90,35 +88,35 @@ dependencies {
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
//Provides @AutoService annotation that makes registration of our SPI implementations much easier

// Provides @AutoService annotation that makes registration of our SPI implementations much easier
compileOnly deps.autoservice
annotationProcessor deps.autoservice


//All dependencies below are only for tests
testImplementation("org.testcontainers:testcontainers:1.17.6")
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
testImplementation("com.google.protobuf:protobuf-java-util:3.22.2")
testImplementation("com.squareup.okhttp3:okhttp:4.10.0")
// All dependencies below are only for tests
testImplementation("org.testcontainers:testcontainers:1.19.8")
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.17.1")
testImplementation("com.google.protobuf:protobuf-java-util:3.25.3")
testImplementation("com.squareup.okhttp3:okhttp:4.12.0")
testImplementation("io.opentelemetry:opentelemetry-api")
testImplementation("io.opentelemetry.proto:opentelemetry-proto:0.19.0-alpha")
testImplementation("io.opentelemetry.proto:opentelemetry-proto:1.3.1-alpha")

testImplementation("org.junit.jupiter:junit-jupiter-api:${versions.junit}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions.junit}")
testRuntimeOnly("ch.qos.logback:logback-classic:1.4.6")
testRuntimeOnly('ch.qos.logback:logback-classic:1.5.6')

//Otel Java instrumentation that we use and extend during integration tests
// Otel Java instrumentation that we use and extend during integration tests
otel("io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}")

//TODO remove when start using io.opentelemetry.instrumentation.javaagent-instrumentation plugin
// TODO remove when start using io.opentelemetry.instrumentation.javaagent-instrumentation plugin
add("codegen", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
add("muzzleBootstrap", "io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations-support:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
}

//Produces a copy of upstream javaagent with this extension jar included inside it
//The location of extension directory inside agent jar is hard-coded in the agent source code
// Produces a copy of upstream javaagent with this extension jar included inside it
// The location of extension directory inside agent jar is hard-coded in the agent source code
tasks.register('extendedAgent', Jar) {
dependsOn(configurations.otel)
archiveFileName = "opentelemetry-javaagent.jar"
Expand All @@ -127,12 +125,12 @@ tasks.register('extendedAgent', Jar) {
into "extensions"
}

//Preserve MANIFEST.MF file from the upstream javaagent
// Preserve MANIFEST.MF file from the upstream javaagent
doFirst {
manifest.from(
zipTree(configurations.otel.singleFile).matching {
include 'META-INF/MANIFEST.MF'
}.singleFile
zipTree(configurations.otel.singleFile).matching {
include 'META-INF/MANIFEST.MF'
}.singleFile
)
}
}
Expand All @@ -150,7 +148,7 @@ tasks {
}

compileJava {
options.release.set(8)
options.release.set(17)
}

assemble.dependsOn(shadowJar)
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package rocks.inspectit.gepard.agent;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.AgentExtension;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("unused")
@AutoService(AgentExtension.class)
public class InspectitAgentExtension implements AgentExtension {

private static final Logger log = LoggerFactory.getLogger(InspectitAgentExtension.class);

@Override
public AgentBuilder extend(AgentBuilder agentBuilder, ConfigProperties config) {
log.info("Starting inspectIT Gepard agent extension ...");

return agentBuilder;
}

@Override
public String extensionName() {
return "inspectit-gepard";
}
}

0 comments on commit a7b01db

Please sign in to comment.