Skip to content

Commit

Permalink
refactor: Fix findings and PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
binarycoded committed Aug 29, 2024
1 parent b7651fc commit bf183ea
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 77 deletions.
3 changes: 0 additions & 3 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ dependencies {
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// Management

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
/* (C) 2024 */
package rocks.inspectit.gepard.agentmanager.agent.model;

import jakarta.annotation.Nonnull;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import lombok.*;

/** Represents an agent which is connected to the config server. */
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@Getter
public class Agent {
/** The name of the service which is running the agent. */
@Nonnull private String serviceName;
@NotNull private String serviceName;

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

/** The Gepard-Version. */
@Nonnull private String gepardVersion;
@NotNull private String gepardVersion;

/** The OpenTelemetry-Java-Instrumentation-Version. */
@Nonnull private String otelVersion;
@NotNull private String otelVersion;

/** The start time of the JVM which carries the agent. */
@Nonnull private Instant startTime;
@NotNull private Instant startTime;

/** The Java version of the JVM which carries the agent. */
@Nonnull private String javaVersion;
@NotNull private String javaVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {

@Value("${inspectit.gepard.security.cors.path-pattern}")
@Value("${inspectit-config-server.security.cors.path-pattern}")
private String pathPattern;

@Value("${inspectit.gepard.security.cors.allowed-origins}")
@Value("${inspectit-config-server.security.cors.allowed-origins}")
private String allowedOrigins;

@Value("${inspectit.gepard.security.cors.allowed-methods}")
@Value("${inspectit-config-server.security.cors.allowed-methods}")
private String allowedMethods;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -16,5 +17,5 @@
@Getter
public class InstrumentationConfiguration {

@Valid private List<Scope> scopes = List.of();
@Valid private List<@NotNull Scope> scopes = List.of();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Scope {

@NotNull(message = "Fqn is missing.") private String fqn;

private List<String> methods = List.of();
private List<@NotNull String> methods = List.of();

private boolean enabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Service
public class ConfigurationService {

private InspectitConfiguration inspectitConfiguration;
private volatile InspectitConfiguration inspectitConfiguration;

public InspectitConfiguration getConfiguration() {
return inspectitConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* (C) 2024 */
package rocks.inspectit.gepard.agentmanager.connection.model.dto;

import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;
Expand All @@ -9,14 +10,14 @@
/** Represents a connection response. */
@Builder
public record ConnectionDto(
UUID id,
LocalDateTime registrationTime,
String serviceName,
String gepardVersion,
String otelVersion,
Long pid,
Long startTime,
String javaVersion) {
@NotNull(message = "ID missing.") UUID id,
@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 = "Start-Time missing.") Long startTime,
@NotNull(message = "Java Version missing.") String javaVersion) {

public static ConnectionDto fromConnection(Connection connection) {
return ConnectionDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;
import rocks.inspectit.gepard.agentmanager.agent.model.Agent;
import rocks.inspectit.gepard.agentmanager.connection.model.Connection;

/** Represents a connection request from an agent. */
@Builder
public record CreateConnectionRequest(
@NotNull(message = "Service Name missing.") String serviceName,
@NotNull(message = "Gepard Version missing.") String gepardVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* (C) 2024 */
package rocks.inspectit.gepard.agentmanager.connection.service;

import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -18,7 +18,7 @@
@RequiredArgsConstructor
public class ConnectionService {

private final HashMap<UUID, Connection> connectionCache = new HashMap<>();
private final ConcurrentHashMap<UUID, Connection> connectionCache = new ConcurrentHashMap<>();

/**
* Handles a connection request from an agent.
Expand Down
13 changes: 6 additions & 7 deletions backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ springdoc:
show-actuator: true
use-management-port: true

inspectit:
gepard:
security:
cors:
path-pattern: "/**"
allowed-origins: "*"
allowed-methods: "*"
inspectit-config-server:
security:
cors:
path-pattern: "/**"
allowed-origins: "*"
allowed-methods: "*"
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.UUID;
import org.junit.jupiter.api.Test;
Expand All @@ -31,33 +32,29 @@ class ConnectionControllerTest {

@Test
void connect_whenFieldIsMissing_shouldReturnBadRequest() throws Exception {
CreateConnectionRequest createConnectionRequest =
CreateConnectionRequest.builder()
.serviceName("customer-service-e")
.pid(67887L)
.gepardVersion("0.0.1")
.otelVersion("1.26.8")
.build();
String requestBody =
"""
{
"serviceName": "customer-service-e",
"gepardVersion: "0.0.1",
"otelVersion": "1.26.8"
}
""";

mockMvc
.perform(
post("/api/v1/connections")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(createConnectionRequest)))
.content(requestBody))
.andExpect(status().isBadRequest());
}

@Test
void connect_whenEverythingIsValid_shouldReturnOk() throws Exception {
CreateConnectionRequest createConnectionRequest =
CreateConnectionRequest.builder()
.serviceName("customer-service-e")
.pid(67887L)
.gepardVersion("0.0.1")
.otelVersion("1.26.8")
.startTime(213423L)
.javaVersion("11.0.12")
.build();
new CreateConnectionRequest(
"customer-service-e", "0.0.1", "1.26.8", 67887L, Instant.now().toEpochMilli(), "22");

Connection connection = CreateConnectionRequest.toConnection(createConnectionRequest);
when(connectionService.handleConnectRequest(createConnectionRequest)).thenReturn(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ class ConnectionServiceTest {
@Test
void testHandleConnectRequest() {
CreateConnectionRequest createConnectionRequest =
CreateConnectionRequest.builder()
.startTime(Instant.now().toEpochMilli())
.javaVersion("22")
.otelVersion("3")
.gepardVersion("4")
.pid(4435L)
.serviceName("ServiceName")
.build();
new CreateConnectionRequest(
"customer-service-e", "0.0.1", "1.26.8", 67887L, Instant.now().toEpochMilli(), "22");

Connection response = connectionService.handleConnectRequest(createConnectionRequest);

Expand All @@ -47,14 +41,8 @@ void testHandleConnectRequest() {
@Test
void testGetConnections() {
CreateConnectionRequest createConnectionRequest =
CreateConnectionRequest.builder()
.startTime(Instant.now().toEpochMilli())
.javaVersion("22")
.otelVersion("3")
.gepardVersion("4")
.pid(4435L)
.serviceName("ServiceName")
.build();
new CreateConnectionRequest(
"customer-service-e", "0.0.1", "1.26.8", 67887L, Instant.now().toEpochMilli(), "22");
connectionService.handleConnectRequest(createConnectionRequest);
connectionService.handleConnectRequest(createConnectionRequest);

Expand All @@ -72,14 +60,8 @@ void testGetConnectionsEmptyResult() {
@Test
void testGetConnection() {
CreateConnectionRequest createConnectionRequest =
CreateConnectionRequest.builder()
.startTime(Instant.now().toEpochMilli())
.javaVersion("22")
.otelVersion("3")
.gepardVersion("4")
.pid(4435L)
.serviceName("ServiceName")
.build();
new CreateConnectionRequest(
"customer-service-e", "0.0.1", "1.26.8", 67887L, Instant.now().toEpochMilli(), "22");
Connection connection = connectionService.handleConnectRequest(createConnectionRequest);

ConnectionDto connectionDto = connectionService.getConnection(connection.getId());
Expand Down

0 comments on commit bf183ea

Please sign in to comment.