Skip to content

Commit

Permalink
use config 3.0.3-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Nov 7, 2024
1 parent 374eb49 commit b6765f2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 38 deletions.
5 changes: 3 additions & 2 deletions 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'
def configVersion = "3.0.2-dev"
def configVersion = "3.0.3-dev"

sourceCompatibility = "17"
targetCompatibility = "17"
Expand Down Expand Up @@ -76,7 +76,8 @@ dependencies {
implementation("org.slf4j:slf4j-api:2.0.16")
// http client for server notification
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.1")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1")
implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private MethodHookFactory() {}
public static MethodHook createHook(MethodHookConfiguration hookConfig) {
MethodHook.Builder builder = MethodHook.builder().setConfiguration(hookConfig);

if (hookConfig.getTracing().getStartSpan()) builder.setSpanAction(new SpanAction());
if (hookConfig.getTracing().isStartSpan()) builder.setSpanAction(new SpanAction());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,50 @@
import io.opentelemetry.javaagent.tooling.AgentVersion;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import rocks.inspectit.gepard.agent.internal.identity.IdentityManager;
import rocks.inspectit.gepard.agent.internal.properties.PropertiesResolver;
import rocks.inspectit.gepard.commons.model.agent.Agent;

/** Meta-information about the current agent */
public final class AgentInfo {

public static final AgentInfo INFO = new AgentInfo();
public static AgentInfo INFO = new AgentInfo();

private final String serviceName;

private final String gepardVersion;

private final String otelVersion;

private final String javaVersion;

private final long startTime;

private final String vmId;
private final Agent agent;

private final String agentId;

private final Map<String, String> attributes;

private AgentInfo() {
IdentityManager identityManager = IdentityManager.getInstance();
IdentityInfo identityInfo = identityManager.getIdentityInfo();
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();

this.serviceName = getServiceNameFromSdk();
this.gepardVersion = "0.0.1";
this.otelVersion = AgentVersion.VERSION;
this.javaVersion = System.getProperty("java.version");
this.startTime = runtime.getStartTime();
this.vmId = identityInfo.vmId();
this.agent = createAgent(identityInfo);
this.agentId = identityInfo.agentId();
this.attributes = PropertiesResolver.getAttributes();
}

private Agent createAgent(IdentityInfo identityInfo) {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();

String serviceName = getServiceNameFromSdk();
String gepardVersion = "0.0.1";
String otelVersion = AgentVersion.VERSION;
String javaVersion = System.getProperty("java.version");
Instant startTime = Instant.ofEpochMilli(runtime.getStartTime());
String vmId = identityInfo.vmId();
Map<String, String> attributes = PropertiesResolver.getAttributes();

return new Agent(
serviceName, gepardVersion, otelVersion, javaVersion, startTime, vmId, attributes);
}

/**
* @return the agent meta-information
*/
public Agent getAgent() {
return agent;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
Expand All @@ -17,7 +18,9 @@
public class NotificationFactory {

private static final ObjectMapper mapper =
new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
new ObjectMapper()
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.registerModule(new JavaTimeModule());

private NotificationFactory() {}

Expand All @@ -34,7 +37,7 @@ public static SimpleHttpRequest createStartNotification(String baseUrl)
throws URISyntaxException, JsonProcessingException {
String agentId = AgentInfo.INFO.getAgentId();
URI uri = new URI(baseUrl + "/connections/" + agentId);
String agentInfoString = mapper.writeValueAsString(AgentInfo.INFO);
String agentInfoString = mapper.writeValueAsString(AgentInfo.INFO.getAgent());

return SimpleRequestBuilder.post(uri)
.setBody(agentInfoString, ContentType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void shouldResolveConfigWithEnabledTracing() {
when(activeRule.getTracing()).thenReturn(tracing);

MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration);
boolean tracingEnabled = hookConfig.getTracing().getStartSpan();
boolean tracingEnabled = hookConfig.getTracing().isStartSpan();

assertEquals(methodName, hookConfig.getMethodName());
assertTrue(tracingEnabled);
Expand All @@ -62,7 +62,7 @@ void shouldResolveConfigWithoutEnabledTracing() {
when(activeRule.getTracing()).thenReturn(tracing);

MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration);
boolean tracingEnabled = hookConfig.getTracing().getStartSpan();
boolean tracingEnabled = hookConfig.getTracing().isStartSpan();

assertEquals(methodName, hookConfig.getMethodName());
assertFalse(tracingEnabled);
Expand All @@ -73,7 +73,7 @@ void shouldResolveConfigWithoutEnabledTracingWhenNoRulesMatch() {
when(methodDescription.isMethod()).thenReturn(false);

MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration);
boolean tracingEnabled = hookConfig.getTracing().getStartSpan();
boolean tracingEnabled = hookConfig.getTracing().isStartSpan();

assertEquals(methodName, hookConfig.getMethodName());
assertFalse(tracingEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void shouldCreateMethodHookWithoutTracing() {
when(hookConfiguration.getTracing()).thenReturn(RuleTracingConfiguration.NO_TRACING);

MethodHook hook = MethodHookFactory.createHook(hookConfiguration);
boolean tracingEnabled = hook.getConfiguration().getTracing().getStartSpan();
boolean tracingEnabled = hook.getConfiguration().getTracing().isStartSpan();

assertNotNull(hook);
assertEquals(methodName, hook.getConfiguration().getMethodName());
Expand All @@ -39,7 +39,7 @@ void shouldCreateMethodHookWithTracing() {
when(hookConfiguration.getTracing()).thenReturn(tracing);

MethodHook hook = MethodHookFactory.createHook(hookConfiguration);
boolean tracingEnabled = hook.getConfiguration().getTracing().getStartSpan();
boolean tracingEnabled = hook.getConfiguration().getTracing().isStartSpan();

assertNotNull(hook);
assertEquals(methodName, hook.getConfiguration().getMethodName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void shouldCreateRuleWithOneScopeAndTracingEnabled() {
assertTrue(activeRule.isPresent());
assertEquals(1, activeRule.get().getScopes().size());
assertTrue(activeRule.get().getScopes().contains(scope1));
assertTrue(activeRule.get().getTracing().getStartSpan());
assertTrue(activeRule.get().getTracing().isStartSpan());
assertEquals(methodMatcher, activeRule.get().getMethodMatcher());
}

Expand Down Expand Up @@ -113,7 +113,7 @@ void shouldCreateRuleWithTwoScopesAndTracingDisabled() {
assertEquals(2, activeRule.get().getScopes().size());
assertTrue(activeRule.get().getScopes().contains(scope1));
assertTrue(activeRule.get().getScopes().contains(scope2));
assertFalse(activeRule.get().getTracing().getStartSpan());
assertFalse(activeRule.get().getTracing().isStartSpan());
verify(methodMatcher).or(methodMatcher); // method matchers of scopes were combined
}

Expand Down Expand Up @@ -186,12 +186,12 @@ void shouldCreateTwoRulesWithDifferentScopesAndDifferentTracing() {
assertTrue(activeRule1.isPresent());
assertEquals(1, activeRule1.get().getScopes().size());
assertTrue(activeRule1.get().getScopes().contains(scope1));
assertTrue(activeRule1.get().getTracing().getStartSpan());
assertTrue(activeRule1.get().getTracing().isStartSpan());
assertEquals(methodMatcher, activeRule1.get().getMethodMatcher());
assertTrue(activeRule2.isPresent());
assertEquals(1, activeRule2.get().getScopes().size());
assertTrue(activeRule2.get().getScopes().contains(scope2));
assertFalse(activeRule2.get().getTracing().getStartSpan());
assertFalse(activeRule2.get().getTracing().isStartSpan());
assertEquals(methodMatcher, activeRule2.get().getMethodMatcher());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ void validUrlCreatesStartNotification() throws Exception {
String baseUrl = "http://localhost:8080";
String url = "http://localhost:8080/connections/" + agentId;
String contentType = "application/json";
String info = mapper.writeValueAsString(AgentInfo.INFO);
String agent = mapper.writeValueAsString(AgentInfo.INFO.getAgent());

SimpleHttpRequest request = NotificationFactory.createStartNotification(baseUrl);

assertEquals(url, request.getUri().toString());
assertEquals(contentType, request.getHeader("content-type").getValue());
assertEquals(info, request.getBodyText());
assertEquals(agent, request.getBodyText());
}

@Test
Expand Down

0 comments on commit b6765f2

Please sign in to comment.