From b24342be160a235d7b7c1b1bb4b2d96f3e63d4ac Mon Sep 17 00:00:00 2001 From: Eduard Schander <66794307+EddeCCC@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:23:59 +0200 Subject: [PATCH 1/2] feature: prevent span duplicates (#22) * feature: prevent span duplicates * refactor: sonarcloud issues * prevent duplicate GitHub workflow * revert last commit * refactor: add null-check * refactor: replace exception with return value * test: add util tests * fix test * refactor: use ReadableSpan instead of SdkSpan * fix gradle group * apply spotless * exclude our classes from transformation * push docker images for every branch * update workflow * try fix workflow * fix image tag format * apply requested changes --- .github/workflows/ci-feature.yml | 59 --------- ...master.yml => ci-test-and-push-docker.yml} | 44 ++++--- inspectit-gepard-agent/build.gradle | 2 +- .../hook/action/SpanAction.java | 38 +++--- .../hook/action/util/SpanUtil.java | 27 ++++ .../internal/otel/OpenTelemetryAccessor.java | 25 ++-- .../transformation/TransformationManager.java | 17 ++- .../hook/action/util/SpanUtilTest.java | 61 ++++++++++ .../spring/trace/TracingTest.java | 115 +++++++++++------- 9 files changed, 237 insertions(+), 151 deletions(-) delete mode 100644 .github/workflows/ci-feature.yml rename .github/workflows/{cr-master.yml => ci-test-and-push-docker.yml} (78%) create mode 100644 inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtil.java create mode 100644 inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtilTest.java diff --git a/.github/workflows/ci-feature.yml b/.github/workflows/ci-feature.yml deleted file mode 100644 index 3ef2dc6..0000000 --- a/.github/workflows/ci-feature.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Feature Branch Continous Integration - -on: - push: - branches: - - "feature/**" - pull_request: - -jobs: - build-and-test: - name: "Build and test extension" - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. - # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md - - name: Setup Gradle - uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 - with: - build-scan-publish: true - build-scan-terms-of-service-url: 'https://gradle.com/terms-of-service' - build-scan-terms-of-service-agree: 'yes' - - - name: Test - run: ./gradlew test - - - name: Build - run: ./gradlew extendedAgent - - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - with: - name: Package - path: build/libs - - dependency-submission: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 diff --git a/.github/workflows/cr-master.yml b/.github/workflows/ci-test-and-push-docker.yml similarity index 78% rename from .github/workflows/cr-master.yml rename to .github/workflows/ci-test-and-push-docker.yml index 7cfa1e6..174847c 100644 --- a/.github/workflows/cr-master.yml +++ b/.github/workflows/ci-test-and-push-docker.yml @@ -1,11 +1,11 @@ -# This workflow is triggered on pushes to the master branch. -# It builds the agent and creates a multi-arch image for it. +# This workflow builds the agent and creates a multi-arch image for it. # The image is then pushed to Docker Hub. # -# The workflow consists of three jobs: -# 1. build-agent: Builds the agent and uploads the resulting JAR as an artifact. -# 2. build-image: Builds a Docker image for multiple platforms with the matrix strategy. -# 3. merge: Merges the images for the different platforms into a manifest list and pushes it to Docker Hub. +# The workflow consists of the following jobs: +# 1. build-agent-jar: Builds the agent and uploads the resulting JAR as an artifact. +# 2. dependency-submission: Generate a dependency graph. +# 2. build-docker-images: Builds a Docker image for multiple platforms with the matrix strategy. +# 3. merge-images: Merges the images for the different platforms into a manifest list and pushes it to Docker Hub. # To make the build faster, we use a matrix strategy to build the image for multiple platforms in parallel. # The build of the first job is copied over to the image build jobs, so that the application build is only done once. @@ -14,18 +14,16 @@ # For more information about how to build multi-arch images and advanced settings with Docker Buildx in GitHub actions, see: # https://docs.docker.com/build/ci/github-actions/multi-platform/ -name: Master Branch Continuous Release +name: Branch Continuous Integration on: push: - branches: - - master env: REGISTRY_IMAGE: inspectit/inspectit-gepard-agent jobs: - build-agent: + build-agent-jar: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -56,9 +54,26 @@ jobs: name: agent-artifact path: inspectit-gepard-agent/build/libs/inspectit-gepard-agent.jar - build-image: + dependency-submission: runs-on: ubuntu-latest - needs: build-agent + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. + # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + build-docker-images: + runs-on: ubuntu-latest + needs: build-agent-jar strategy: fail-fast: false matrix: @@ -124,10 +139,9 @@ jobs: if-no-files-found: error retention-days: 1 - merge: + merge-images: runs-on: ubuntu-latest - needs: - - build-image + needs: build-docker-images steps: - name: Download digests uses: actions/download-artifact@v4 diff --git a/inspectit-gepard-agent/build.gradle b/inspectit-gepard-agent/build.gradle index f54bc91..8f66635 100644 --- a/inspectit-gepard-agent/build.gradle +++ b/inspectit-gepard-agent/build.gradle @@ -19,7 +19,7 @@ plugins { id "com.palantir.docker" version "0.36.0" } -group 'rocks.inspectit.gepard.agent' +group 'rocks.inspectit.gepard' version = "0.0.1-SNAPSHOT" sourceCompatibility = "17" diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/SpanAction.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/SpanAction.java index 44f28a6..fb574e4 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/SpanAction.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/SpanAction.java @@ -1,54 +1,52 @@ /* (C) 2024 */ package rocks.inspectit.gepard.agent.instrumentation.hook.action; -import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import rocks.inspectit.gepard.agent.instrumentation.hook.action.exception.CouldNotCloseSpanScopeException; +import rocks.inspectit.gepard.agent.instrumentation.hook.action.util.SpanUtil; import rocks.inspectit.gepard.agent.internal.otel.OpenTelemetryAccessor; /** This action contains the logic to start and end a {@link Span}. */ public class SpanAction { - - private static final String INSTRUMENTATION_SCOPE_NAME = "inspectit-gepard"; - - private final OpenTelemetry openTelemetry; - - public SpanAction() { - this.openTelemetry = OpenTelemetryAccessor.getOpenTelemetry(); - } + private static final Logger log = LoggerFactory.getLogger(SpanAction.class); /** * Starts a new {@link Span}. Should be called before {@link SpanAction#endSpan}. * * @param spanName the name of the span - * @return the scope of the started span + * @return the scope of the started span or null, if the current span has the same name */ public AutoCloseable startSpan(String spanName) { - Span.current().getSpanContext(); + // In the future, we still might want to set some attributes in the current span + if (SpanUtil.spanAlreadyExists(spanName)) { + log.debug("Span '{}' already exists at the moment. No new span will be started", spanName); + return null; + } - Tracer tracer = openTelemetry.getTracer(INSTRUMENTATION_SCOPE_NAME); + Tracer tracer = OpenTelemetryAccessor.getTracer(); Span span = tracer.spanBuilder(spanName).setParent(Context.current()).startSpan(); return span.makeCurrent(); } /** * Ends the current span and closes its scope. Should be called after {@link - * SpanAction#startSpan}. + * SpanAction#startSpan}. If the scope is null, we won't do anything. * * @param spanScope the scope of the span, which should be finished */ public void endSpan(AutoCloseable spanScope) { - Span current = Span.current(); + if (Objects.isNull(spanScope)) return; - if (Objects.nonNull(spanScope)) { - try { - spanScope.close(); - } catch (Exception e) { - throw new CouldNotCloseSpanScopeException(e); - } + Span current = Span.current(); + try { + spanScope.close(); + } catch (Exception e) { + throw new CouldNotCloseSpanScopeException(e); } current.end(); } diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtil.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtil.java new file mode 100644 index 0000000..09945c7 --- /dev/null +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtil.java @@ -0,0 +1,27 @@ +/* (C) 2024 */ +package rocks.inspectit.gepard.agent.instrumentation.hook.action.util; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.sdk.trace.ReadableSpan; + +/** Util class to access span data, like the name or attributes. */ +public class SpanUtil { + + private SpanUtil() {} + + /** + * Checks, if the current span uses the provided span name. This check might be necessary to + * prevent span duplicates. For example, we would like to create a span for a method, which is + * already recorded by OpenTelemetry. In this case, we should not create a new span. + * + * @param spanName the name of the span with the format 'SimpleClassName.methodName', for instance + * 'SpanUtil.spanAlreadyExists' + * @return true, if the current span uses the provided span name + */ + public static boolean spanAlreadyExists(String spanName) { + Span span = Span.current(); + + if (span instanceof ReadableSpan readableSpan) return spanName.equals(readableSpan.getName()); + return false; + } +} diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/otel/OpenTelemetryAccessor.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/otel/OpenTelemetryAccessor.java index f95865f..2da215a 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/otel/OpenTelemetryAccessor.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/otel/OpenTelemetryAccessor.java @@ -3,25 +3,23 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; /** - * Singleton to access the {@link OpenTelemetry} instance. We use this accessor, because according - * to the documentation of {@link GlobalOpenTelemetry}, the get() method should only be called once - * during the application. + * Singleton to access the OpenTelemetry API. We use this accessor, because according to the + * documentation of {@link GlobalOpenTelemetry}, the get() method should only be called once during + * the application. */ public class OpenTelemetryAccessor { + /** The instrumentation scope name we use for our spans and metrics */ + public static final String INSTRUMENTATION_SCOPE_NAME = "inspectit-gepard"; + + /** Our global OpenTelemetry instance */ private static OpenTelemetry openTelemetry; private OpenTelemetryAccessor() {} - /** - * @return the global {@link OpenTelemetry} instance - */ - public static OpenTelemetry getOpenTelemetry() { - return openTelemetry; - } - /** * Sets the global {@link OpenTelemetry} instance for inspectIT. This will allow us to create * traces or metrics. Should only be called once. @@ -31,4 +29,11 @@ public static OpenTelemetry getOpenTelemetry() { public static void setOpenTelemetry(OpenTelemetry otel) { openTelemetry = otel; } + + /** + * @return the tracer to create spans + */ + public static Tracer getTracer() { + return openTelemetry.getTracer(INSTRUMENTATION_SCOPE_NAME); + } } diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/transformation/TransformationManager.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/transformation/TransformationManager.java index c8609dc..b987399 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/transformation/TransformationManager.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/transformation/TransformationManager.java @@ -1,9 +1,11 @@ /* (C) 2024 */ package rocks.inspectit.gepard.agent.transformation; -import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.*; import net.bytebuddy.agent.builder.AgentBuilder; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; import rocks.inspectit.gepard.agent.instrumentation.state.InstrumentationState; /** Responsible component for setting up class transformation for instrumentation */ @@ -34,7 +36,16 @@ public AgentBuilder modify(AgentBuilder agentBuilder) { DynamicTransformer transformer = new DynamicTransformer(instrumentationState); InspectitListener listener = new InspectitListener(); - // In the future, we might add a white- or black-list for types - return agentBuilder.type(any()).transform(transformer).with(listener); + return agentBuilder.type(typeMatcher()).transform(transformer).with(listener); + } + + /** + * Defines all types, which should (or should not) be transformed. We don't want to transform our + * own classes. + * + * @return the type matcher for transformation + */ + private ElementMatcher.Junction typeMatcher() { + return not(nameStartsWith("rocks.inspectit.gepard.agent")); } } diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtilTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtilTest.java new file mode 100644 index 0000000..5018219 --- /dev/null +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/hook/action/util/SpanUtilTest.java @@ -0,0 +1,61 @@ +/* (C) 2024 */ +package rocks.inspectit.gepard.agent.instrumentation.hook.action.util; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.Scope; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class SpanUtilTest { + + private Tracer tracer; + + private final String spanName = "SpanUtilTest.method"; + + @BeforeEach + void beforeEach() { + GlobalOpenTelemetry.resetForTest(); + OpenTelemetry openTelemetry = OpenTelemetrySdk.builder().buildAndRegisterGlobal(); + tracer = openTelemetry.getTracer("inspectit-gepard"); + } + + @Test + void shouldReturnTrueWhenSpanExists() throws Exception { + Span span = tracer.spanBuilder(spanName).startSpan(); + Scope scope = span.makeCurrent(); + + boolean exists = SpanUtil.spanAlreadyExists(spanName); + + assertTrue(exists); + + scope.close(); + span.end(); + } + + @Test + void shouldReturnFalseWhenNoSpanExists() throws Exception { + boolean exists = SpanUtil.spanAlreadyExists(spanName); + + assertFalse(exists); + } + + @Test + void shouldReturnFalseWhenOtherSpanExists() throws Exception { + Span span = tracer.spanBuilder("dummy").startSpan(); + Scope scope = span.makeCurrent(); + + boolean exists = SpanUtil.spanAlreadyExists(spanName); + + assertFalse(exists); + + scope.close(); + span.end(); + } +} diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/trace/TracingTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/trace/TracingTest.java index 334fb1f..a3fa32b 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/trace/TracingTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/trace/TracingTest.java @@ -1,15 +1,15 @@ /* (C) 2024 */ package rocks.inspectit.gepard.agent.integrationtest.spring.trace; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static rocks.inspectit.gepard.agent.internal.otel.OpenTelemetryAccessor.INSTRUMENTATION_SCOPE_NAME; import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest; +import io.opentelemetry.proto.trace.v1.ResourceSpans; import io.opentelemetry.proto.trace.v1.ScopeSpans; import io.opentelemetry.proto.trace.v1.Span; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; +import java.util.function.Predicate; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import rocks.inspectit.gepard.agent.integrationtest.spring.SpringTestBase; @@ -21,12 +21,6 @@ class TracingTest extends SpringTestBase { private static final String childSpanName = "WebController.withSpan"; - @Override - protected Map getExtraEnv() { - // We need to disable the OTel annotations to prevent span duplicates - return Map.of("OTEL_INSTRUMENTATION_OPENTELEMETRY_EXTENSION_ANNOTATIONS_ENABLED", "false"); - } - @Test void shouldSendSpansToBackendWhenScopesAreActive() throws Exception { configurationServerMock.configServerSetup(configDir + "simple-scope.json"); @@ -52,8 +46,8 @@ void shouldNotSendSpansToBackendWhenNoScopesAreActive() throws Exception { } /** - * This method asserts that spans with the given names exist and that the child's {@link - * Span#getParentSpanId()} equals the parent's {@link Span#getSpanId()}. + * This method asserts that spans with the given names exist, they appear in the same trace and + * that the child's {@link Span#getParentSpanId()} equals the parent's {@link Span#getSpanId()}. * * @param traces the collection of traces * @param parentSpanName the name of the parent span @@ -61,26 +55,26 @@ void shouldNotSendSpansToBackendWhenNoScopesAreActive() throws Exception { */ private void assertSpans( Collection traces, String parentSpanName, String childSpanName) { - Stream> spanLists = getSpanLists(traces); - - assertTrue( - spanLists.anyMatch( - spans -> { - Optional parentSpan = findSpan(spans, parentSpanName); - if (parentSpan.isEmpty()) return false; - - Optional childSpan = findSpan(spans, childSpanName); - if (childSpan.isEmpty()) return false; - - // We cannot compare the ByteStrings directly, because they are different objects - String childParentId = childSpan.get().getParentSpanId().toStringUtf8(); - String parentId = parentSpan.get().getSpanId().toStringUtf8(); - return childParentId.equals(parentId); - })); + List spans = getSpans(traces); + + Optional parentSpan = findSpan(spans, parentSpanName); + Optional childSpan = findSpan(spans, childSpanName); + boolean spansExist = parentSpan.isPresent() && childSpan.isPresent(); + + assertTrue(spansExist); + + // We cannot compare the ByteStrings directly, because they are different objects + String parentId = parentSpan.get().getSpanId().toStringUtf8(); + String childParentId = childSpan.get().getParentSpanId().toStringUtf8(); + String parentTraceId = parentSpan.get().getTraceId().toStringUtf8(); + String childTraceId = childSpan.get().getTraceId().toStringUtf8(); + + assertEquals(parentId, childParentId); + assertEquals(parentTraceId, childTraceId); } /** - * This method asserts that no spans with the given names exist. + * This method asserts that no spans from inspectIT with the given names exist. * * @param traces the collection of traces * @param parentSpanName the name of the parent span @@ -88,33 +82,68 @@ private void assertSpans( */ private void assertNoSpans( Collection traces, String parentSpanName, String childSpanName) { - Stream> spanLists = getSpanLists(traces); + List spans = getInspectItSpans(traces); - assertTrue( - spanLists.anyMatch( - spans -> { - Optional parentSpan = findSpan(spans, parentSpanName); - Optional childSpan = findSpan(spans, childSpanName); + Optional parentSpan = findSpan(spans, parentSpanName); + Optional childSpan = findSpan(spans, childSpanName); + boolean noSpanExist = parentSpan.isEmpty() && childSpan.isEmpty(); - return parentSpan.isEmpty() && childSpan.isEmpty(); - })); + assertTrue(noSpanExist); + } + + /** + * Maps the provided traces to a collection of spans. + * + * @param traces the collection of traces + * @return the collection of span within the provided traces + */ + private List getSpans(Collection traces) { + Predicate scopeFilter = (scopeName) -> true; + return getSpans(traces, scopeFilter); } /** - * Maps the provided traces to a collection of span lists. + * Maps the provided traces to a collection of spans, which were created by inspectIT. * * @param traces the collection of traces - * @return the collection of span lists within the provided traces + * @return the collection of span within the provided traces */ - private Stream> getSpanLists(Collection traces) { + private List getInspectItSpans(Collection traces) { + Predicate scopeFilter = (scopeName) -> scopeName.equals(INSTRUMENTATION_SCOPE_NAME); + return getSpans(traces, scopeFilter); + } + + /** + * Maps the provided traces to a collection of spans filtered by a specific instrumentation scope. + * + * @param traces the collection of traces + * @param scopeFilter the filter for the instrumentation scope + * @return the filtered collection of span within the provided traces + */ + private List getSpans( + Collection traces, Predicate scopeFilter) { return traces.stream() .flatMap( trace -> trace.getResourceSpansList().stream() .flatMap( resourceSpans -> - resourceSpans.getScopeSpansList().stream() - .map(ScopeSpans::getSpansList))); + filterAndExtractSpans(resourceSpans.getScopeSpansList(), scopeFilter))) + .toList(); + } + + /** + * Filters and extracts all {@link Span}s from {@link ScopeSpans}. + * + * @param scopeSpansList the list of {@link ScopeSpans} from {@link ResourceSpans} + * @param scopeFilter the filter for the instrumentation scope + * @return the collection of filtered spans as stream + */ + private Stream filterAndExtractSpans( + List scopeSpansList, Predicate scopeFilter) { + return scopeSpansList.stream() + .filter(scopeSpans -> scopeFilter.test(scopeSpans.getScope().getName())) + .flatMap(scopeSpans -> scopeSpans.getSpansList().stream()); } /** From 489bbbe10fe97ede0c6e7909459603b8d014b8e1 Mon Sep 17 00:00:00 2001 From: Eduard Schander <66794307+EddeCCC@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:39:11 +0200 Subject: [PATCH 2/2] feature: use configuration as dependency (#23) * feature: use configuration as dependency * test: add config as test dependency * add PAT to workflow * adjust config version * add PAT to workflow --- .github/workflows/ci-test-and-push-docker.yml | 1 + CONTRIBUTING.md | 18 ++++++++- build.gradle | 8 ++++ inspectit-gepard-agent/build.gradle | 3 +- .../http/HttpConfigurationCallback.java | 2 +- .../persistence/ConfigurationPersistence.java | 2 +- .../file/ConfigurationFileReader.java | 2 +- .../file/ConfigurationFileWriter.java | 2 +- .../configuration/ConfigurationResolver.java | 2 +- .../InspectitConfigurationHolder.java | 2 +- .../configuration/scope/ScopeResolver.java | 14 +++---- .../model/InspectitConfiguration.java | 22 ----------- .../InstrumentationConfiguration.java | 29 --------------- .../model/instrumentation/Scope.java | 37 ------------------- .../observer/ConfigurationReceivedEvent.java | 2 +- .../ConfigurationReceivedSubject.java | 2 +- .../util/ConfigurationMapper.java | 2 +- .../model/InstrumentationScope.java | 6 +-- .../ConfigurationPersistenceTest.java | 9 +++-- .../file/ConfigurationFileReaderTest.java | 6 +-- .../file/ConfigurationFileWriterTest.java | 9 +++-- .../input/ConfigurationReceiverTest.java | 2 +- .../ConfigurationResolverTest.java | 8 ++-- .../InspectitConfigurationHolderTest.java | 9 +++-- .../scope/ScopeResolverTest.java | 12 +++--- .../ConfigurationReceivedSubjectTest.java | 2 +- .../util/ConfigurationMapperTest.java | 9 +++-- .../testutils/InspectitConfigurationUtil.java | 15 ++++---- 28 files changed, 90 insertions(+), 147 deletions(-) delete mode 100644 inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/InspectitConfiguration.java delete mode 100644 inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/InstrumentationConfiguration.java delete mode 100644 inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/Scope.java diff --git a/.github/workflows/ci-test-and-push-docker.yml b/.github/workflows/ci-test-and-push-docker.yml index 174847c..fb422bc 100644 --- a/.github/workflows/ci-test-and-push-docker.yml +++ b/.github/workflows/ci-test-and-push-docker.yml @@ -21,6 +21,7 @@ on: env: REGISTRY_IMAGE: inspectit/inspectit-gepard-agent + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build-agent-jar: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index de33175..09ba73a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,22 @@ We recommend using [IntelliJ](https://www.jetbrains.com/idea/download/#section=windows) as IDE for contributing. +## Dependencies + +We integrate our [inspectit-gepard-config](https://github.com/inspectIT/inspectit-gepard-config) model as dependency. We download the dependency +from GitHub Packages, which requires authentication. To set up your authentication, follow these steps: + +1. Create a `gradle.properties` file in `%userprofile%\.gradle` +2. Create a [(classic) personal access token (PAT)](https://github.com/settings/tokens) with `read:packages` permissions. +3. Paste the following content into your `gradle.properties`: + +``` +gpr.inspectit.gepard.user= +gpr.inspectit.gepard.token= +``` + +You can find more information here as well: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry + ## Formatting We have [spotless](https://github.com/diffplug/spotless) configured to format the code. You can run the following commands: @@ -29,4 +45,4 @@ To run the tests, use the command `./gradlew test`. ## Releasing -Currently, there is no automatic release process, as we are still in the early stages of development. \ No newline at end of file +Currently, there is no automatic release process, as we are still in the early stages of development. diff --git a/build.gradle b/build.gradle index c1e95a5..28caca3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,14 @@ allprojects { name = "sonatype" url = uri("https://oss.sonatype.org/content/repositories/snapshots") } + maven { + name = "inspectit-gepard-config" + url = uri("https://maven.pkg.github.com/inspectIT/inspectit-gepard-config") + credentials { + username = project.findProperty("gpr.inspectit.gepard.user") ?: System.getenv("GITHUB_ACTOR") + password = project.findProperty("gpr.inspectit.gepard.token") ?: System.getenv("GITHUB_TOKEN") + } + } } apply plugin: "java" diff --git a/inspectit-gepard-agent/build.gradle b/inspectit-gepard-agent/build.gradle index 8f66635..6f10593 100644 --- a/inspectit-gepard-agent/build.gradle +++ b/inspectit-gepard-agent/build.gradle @@ -20,7 +20,7 @@ plugins { } group 'rocks.inspectit.gepard' -version = "0.0.1-SNAPSHOT" +def configVersion = "3.0.1-dev" sourceCompatibility = "17" targetCompatibility = "17" @@ -70,6 +70,7 @@ dependencies { implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${versions.opentelemetryJavaagentAlpha}")) // inspectit-gepard dependencies + implementation("rocks.inspectit.gepard:inspectit-gepard-config:${configVersion}") implementation("net.bytebuddy:byte-buddy:1.14.15") implementation("ch.qos.logback:logback-classic:1.5.6") implementation("org.slf4j:slf4j-api:2.0.16") diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/http/HttpConfigurationCallback.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/http/HttpConfigurationCallback.java index 4c26c78..b0b453f 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/http/HttpConfigurationCallback.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/http/HttpConfigurationCallback.java @@ -6,9 +6,9 @@ import org.apache.hc.core5.concurrent.FutureCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedSubject; import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** Callback for configuration requests to the configuration server. */ public class HttpConfigurationCallback implements FutureCallback { diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistence.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistence.java index eab3fc0..eee2c26 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistence.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistence.java @@ -6,10 +6,10 @@ import org.slf4j.LoggerFactory; import rocks.inspectit.gepard.agent.configuration.persistence.file.ConfigurationFileReader; import rocks.inspectit.gepard.agent.configuration.persistence.file.ConfigurationFileWriter; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedObserver; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedSubject; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** * Responsible for accessing the persisted agent configuration as well as keeping the configuration diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReader.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReader.java index 3417ffd..6e11ed9 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReader.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReader.java @@ -4,9 +4,9 @@ import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper; import rocks.inspectit.gepard.agent.internal.file.FileAccessor; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** Reads the agent configuration persistence file. */ public class ConfigurationFileReader { diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriter.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriter.java index 999fedc..9d15b2f 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriter.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriter.java @@ -4,9 +4,9 @@ import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper; import rocks.inspectit.gepard.agent.internal.file.FileAccessor; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** * Writes into the agent configuration persistence file. After every configuration update, the diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolver.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolver.java index a47905f..ca29aa1 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolver.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolver.java @@ -5,10 +5,10 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import rocks.inspectit.gepard.agent.instrumentation.state.configuration.scope.ScopeResolver; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; import rocks.inspectit.gepard.agent.internal.instrumentation.InstrumentedType; import rocks.inspectit.gepard.agent.internal.instrumentation.model.ClassInstrumentationConfiguration; import rocks.inspectit.gepard.agent.internal.instrumentation.model.InstrumentationScope; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; /** * Utility class to resolve the {@link InstrumentationConfiguration} and determine whether class diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolder.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolder.java index 26b84d2..2b456db 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolder.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolder.java @@ -3,9 +3,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedObserver; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** * When the agent receives a new configuration, it will notify this holder about the new diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolver.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolver.java index 13a58fe..9d993d5 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolver.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolver.java @@ -9,13 +9,13 @@ import rocks.inspectit.gepard.agent.instrumentation.state.configuration.InspectitConfigurationHolder; import rocks.inspectit.gepard.agent.instrumentation.state.configuration.matcher.CustomElementMatchers; import rocks.inspectit.gepard.agent.instrumentation.state.configuration.matcher.MatcherChainBuilder; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.instrumentation.model.InstrumentationScope; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; /** - * This class is used to resolve the {@link Scope} based on the {@link Scope} List, contained in the - * {@link InstrumentationConfiguration}. + * This class is used to resolve the {@link ScopeConfiguration} based on the {@link + * ScopeConfiguration} List, contained in the {@link InstrumentationConfiguration}. */ public class ScopeResolver { @@ -34,9 +34,9 @@ public ScopeResolver(InspectitConfigurationHolder holder) { public Set getActiveScopes(String fullyQualifiedName) { if (shouldIgnore(fullyQualifiedName)) return Collections.emptySet(); - List scopes = getAllMatchingScopes(fullyQualifiedName); + List scopes = getAllMatchingScopes(fullyQualifiedName); return scopes.stream() - .filter(Scope::isEnabled) + .filter(ScopeConfiguration::isEnabled) .map(InstrumentationScope::create) .collect(Collectors.toSet()); } @@ -61,7 +61,7 @@ public ElementMatcher.Junction getMethodMatcher( * @param fqn the fully qualified name to match * @return the list of matching scopes */ - private List getAllMatchingScopes(String fqn) { + private List getAllMatchingScopes(String fqn) { return holder.getConfiguration().getInstrumentation().getAllMatchingScopes(fqn); } diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/InspectitConfiguration.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/InspectitConfiguration.java deleted file mode 100644 index e0c310e..0000000 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/InspectitConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -/* (C) 2024 */ -package rocks.inspectit.gepard.agent.internal.configuration.model; - -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; - -/** Model of an inspectit gepard configuration. */ -public class InspectitConfiguration { - - private InstrumentationConfiguration instrumentation; - - public InspectitConfiguration() { - this.instrumentation = new InstrumentationConfiguration(); - } - - public InspectitConfiguration(InstrumentationConfiguration instrumentation) { - this.instrumentation = instrumentation; - } - - public InstrumentationConfiguration getInstrumentation() { - return instrumentation; - } -} diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/InstrumentationConfiguration.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/InstrumentationConfiguration.java deleted file mode 100644 index 5243e16..0000000 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/InstrumentationConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -/* (C) 2024 */ -package rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation; - -import java.util.List; - -/** - * The Instrumentation Configuration contains all configuration related to instrumentation. e.g - * scopes, rules, actions. - */ -public class InstrumentationConfiguration { - - private final List scopes; - - public InstrumentationConfiguration() { - this.scopes = List.of(); - } - - public InstrumentationConfiguration(List scopes) { - this.scopes = scopes; - } - - public List getScopes() { - return scopes; - } - - public List getAllMatchingScopes(String fqn) { - return scopes.stream().filter(scope -> scope.getFqn().equals(fqn)).toList(); - } -} diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/Scope.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/Scope.java deleted file mode 100644 index 29ef885..0000000 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/model/instrumentation/Scope.java +++ /dev/null @@ -1,37 +0,0 @@ -/* (C) 2024 */ -package rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation; - -import java.util.List; - -/** - * Represents a scope in the instrumentation configuration. A scope defines a set of methods which - * should be instrumented. - */ -public class Scope { - - private boolean enabled; - - private String fqn; - - private List methods; - - public Scope() {} - - public Scope(boolean enabled, String fqn, List methods) { - this.fqn = fqn; - this.methods = methods; - this.enabled = enabled; - } - - public boolean isEnabled() { - return enabled; - } - - public String getFqn() { - return fqn; - } - - public List getMethods() { - return methods; - } -} diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedEvent.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedEvent.java index 4648b1d..e84ddc9 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedEvent.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedEvent.java @@ -2,7 +2,7 @@ package rocks.inspectit.gepard.agent.internal.configuration.observer; import java.util.EventObject; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** Event, which should be published, after the {@link InspectitConfiguration} changed. */ public class ConfigurationReceivedEvent extends EventObject { diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubject.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubject.java index ba8401c..2e6c736 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubject.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubject.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** * Observer pattern subject, which notifies all registered observers about {@link diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapper.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapper.java index 284f2ba..a3bd7da 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapper.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapper.java @@ -6,7 +6,7 @@ import java.util.Objects; import rocks.inspectit.gepard.agent.internal.configuration.exception.CouldNotDeserializeConfigurationException; import rocks.inspectit.gepard.agent.internal.configuration.exception.CouldNotSerializeConfigurationException; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; /** Utility class for mapping configuration strings to configuration objects. */ public class ConfigurationMapper { diff --git a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/instrumentation/model/InstrumentationScope.java b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/instrumentation/model/InstrumentationScope.java index ab64633..6c76120 100644 --- a/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/instrumentation/model/InstrumentationScope.java +++ b/inspectit-gepard-agent/src/main/java/rocks/inspectit/gepard/agent/internal/instrumentation/model/InstrumentationScope.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Objects; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; /** * @param fqn the fully qualified name of a class @@ -12,12 +12,12 @@ public record InstrumentationScope(String fqn, List methods) { /** - * Creates an {@link InstrumentationScope} out of a {@link Scope} + * Creates an {@link InstrumentationScope} out of a {@link ScopeConfiguration} * * @param scope the scope * @return the instrumentation scope */ - public static InstrumentationScope create(Scope scope) { + public static InstrumentationScope create(ScopeConfiguration scope) { return new InstrumentationScope(scope.getFqn(), scope.getMethods()); } diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistenceTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistenceTest.java index 5501a28..00e315a 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistenceTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/ConfigurationPersistenceTest.java @@ -15,12 +15,12 @@ import org.mockito.junit.jupiter.MockitoExtension; import rocks.inspectit.gepard.agent.configuration.persistence.file.ConfigurationFileReader; import rocks.inspectit.gepard.agent.configuration.persistence.file.ConfigurationFileWriter; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedObserver; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedSubject; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; @ExtendWith(MockitoExtension.class) public class ConfigurationPersistenceTest { @@ -82,7 +82,8 @@ void newConfigurationNotifiesObservers() { } private static InspectitConfiguration createConfiguration() { - Scope scope = new Scope(true, "com.example.Application", Collections.emptyList()); + ScopeConfiguration scope = + new ScopeConfiguration(true, "com.example.Application", Collections.emptyList()); InstrumentationConfiguration instrumentationConfiguration = new InstrumentationConfiguration(List.of(scope)); return new InspectitConfiguration(instrumentationConfiguration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReaderTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReaderTest.java index 8ec5fd3..81583b2 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReaderTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileReaderTest.java @@ -11,9 +11,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.file.FileAccessor; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; @ExtendWith(MockitoExtension.class) public class ConfigurationFileReaderTest { @@ -34,7 +34,7 @@ void fileContentIsMappedToConfiguration() throws IOException { when(fileAccessor.readFile()).thenReturn(expectedString); InspectitConfiguration configuration = reader.readConfiguration(); - List scopes = configuration.getInstrumentation().getScopes(); + List scopes = configuration.getInstrumentation().getScopes(); boolean foundScope = scopes.stream().anyMatch(scope -> expectedScope.equals(scope.getFqn())); assertTrue(foundScope); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriterTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriterTest.java index fe27017..e9f1bba 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriterTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/configuration/persistence/file/ConfigurationFileWriterTest.java @@ -14,10 +14,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.file.FileAccessor; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; @ExtendWith(MockitoExtension.class) public class ConfigurationFileWriterTest { @@ -49,7 +49,8 @@ void nullIsNotWrittenToFile() throws IOException { } private static InspectitConfiguration createConfiguration() { - Scope scope = new Scope(true, "com.example.Application", Collections.emptyList()); + ScopeConfiguration scope = + new ScopeConfiguration(true, "com.example.Application", Collections.emptyList()); InstrumentationConfiguration instrumentationConfiguration = new InstrumentationConfiguration(List.of(scope)); return new InspectitConfiguration(instrumentationConfiguration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/cache/input/ConfigurationReceiverTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/cache/input/ConfigurationReceiverTest.java index 76ae845..97b6e92 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/cache/input/ConfigurationReceiverTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/cache/input/ConfigurationReceiverTest.java @@ -10,8 +10,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import rocks.inspectit.gepard.agent.instrumentation.cache.PendingClassesCache; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; @ExtendWith(MockitoExtension.class) class ConfigurationReceiverTest { diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolverTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolverTest.java index 9a67dfe..3fa68b2 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolverTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/ConfigurationResolverTest.java @@ -12,10 +12,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.instrumentation.InstrumentedType; import rocks.inspectit.gepard.agent.internal.instrumentation.model.ClassInstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; @ExtendWith(MockitoExtension.class) class ConfigurationResolverTest { @@ -46,7 +46,7 @@ void typeShouldNotBeInstrumented() { @Test void typeShouldBeInstrumented() { - Scope scope = createScope(true, getClass().getName()); + ScopeConfiguration scope = createScope(true, getClass().getName()); InspectitConfiguration configuration = createConfiguration(List.of(scope)); when(holder.getConfiguration()).thenReturn(configuration); @@ -59,7 +59,7 @@ void typeShouldBeInstrumented() { @Test void typeShouldBeDeinstrumented() { - Scope scope = createScope(false, getClass().getName()); + ScopeConfiguration scope = createScope(false, getClass().getName()); InspectitConfiguration configuration = createConfiguration(List.of(scope)); when(holder.getConfiguration()).thenReturn(configuration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolderTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolderTest.java index f310981..ebb93d3 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolderTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/InspectitConfigurationHolderTest.java @@ -7,10 +7,10 @@ import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; class InspectitConfigurationHolderTest { @@ -35,7 +35,8 @@ void configurationIsUpdated() { } private InspectitConfiguration createConfiguration() { - Scope scope = new Scope(true, "com.example.Application", Collections.emptyList()); + ScopeConfiguration scope = + new ScopeConfiguration(true, "com.example.Application", Collections.emptyList()); InstrumentationConfiguration instrumentationConfiguration = new InstrumentationConfiguration(List.of(scope)); return new InspectitConfiguration(instrumentationConfiguration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolverTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolverTest.java index 5dc811c..e7cd7d4 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolverTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/instrumentation/state/configuration/scope/ScopeResolverTest.java @@ -19,9 +19,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import rocks.inspectit.gepard.agent.instrumentation.state.configuration.InspectitConfigurationHolder; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; import rocks.inspectit.gepard.agent.internal.instrumentation.model.InstrumentationScope; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; @ExtendWith(MockitoExtension.class) class ScopeResolverTest { @@ -34,10 +34,10 @@ class ScopeResolverTest { @Test void returnsOnlyActiveScopes() { - Scope matchingScope = createScope(true, CLASS_NAME, List.of("method")); - Scope nonMatchingScope1 = createScope(false, CLASS_NAME); - Scope nonMatchingScope2 = createScope(true, "dummyName"); - List scopes = List.of(matchingScope, nonMatchingScope1, nonMatchingScope2); + ScopeConfiguration matchingScope = createScope(true, CLASS_NAME, List.of("method")); + ScopeConfiguration nonMatchingScope1 = createScope(false, CLASS_NAME); + ScopeConfiguration nonMatchingScope2 = createScope(true, "dummyName"); + List scopes = List.of(matchingScope, nonMatchingScope1, nonMatchingScope2); InspectitConfiguration configuration = createConfiguration(scopes); when(holder.getConfiguration()).thenReturn(configuration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubjectTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubjectTest.java index 91b6287..d5e0622 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubjectTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/observer/ConfigurationReceivedSubjectTest.java @@ -5,7 +5,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.jupiter.api.Test; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; class ConfigurationReceivedSubjectTest { diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapperTest.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapperTest.java index 87db4e5..88302a6 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapperTest.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/internal/configuration/util/ConfigurationMapperTest.java @@ -8,9 +8,9 @@ import java.util.List; import org.junit.jupiter.api.Test; import rocks.inspectit.gepard.agent.internal.configuration.exception.CouldNotDeserializeConfigurationException; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; class ConfigurationMapperTest { @@ -63,7 +63,8 @@ private static String expectedString() { } private static InspectitConfiguration expectedConfig() { - Scope scope = new Scope(true, "com.example.Application", Collections.emptyList()); + ScopeConfiguration scope = + new ScopeConfiguration(true, "com.example.Application", Collections.emptyList()); InstrumentationConfiguration instrumentationConfiguration = new InstrumentationConfiguration(List.of(scope)); return new InspectitConfiguration(instrumentationConfiguration); diff --git a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/testutils/InspectitConfigurationUtil.java b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/testutils/InspectitConfigurationUtil.java index ff7ae43..dc0e5a6 100644 --- a/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/testutils/InspectitConfigurationUtil.java +++ b/inspectit-gepard-agent/src/test/java/rocks/inspectit/gepard/agent/testutils/InspectitConfigurationUtil.java @@ -3,9 +3,9 @@ import java.util.Collections; import java.util.List; -import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.InstrumentationConfiguration; -import rocks.inspectit.gepard.agent.internal.configuration.model.instrumentation.Scope; +import rocks.inspectit.gepard.config.model.InspectitConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration; +import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration; public class InspectitConfigurationUtil { @@ -13,7 +13,7 @@ public class InspectitConfigurationUtil { * @param scopes a list of scopes to be added to the configuration * @return the inspectit configuration with the current class as scope */ - public static InspectitConfiguration createConfiguration(List scopes) { + public static InspectitConfiguration createConfiguration(List scopes) { InstrumentationConfiguration instrumentationConfiguration = new InstrumentationConfiguration(scopes); return new InspectitConfiguration(instrumentationConfiguration); @@ -26,11 +26,12 @@ public static InspectitConfiguration createConfiguration(List scopes) { * @param methodNames the method names to be instrumented * @return the scope with the current class as fqn */ - public static Scope createScope(boolean enabled, String name, List methodNames) { - return new Scope(enabled, name, methodNames); + public static ScopeConfiguration createScope( + boolean enabled, String name, List methodNames) { + return new ScopeConfiguration(enabled, name, methodNames); } - public static Scope createScope(boolean enabled, String name) { + public static ScopeConfiguration createScope(boolean enabled, String name) { return createScope(enabled, name, Collections.emptyList()); } }