Skip to content

Commit

Permalink
feature: adapt to config 3.0.2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Oct 16, 2024
1 parent ee1c77a commit fe1de3b
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 83 deletions.
6 changes: 3 additions & 3 deletions inspectit-gepard-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ plugins {
id "com.palantir.docker" version "0.36.0"
}

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

sourceCompatibility = "17"
targetCompatibility = "17"
Expand Down Expand Up @@ -70,7 +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("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
@@ -1,6 +1,7 @@
/* (C) 2024 */
package rocks.inspectit.gepard.agent.configuration.persistence.file;

import java.io.FileNotFoundException;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,9 +28,11 @@ public InspectitConfiguration readConfiguration() {
try {
String fileContent = configFileAccessor.readFile();
return ConfigurationMapper.toObject(fileContent);
} catch (FileNotFoundException e) {
log.warn("No local configuration file found");
} catch (IOException e) {
log.warn("No local configuration file found.");
return null;
log.error("Error while reading local configuration file", e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import rocks.inspectit.gepard.agent.instrumentation.state.configuration.matcher.MatcherChainBuilder;
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;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

/**
* This class is used to resolve the {@link ScopeConfiguration} based on the {@link
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.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

/**
* @param fqn the fully qualified name of a class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.mockito.Mockito.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -20,7 +20,7 @@
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;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

@ExtendWith(MockitoExtension.class)
public class ConfigurationPersistenceTest {
Expand Down Expand Up @@ -85,7 +85,7 @@ private static InspectitConfiguration createConfiguration() {
ScopeConfiguration scope =
new ScopeConfiguration(true, "com.example.Application", Collections.emptyList());
InstrumentationConfiguration instrumentationConfiguration =
new InstrumentationConfiguration(List.of(scope));
new InstrumentationConfiguration(Map.of("s_scope", scope), Map.of());
return new InspectitConfiguration(instrumentationConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;
import rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil;
import rocks.inspectit.gepard.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

@ExtendWith(MockitoExtension.class)
public class ConfigurationFileReaderTest {
Expand All @@ -29,14 +30,15 @@ void setUp() {

@Test
void fileContentIsMappedToConfiguration() throws IOException {
String expectedString = expectedString();
String expectedString = InspectitConfigurationTestUtil.expectedString();
String expectedScope = "com.example.Application";
when(fileAccessor.readFile()).thenReturn(expectedString);

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

boolean foundScope = scopes.stream().anyMatch(scope -> expectedScope.equals(scope.getFqn()));
boolean foundScope =
scopes.values().stream().anyMatch(scope -> expectedScope.equals(scope.getFqn()));
assertTrue(foundScope);
}

Expand All @@ -48,8 +50,4 @@ void emptyFileIsMappedToNull() throws IOException {

assertNull(configuration);
}

private static String expectedString() {
return "{\"instrumentation\":{\"scopes\":[{\"fqn\":\"com.example.Application\",\"enabled\":true}]}}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import rocks.inspectit.gepard.agent.internal.file.FileAccessor;
import rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil;
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.config.model.instrumentation.scopes.ScopeConfiguration;

@ExtendWith(MockitoExtension.class)
public class ConfigurationFileWriterTest {
Expand All @@ -34,7 +35,7 @@ void setUp() {
@Test
void configurationIsWrittenToFile() throws IOException {
InspectitConfiguration configuration = createConfiguration();
String expectedString = expectedString();
String expectedString = InspectitConfigurationTestUtil.expectedString();

writer.writeConfiguration(configuration);

Expand All @@ -52,11 +53,7 @@ private static InspectitConfiguration createConfiguration() {
ScopeConfiguration scope =
new ScopeConfiguration(true, "com.example.Application", Collections.emptyList());
InstrumentationConfiguration instrumentationConfiguration =
new InstrumentationConfiguration(List.of(scope));
new InstrumentationConfiguration(Map.of("s_scope", scope), Map.of());
return new InspectitConfiguration(instrumentationConfiguration);
}

private static String expectedString() {
return "{\"instrumentation\":{\"scopes\":[{\"enabled\":true,\"fqn\":\"com.example.Application\",\"methods\":[]}]}}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationUtil.createConfiguration;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationUtil.createScope;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil.createConfiguration;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil.createScope;

import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -15,7 +15,7 @@
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;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

@ExtendWith(MockitoExtension.class)
class ConfigurationResolverTest {
Expand Down Expand Up @@ -47,7 +47,7 @@ void typeShouldNotBeInstrumented() {
@Test
void typeShouldBeInstrumented() {
ScopeConfiguration scope = createScope(true, getClass().getName());
InspectitConfiguration configuration = createConfiguration(List.of(scope));
InspectitConfiguration configuration = createConfiguration(Map.of("s_scope", scope));
when(holder.getConfiguration()).thenReturn(configuration);

ClassInstrumentationConfiguration config =
Expand All @@ -60,7 +60,7 @@ void typeShouldBeInstrumented() {
@Test
void typeShouldBeDeinstrumented() {
ScopeConfiguration scope = createScope(false, getClass().getName());
InspectitConfiguration configuration = createConfiguration(List.of(scope));
InspectitConfiguration configuration = createConfiguration(Map.of("s_scope", scope));
when(holder.getConfiguration()).thenReturn(configuration);

ClassInstrumentationConfiguration config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
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;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

class InspectitConfigurationHolderTest {

Expand Down Expand Up @@ -38,7 +38,7 @@ private InspectitConfiguration createConfiguration() {
ScopeConfiguration scope =
new ScopeConfiguration(true, "com.example.Application", Collections.emptyList());
InstrumentationConfiguration instrumentationConfiguration =
new InstrumentationConfiguration(List.of(scope));
new InstrumentationConfiguration(Map.of("s_scope", scope), Map.of());
return new InspectitConfiguration(instrumentationConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
import static rocks.inspectit.gepard.agent.testutils.CustomAssertions.assertMethodDescriptionMatcherMatches;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationUtil.createConfiguration;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationUtil.createScope;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil.createConfiguration;
import static rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil.createScope;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -21,7 +22,7 @@
import rocks.inspectit.gepard.agent.instrumentation.state.configuration.InspectitConfigurationHolder;
import rocks.inspectit.gepard.agent.internal.instrumentation.model.InstrumentationScope;
import rocks.inspectit.gepard.config.model.InspectitConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.ScopeConfiguration;
import rocks.inspectit.gepard.config.model.instrumentation.scopes.ScopeConfiguration;

@ExtendWith(MockitoExtension.class)
class ScopeResolverTest {
Expand All @@ -37,7 +38,14 @@ void returnsOnlyActiveScopes() {
ScopeConfiguration matchingScope = createScope(true, CLASS_NAME, List.of("method"));
ScopeConfiguration nonMatchingScope1 = createScope(false, CLASS_NAME);
ScopeConfiguration nonMatchingScope2 = createScope(true, "dummyName");
List<ScopeConfiguration> scopes = List.of(matchingScope, nonMatchingScope1, nonMatchingScope2);
Map<String, ScopeConfiguration> scopes =
Map.of(
"s_scope1",
matchingScope,
"s_scope2",
nonMatchingScope1,
"s_scope3",
nonMatchingScope2);
InspectitConfiguration configuration = createConfiguration(scopes);
when(holder.getConfiguration()).thenReturn(configuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected void awaitConfigurationUpdate() {
/**
* Waits until a certain update message was logged again. This happens via checking the container
* logs. First the method counts the current amount of update messages. If the amount of update
* messages has increased, it is assumed that a new configuration has been pooled.
* messages has increased, we assume an event has occurred.
*
* @param updateMessage the message, which will be waited for
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import rocks.inspectit.gepard.agent.internal.configuration.exception.CouldNotDeserializeConfigurationException;
import rocks.inspectit.gepard.agent.testutils.InspectitConfigurationTestUtil;
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.config.model.instrumentation.scopes.ScopeConfiguration;

class ConfigurationMapperTest {

private static final String expectedString = expectedString();
private static final String expectedString = InspectitConfigurationTestUtil.expectedString();

private static final InspectitConfiguration expectedConfig = expectedConfig();

Expand Down Expand Up @@ -58,15 +59,11 @@ void nullConfigThrowsException() {
assertThrows(IllegalArgumentException.class, () -> ConfigurationMapper.toString(null));
}

private static String expectedString() {
return "{\"instrumentation\":{\"scopes\":[{\"enabled\":true,\"fqn\":\"com.example.Application\",\"methods\":[]}]}}";
}

private static InspectitConfiguration expectedConfig() {
ScopeConfiguration scope =
new ScopeConfiguration(true, "com.example.Application", Collections.emptyList());
InstrumentationConfiguration instrumentationConfiguration =
new InstrumentationConfiguration(List.of(scope));
new InstrumentationConfiguration(Map.of("s_scope", scope), Map.of());
return new InspectitConfiguration(instrumentationConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
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.config.model.instrumentation.scopes.ScopeConfiguration;

public class InspectitConfigurationUtil {
public class InspectitConfigurationTestUtil {

/**
* @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<ScopeConfiguration> scopes) {
public static InspectitConfiguration createConfiguration(Map<String, ScopeConfiguration> scopes) {
InstrumentationConfiguration instrumentationConfiguration =
new InstrumentationConfiguration(scopes);
new InstrumentationConfiguration(scopes, Map.of());
return new InspectitConfiguration(instrumentationConfiguration);
}

Expand All @@ -34,4 +35,11 @@ public static ScopeConfiguration createScope(
public static ScopeConfiguration createScope(boolean enabled, String name) {
return createScope(enabled, name, Collections.emptyList());
}

/**
* @return the inspectIT configuration as string.
*/
public static String expectedString() {
return "{\"instrumentation\":{\"scopes\":{\"s_scope\":{\"enabled\":true,\"fqn\":\"com.example.Application\",\"methods\":[]}},\"rules\":{}}}";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
{
"instrumentation": {
"scopes": []
}
}
}
Loading

0 comments on commit fe1de3b

Please sign in to comment.