-
Notifications
You must be signed in to change notification settings - Fork 12
Intermediate commit: #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CoderRamya
wants to merge
7
commits into
kenya-jug:main
Choose a base branch
from
CoderRamya:feature/LogIngestionEndPoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4c0e60
Intermediate commit:
CoderRamya 56eabe3
Intermediate commit:
CoderRamya 7989246
Intermediate commit:
CoderRamya c515654
Intermediate commit:
CoderRamya c2b97fd
Intermediate commit:
CoderRamya e7f554d
Intermediate commit:
CoderRamya b2cf426
Removed the permitAll for the specific endpoint
CoderRamya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/kenyajug/regression/controllers/LogsIngestionController.java
This file contains hidden or 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,38 @@ | ||
| package com.kenyajug.regression.controllers; | ||
|
|
||
| import com.kenyajug.regression.entities.AppLog; | ||
| import com.kenyajug.regression.services.IngestionService; | ||
| import com.kenyajug.regression.services.RetrievalService; | ||
| import jakarta.validation.Valid; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
|
|
||
| @RestController | ||
| public class LogsIngestionController { | ||
| private final RetrievalService retrievalService; | ||
| private final IngestionService ingestionService; | ||
|
|
||
| public LogsIngestionController(RetrievalService retrievalService, IngestionService ingestionService) { | ||
| this.retrievalService = retrievalService; | ||
| this.ingestionService = ingestionService; | ||
| } | ||
|
|
||
|
|
||
| @PostMapping("/ingest") | ||
| @PreAuthorize("hasAnyRole('ROLE_ADMIN','datasource')") | ||
| public ResponseEntity<?> ingestLogs(@Valid @RequestBody AppLog appLog) { | ||
| var optionalAppLog = retrievalService.findAppLogById(appLog.uuid()); | ||
| if (optionalAppLog.isPresent()) { | ||
| return ResponseEntity.status(HttpStatus.CONFLICT) | ||
| .body("Log with id " + appLog.uuid() + " already exists"); | ||
| } else { | ||
| ingestionService.saveAppLog(appLog); | ||
| return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
127 changes: 127 additions & 0 deletions
127
src/test/java/com/kenyajug/regression/web_mvc_tests/LogsIngestionControllerTest.java
This file contains hidden or 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,127 @@ | ||
| package com.kenyajug.regression.web_mvc_tests; | ||
|
|
||
|
|
||
| import com.kenyajug.regression.controllers.LogsIngestionController; | ||
| import com.kenyajug.regression.entities.AppLog; | ||
| import com.kenyajug.regression.resources.ApplicationResource; | ||
| import com.kenyajug.regression.resources.DatasourceResource; | ||
| import com.kenyajug.regression.resources.LogResource; | ||
| import com.kenyajug.regression.services.IngestionService; | ||
| import com.kenyajug.regression.services.RetrievalService; | ||
| import com.kenyajug.regression.utils.DateTimeUtils; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mock; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Optional; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.*; | ||
| import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
|
||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| class LogsIngestionControllerTest { | ||
|
|
||
| @Autowired | ||
| MockMvc mockMvc; | ||
|
|
||
| @MockitoBean | ||
| RetrievalService retrievalService; | ||
|
|
||
| @MockitoBean | ||
| IngestionService ingestionService; | ||
|
|
||
| @MockitoBean | ||
| private AppLog appLog; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| appLog = new AppLog( | ||
| "test-uuid", | ||
| DateTimeUtils.convertZonedUTCTimeStringToLocalDateTime("2025-08-11 11:09:22 UTC") , | ||
| "ERROR", | ||
| "app-123", | ||
| "", | ||
| "Test message" | ||
| // add other fields as needed | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnConflictIfLogExists() throws Exception { | ||
| var datetime = DateTimeUtils.convertZonedUTCTimeStringToLocalDateTime("2025-08-11 11:09:22 UTC"); | ||
| AppLog applog = new AppLog( | ||
| "test-uuid", | ||
| datetime, | ||
| "ERROR", | ||
| "app-123", | ||
| "", | ||
| "Test message" | ||
| ); | ||
| when(retrievalService.findAppLogById("test-uuid")).thenReturn(Optional.of(applog)); | ||
| mockMvc.perform(post("/ingest") | ||
| .with(httpBasic("admin@regression.com", "admin123")) // Assuming basic auth is used | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "uuid": "test-uuid", | ||
| "timestamp": "%s", | ||
| "severity": "ERROR", | ||
| "applicationId": "app-123", | ||
| "message": "Test message" | ||
| } | ||
| """.formatted(datetime))) | ||
| .andExpect(status().isConflict()) | ||
| .andExpect(content().string("Log with id test-uuid already exists")); | ||
|
|
||
| verify(ingestionService, never()).saveAppLog(any()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldCreateLogIfNotExists() throws Exception { | ||
|
|
||
| mockMvc.perform(post("/ingest") | ||
| .with(httpBasic("admin@regression.com", "admin123")) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "uuid": "test-uuid", | ||
| "timestamp": "2025-05-08T12:00:00", | ||
| "severity": "ERROR", | ||
| "applicationId": "app-123", | ||
| "message": "Test message" | ||
| } | ||
| """)) | ||
| .andExpect(status().isCreated()); | ||
|
|
||
| verify(ingestionService, times(1)).saveAppLog(any()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void shouldReturnUnauthorizedIfNoCredentials() throws Exception { | ||
| mockMvc.perform(post("/ingest") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "uuid": "test-uuid", | ||
| "timestamp": "2025-05-08T12:00:00", | ||
| "severity": "ERROR", | ||
| "applicationId": "app-123", | ||
| "message": "Test message" | ||
| } | ||
| """)) | ||
| .andExpect(status().isUnauthorized()); | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This are awesome 🔥