Skip to content

Commit

Permalink
feature: use configuration as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Oct 15, 2024
1 parent 23d3f39 commit dc948e1
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 145 deletions.
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")
password = project.findProperty("gpr.inspectit.gepard.token")
}
}
}

apply plugin: "java"
Expand Down
1 change: 1 addition & 0 deletions inspectit-gepard-agent/build.gradle
Original file line number Diff line number Diff line change
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:${version}")
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 @@ -37,6 +37,8 @@ public class InspectitAgentExtension implements AgentExtension {
public AgentBuilder extend(AgentBuilder agentBuilder, ConfigProperties config) {
log.info("Starting inspectIT Gepard agent extension ...");



// Append the bootstrap classloader with inspectIT interfaces
BootstrapManager bootstrapManager = BootstrapManager.create();
bootstrapManager.appendToBootstrapClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedSubject;
import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.config.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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.agent.internal.configuration.util.ConfigurationMapper;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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.config.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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rocks.inspectit.gepard.agent.internal.configuration.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent;
import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedObserver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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.config.model.instrumentation.InstrumentationConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.agent.internal.instrumentation.model.InstrumentationScope;

/**
* This class is used to resolve the {@link Scope} based on the {@link Scope} List, contained in the
* 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,9 +15,9 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.InstrumentationConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
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;
Expand Down Expand Up @@ -82,7 +82,7 @@ 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,8 +11,8 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;

@ExtendWith(MockitoExtension.class)
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,9 +14,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.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;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -49,7 +49,7 @@ 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,7 +10,7 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.agent.internal.configuration.observer.ConfigurationReceivedEvent;

@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
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.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.agent.internal.instrumentation.InstrumentedType;
import rocks.inspectit.gepard.agent.internal.instrumentation.model.ClassInstrumentationConfiguration;

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Loading

0 comments on commit dc948e1

Please sign in to comment.