Skip to content

Commit

Permalink
extend agent model
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Nov 5, 2024
1 parent 24b4720 commit ddef706
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public class Agent {
/** The name of the service which is running the agent. */
@NotNull private String serviceName;

/** The process id of the JVM which carries the agent. */
@NotNull private Long pid;
/** The id of the JVM process carries the agent. */
@NotNull private String vmId;

/** The hashed id of the agent. */
@NotNull private String agentId;

/** The Gepard-Version. */
@NotNull private String gepardVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public record ConnectionDto(
@NotNull(message = "Registration Time missing.") LocalDateTime registrationTime,
@NotNull(message = "Service Name missing.") String serviceName,
@NotNull(message = "Gepard Version missing.") String gepardVersion,
@NotNull(message = "Open-Telemetry Version missing.") String otelVersion,
@NotNull(message = "Process ID is missing.") Long pid,
@NotNull(message = "OpenTelemetry Version missing.") String otelVersion,
@NotNull(message = "VM-ID is missing.") String vmId,
@NotNull(message = "Agent-ID is missing") String agentId,
@NotNull(message = "Start-Time missing.") Long startTime,
@NotNull(message = "Java Version missing.") String javaVersion,
@NotNull(message = "Attributes are missing.") Map<String, String> attributes) {
Expand All @@ -26,7 +27,8 @@ public static ConnectionDto fromConnection(Connection connection) {
connection.getAgent().getServiceName(),
connection.getAgent().getGepardVersion(),
connection.getAgent().getOtelVersion(),
connection.getAgent().getPid(),
connection.getAgent().getVmId(),
connection.getAgent().getAgentId(),
connection.getAgent().getStartTime().toEpochMilli(),
connection.getAgent().getJavaVersion(),
connection.getAgent().getAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
public record CreateConnectionRequest(
@NotNull(message = "Service Name missing.") String serviceName,
@NotNull(message = "Gepard Version missing.") String gepardVersion,
@NotNull(message = "Open-Telemetry Version missing.") String otelVersion,
@NotNull(message = "Process ID is missing.") Long pid,
@NotNull(message = "OpenTelemetry Version missing.") String otelVersion,
@NotNull(message = "VM-ID is missing.") String vmId,
@NotNull(message = "Agent-ID is missing") String agentId,
@NotNull(message = "Start-Time missing.") Long startTime,
@NotNull(message = "Java Version missing.") String javaVersion,
Map<String, String> attributes) {
Expand All @@ -25,7 +26,8 @@ public static Connection toConnection(CreateConnectionRequest createConnectionRe
LocalDateTime.now(),
new Agent(
createConnectionRequest.serviceName,
createConnectionRequest.pid,
createConnectionRequest.vmId,
createConnectionRequest.agentId,
createConnectionRequest.gepardVersion,
createConnectionRequest.otelVersion,
Instant.ofEpochMilli(createConnectionRequest.startTime),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public record QueryConnectionRequest(

public record QueryAgentRequest(
@ValidRegexPattern(message = "Invalid service name pattern") String serviceName,
@ValidRegexPattern(message = "Invalid process ID pattern")
String pid, // pid just has to be a number
@ValidRegexPattern(message = "Invalid VM-ID pattern") String vmId,
@ValidRegexPattern(message = "Invalid Gepard version pattern") String gepardVersion,
@ValidRegexPattern(message = "Invalid OpenTelemetry version pattern") String otelVersion,
@ValidRegexPattern(message = "Invalid start time pattern")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private boolean matchesAgent(Agent agent, QueryConnectionRequest.QueryAgentReque
boolean matches = true;

matches &= regexQueryService.matches(agent.getServiceName(), query.serviceName());
matches &= regexQueryService.matchesLong(agent.getPid(), query.pid());
matches &= regexQueryService.matches(agent.getVmId(), query.vmId());
matches &= regexQueryService.matches(agent.getGepardVersion(), query.gepardVersion());
matches &= regexQueryService.matches(agent.getOtelVersion(), query.otelVersion());
matches &= regexQueryService.matchesInstant(agent.getStartTime(), query.startTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void connect_whenEverythingIsValid_shouldReturnOk() throws Exception {
"customer-service-e",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
Instant.now().toEpochMilli(),
"22",
Map.of());
Expand Down Expand Up @@ -93,7 +94,16 @@ void get_connection_whenEverythingIsValid_shouldReturnOk() throws Exception {
UUID uuid = UUID.randomUUID();
ConnectionDto connectionDto =
new ConnectionDto(
uuid, LocalDateTime.now(), "service name", "5", "7", 42L, 123456789L, "22", Map.of());
uuid,
LocalDateTime.now(),
"service name",
"5",
"7",
"42@localhost",
"12345",
123456789L,
"22",
Map.of());
when(connectionService.getConnection(uuid)).thenReturn(connectionDto);

mockMvc
Expand All @@ -120,7 +130,8 @@ void queryConnections_whenMultipleParametersAreDefined_shouldReturnOk() throws E
"service-name",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
123456789L,
"22",
Map.of()));
Expand Down Expand Up @@ -178,7 +189,8 @@ void queryConnections_whenRegexInParameters_shouldReturnOk() throws Exception {
"service-name",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
123456789L,
"22",
Map.of("key", "value-123")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void testHandleConnectRequest() {
"customer-service-e",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
Instant.now().toEpochMilli(),
"22",
Map.of());
Expand All @@ -58,7 +59,7 @@ void testHandleConnectRequest() {
assertEquals(createConnectionRequest.javaVersion(), response.getAgent().getJavaVersion());
assertEquals(createConnectionRequest.otelVersion(), response.getAgent().getOtelVersion());
assertEquals(createConnectionRequest.gepardVersion(), response.getAgent().getGepardVersion());
assertEquals(createConnectionRequest.pid(), response.getAgent().getPid());
assertEquals(createConnectionRequest.vmId(), response.getAgent().getVmId());
assertEquals(createConnectionRequest.serviceName(), response.getAgent().getServiceName());
assertNotNull(response.getId());
}
Expand All @@ -70,7 +71,8 @@ void testGetConnections() {
"customer-service-e",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
Instant.now().toEpochMilli(),
"22",
Map.of());
Expand All @@ -95,7 +97,8 @@ void testGetConnection() {
"customer-service-e",
"0.0.1",
"1.26.8",
67887L,
"67887@localhost",
"7e4686b7998c88427b14700f1c2aa69304a1c2fdb899067efe8ba9542fc02029",
Instant.now().toEpochMilli(),
"22",
Map.of());
Expand All @@ -108,7 +111,7 @@ void testGetConnection() {
assertEquals(createConnectionRequest.javaVersion(), connectionDto.javaVersion());
assertEquals(createConnectionRequest.otelVersion(), connectionDto.otelVersion());
assertEquals(createConnectionRequest.gepardVersion(), connectionDto.gepardVersion());
assertEquals(createConnectionRequest.pid(), connectionDto.pid());
assertEquals(createConnectionRequest.vmId(), connectionDto.vmId());
assertEquals(createConnectionRequest.serviceName(), connectionDto.serviceName());
}

Expand Down Expand Up @@ -242,7 +245,7 @@ void testQueryShouldFindConnectionWithMultipleCriteria() {
id.toString(),
registrationTime.toString(),
new QueryConnectionRequest.QueryAgentRequest(
"testService", "1234", "1.0", "1.0", null, "17", attributes));
"testService", "1234@localhost", "1.0", "1.0", null, "17", attributes));

// when
List<ConnectionDto> result = connectionService.queryConnections(query);
Expand Down Expand Up @@ -425,7 +428,8 @@ private Connection createTestConnection(
return new Connection(
id,
registrationTime,
new Agent(serviceName, 1234L, "1.0", "1.0", Instant.now(), "17", Map.of()));
new Agent(
serviceName, "1234@localhost", "12345", "1.0", "1.0", Instant.now(), "17", Map.of()));
}

private Connection createTestConnectionWithAttributes(UUID id, Map<String, String> attributes) {
Expand All @@ -437,6 +441,14 @@ private Connection createTestConnectionWithAttributes(
return new Connection(
id,
registrationTime,
new Agent("testService", 1234L, "1.0", "1.0", Instant.now(), "17", attributes));
new Agent(
"testService",
"1234@localhost",
"12345",
"1.0",
"1.0",
Instant.now(),
"17",
attributes));
}
}

0 comments on commit ddef706

Please sign in to comment.