-
Notifications
You must be signed in to change notification settings - Fork 0
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
9e5bac2
commit d5a4d0f
Showing
15 changed files
with
161 additions
and
107 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
8 changes: 0 additions & 8 deletions
8
backend/src/main/kotlin/ch/sbb/backend/domain/logging/ConsoleLogService.kt
This file was deleted.
Oops, something went wrong.
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
28 changes: 23 additions & 5 deletions
28
backend/src/main/kotlin/ch/sbb/backend/domain/logging/SplunkLogService.kt
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
package ch.sbb.backend.domain.logging | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.reactive.function.client.WebClient | ||
import org.springframework.web.reactive.function.client.WebClientResponseException | ||
import org.springframework.web.server.ResponseStatusException | ||
|
||
/** example of a log service implementation without the expected behaviour */ | ||
class SplunkLogService: LogService { | ||
@Service | ||
class SplunkLogService( | ||
@Value("\${splunk.url}") private val url: String, | ||
@Value("\${splunk.token}") private val token: String | ||
) : LogService { | ||
private val log = LoggerFactory.getLogger(SplunkLogService::class.java) | ||
private val webClient: WebClient = WebClient.create(url) | ||
|
||
override fun logs( logEntries: List<LogEntry>) { | ||
logEntries.forEach { log.info("SPLUNK: $it") } | ||
// todo: instead of logging to console, log to splunk | ||
override fun logs(logEntries: List<LogEntry>) { | ||
webClient.post() | ||
.headers { it["Authorization"] = "Splunk $token" } | ||
.bodyValue(logEntries.map { it.toSplunkRequest() }) | ||
.retrieve() | ||
.bodyToMono(Object::class.java) | ||
.doOnError(WebClientResponseException::class.java) { | ||
log.error("Error sending logs to Splunk status=${it.statusCode} body=${it.responseBodyAsString}") | ||
throw ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR) | ||
} | ||
.block() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/kotlin/ch/sbb/backend/domain/logging/SplunkRequest.kt
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 @@ | ||
package ch.sbb.backend.domain.logging | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import java.time.OffsetDateTime | ||
|
||
data class SplunkRequest( | ||
val event: String, | ||
val fields: Map<String, String>, | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
val host: String? = null, | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
val index: String? = null, | ||
val source: String, | ||
val time: OffsetDateTime, | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
val sourcetype: String? = null | ||
) |
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
1 change: 0 additions & 1 deletion
1
backend/src/main/kotlin/ch/sbb/backend/infrastructure/configuration/LogDestination.kt
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package ch.sbb.backend.infrastructure.configuration | ||
|
||
enum class LogDestination { | ||
CONSOLE, | ||
SPLUNK | ||
} |
10 changes: 5 additions & 5 deletions
10
backend/src/main/kotlin/ch/sbb/backend/infrastructure/configuration/Tenant.kt
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package ch.sbb.backend.infrastructure.configuration | ||
|
||
data class Tenant( | ||
var name: String? = null, | ||
var id: String? = null, | ||
var jwkSetUri: String? = null, | ||
var issuerUri: String? = null, | ||
var logDestination: LogDestination? = null | ||
var name: String, | ||
var id: String, | ||
var jwkSetUri: String, | ||
var issuerUri: String, | ||
var logDestination: LogDestination | ||
) |
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
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
Oops, something went wrong.