-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d88be3
commit 533c4c4
Showing
10 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ fabric.properties | |
/ui/build_packageClient/ | ||
|
||
**/.DS_Store | ||
|
||
**/node_modules | ||
**/.nuxt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...rocks/inspectit/gepard/agentmanager/configuration/controller/ConfigurationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.validation.Valid; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.InspectitConfiguration; | ||
import rocks.inspectit.gepard.agentmanager.configuration.service.ConfigurationService; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/agent-configuration") | ||
@RequiredArgsConstructor | ||
public class ConfigurationController { | ||
|
||
private final ConfigurationService configurationService; | ||
|
||
@GetMapping | ||
@Operation(summary = "Get the agent configuration.") | ||
public ResponseEntity<InspectitConfiguration> getAgentConfiguration() { | ||
InspectitConfiguration configuration = configurationService.getConfiguration(); | ||
|
||
// No config available | ||
if (Objects.isNull(configuration)) { | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
return ResponseEntity.ok().body(configurationService.getConfiguration()); | ||
} | ||
|
||
@PutMapping | ||
@Operation(summary = "Update the agent configuration.") | ||
public ResponseEntity<InspectitConfiguration> updateAgentConfiguration( | ||
@Valid @RequestBody InspectitConfiguration configuration) { | ||
configurationService.updateConfiguration(configuration); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../java/rocks/inspectit/gepard/agentmanager/configuration/model/InspectitConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.model; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation.InstrumentationConfiguration; | ||
|
||
/** Model of an inspectit gepard configuration. */ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class InspectitConfiguration { | ||
|
||
@Valid private InstrumentationConfiguration instrumentation = new InstrumentationConfiguration(); | ||
} |
20 changes: 20 additions & 0 deletions
20
...gepard/agentmanager/configuration/model/instrumentation/InstrumentationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation; | ||
|
||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* The Instrumentation Configuration contains all configuration related to instrumentation. e.g | ||
* scopes, rules, actions. | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class InstrumentationConfiguration { | ||
|
||
@Valid private List<Scope> scopes = List.of(); | ||
} |
24 changes: 24 additions & 0 deletions
24
...n/java/rocks/inspectit/gepard/agentmanager/configuration/model/instrumentation/Scope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Represents a scope in the instrumentation configuration. A scope defines a set of methods which | ||
* should be instrumented. | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class Scope { | ||
|
||
@NotNull(message = "Fqn is missing.") private String fqn; | ||
|
||
private List<String> methods = List.of(); | ||
|
||
private boolean enabled = false; | ||
} |
19 changes: 19 additions & 0 deletions
19
.../java/rocks/inspectit/gepard/agentmanager/configuration/service/ConfigurationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.InspectitConfiguration; | ||
|
||
@Service | ||
public class ConfigurationService { | ||
|
||
private InspectitConfiguration inspectitConfiguration; | ||
|
||
public InspectitConfiguration getConfiguration() { | ||
return inspectitConfiguration; | ||
} | ||
|
||
public void updateConfiguration(InspectitConfiguration configuration) { | ||
inspectitConfiguration = configuration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...s/inspectit/gepard/agentmanager/configuration/controller/ConfigurationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agentmanager.configuration.controller; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.InspectitConfiguration; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation.InstrumentationConfiguration; | ||
import rocks.inspectit.gepard.agentmanager.configuration.model.instrumentation.Scope; | ||
import rocks.inspectit.gepard.agentmanager.configuration.service.ConfigurationService; | ||
|
||
@WebMvcTest(controllers = ConfigurationController.class) | ||
class ConfigurationControllerTest { | ||
|
||
@Autowired private MockMvc mockMvc; | ||
|
||
@Autowired private ObjectMapper objectMapper; | ||
|
||
@MockBean private ConfigurationService configurationService; | ||
|
||
@Test | ||
void getConfiguration_whenNoConfigAvailable_shouldReturnNoContent() throws Exception { | ||
|
||
when(configurationService.getConfiguration()).thenReturn(null); | ||
|
||
mockMvc.perform(get("/api/v1/agent-configuration")).andExpect(status().isNoContent()); | ||
} | ||
|
||
@Test | ||
void getConfiguration_whenConfigAvailable_shouldReturnOk() throws Exception { | ||
when(configurationService.getConfiguration()).thenReturn(new InspectitConfiguration()); | ||
|
||
mockMvc | ||
.perform(get("/api/v1/agent-configuration")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(content().json(objectMapper.writeValueAsString(new InspectitConfiguration()))); | ||
} | ||
|
||
@Test | ||
void updateConfiguration_shouldReturnOkAndConfiguration() throws Exception { | ||
|
||
InspectitConfiguration configuration = createConfiguration(); | ||
|
||
when(configurationService.getConfiguration()).thenReturn(configuration); | ||
|
||
mockMvc | ||
.perform( | ||
get("/api/v1/agent-configuration") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(configuration))) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
private InspectitConfiguration createConfiguration() { | ||
Scope scope = new Scope("org.test.package", List.of("testMethod"), true); | ||
InstrumentationConfiguration instrumentationConfiguration = | ||
new InstrumentationConfiguration(List.of(scope)); | ||
return new InspectitConfiguration(instrumentationConfiguration); | ||
} | ||
} |