Skip to content

Commit

Permalink
feature: use configuration as dependency (#23)
Browse files Browse the repository at this point in the history
* feature: use configuration as dependency

* test: add config as test dependency

* add PAT to workflow

* adjust config version

* add PAT to workflow
  • Loading branch information
EddeCCC authored Oct 22, 2024
1 parent b24342b commit 489bbbe
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 147 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-test-and-push-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:

env:
REGISTRY_IMAGE: inspectit/inspectit-gepard-agent
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build-agent-jar:
Expand Down
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<YOUR_GITHUB_USERNAME>
gpr.inspectit.gepard.token=<YOUR_GITHUB_ACCESS_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:
Expand All @@ -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.
Currently, there is no automatic release process, as we are still in the early stages of development.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion inspectit-gepard-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
}

group 'rocks.inspectit.gepard'
version = "0.0.1-SNAPSHOT"
def configVersion = "3.0.1-dev"

sourceCompatibility = "17"
targetCompatibility = "17"
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleHttpResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -34,9 +34,9 @@ public ScopeResolver(InspectitConfigurationHolder holder) {
public Set<InstrumentationScope> getActiveScopes(String fullyQualifiedName) {
if (shouldIgnore(fullyQualifiedName)) return Collections.emptySet();

List<Scope> scopes = getAllMatchingScopes(fullyQualifiedName);
List<ScopeConfiguration> scopes = getAllMatchingScopes(fullyQualifiedName);
return scopes.stream()
.filter(Scope::isEnabled)
.filter(ScopeConfiguration::isEnabled)
.map(InstrumentationScope::create)
.collect(Collectors.toSet());
}
Expand All @@ -61,7 +61,7 @@ public ElementMatcher.Junction<MethodDescription> getMethodMatcher(
* @param fqn the fully qualified name to match
* @return the list of matching scopes
*/
private List<Scope> getAllMatchingScopes(String fqn) {
private List<ScopeConfiguration> getAllMatchingScopes(String fqn) {
return holder.getConfiguration().getInstrumentation().getAllMatchingScopes(fqn);
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,12 +12,12 @@
public record InstrumentationScope(String fqn, List<String> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,7 +34,7 @@ void fileContentIsMappedToConfiguration() throws IOException {
when(fileAccessor.readFile()).thenReturn(expectedString);

InspectitConfiguration configuration = reader.readConfiguration();
List<Scope> scopes = configuration.getInstrumentation().getScopes();
List<ScopeConfiguration> scopes = configuration.getInstrumentation().getScopes();

boolean foundScope = scopes.stream().anyMatch(scope -> expectedScope.equals(scope.getFqn()));
assertTrue(foundScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 489bbbe

Please sign in to comment.