-
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.
feat: add alias creation and refactor setup process
Resolves #15 by introducing an alias in the OpenSearch setup to filter out robot-generated events, allowing Grafana charts to focus on human-generated events. Changes made: - Added alias creation as a dedicated setup task, enabling filtering by default in Grafana of robot generated events. - Refactored the setup process into single-responsibility tasks: policy creation, index creation, and alias creation. Tasks are injected in the execution order using the `@Order` annotation. - Created an `ApplicationRunner` to orchestrate the startup process, handling both OpenSearch setup and event dispatcher client initialization. - Added `MockWebServer` as a test dependency to facilitate testing of OpenSearch setup. - Renamed `SseClient` to `EventDispatcherClient` to align with service naming conventions. - Added jacoco coverage report for pull requests.
- Loading branch information
Showing
20 changed files
with
892 additions
and
178 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
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
src/main/kotlin/ch/srgssr/pillarbox/monitoring/DataTransferApplicationRunner.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,71 @@ | ||
package ch.srgssr.pillarbox.monitoring | ||
|
||
import ch.srgssr.pillarbox.monitoring.event.EventDispatcherClient | ||
import ch.srgssr.pillarbox.monitoring.event.setup.OpenSearchSetupService | ||
import ch.srgssr.pillarbox.monitoring.exception.RetryExhaustedException | ||
import ch.srgssr.pillarbox.monitoring.log.logger | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import org.springframework.boot.ApplicationArguments | ||
import org.springframework.boot.ApplicationRunner | ||
import org.springframework.context.annotation.Profile | ||
import org.springframework.stereotype.Component | ||
|
||
/** | ||
* DataTransferApplicationRunner is responsible for initializing the OpenSearch setup and | ||
* starting the Event dispatcher client upon application start-up. | ||
* | ||
* If either the OpenSearch setup or the SSE connection fails irrecoverably, the application | ||
* is terminated via [TerminationService]. | ||
* | ||
* @property openSearchSetupService Service responsible for initializing and validating the OpenSearch setup. | ||
* @property eventDispatcherClient The client responsible for establishing a connection to the event dispatcher. | ||
* @property terminationService Responsible for gracefully terminating the application if critical failures occur | ||
* during either OpenSearch setup or SSE connection. | ||
*/ | ||
@Component | ||
@Profile("!test") | ||
class DataTransferApplicationRunner( | ||
private val openSearchSetupService: OpenSearchSetupService, | ||
private val eventDispatcherClient: EventDispatcherClient, | ||
private val terminationService: TerminationService, | ||
) : ApplicationRunner { | ||
private companion object { | ||
private val logger = logger() | ||
} | ||
|
||
/** | ||
* Executes the OpenSearch setup task when the application starts. | ||
* | ||
* Upon successful setup, it initiates the [EventDispatcherClient]. If the setup fails, | ||
* an error is logged and the application is terminated. | ||
* | ||
* @param args Application arguments. | ||
*/ | ||
override fun run(args: ApplicationArguments?) { | ||
openSearchSetupService.start().subscribe( | ||
{ this.startSseClient() }, | ||
{ | ||
logger.error("Failed to connect to OpenSearch:", it) | ||
CoroutineScope(Dispatchers.IO).launch { | ||
terminationService.terminateApplication() | ||
} | ||
}, | ||
) | ||
} | ||
|
||
private fun startSseClient() { | ||
eventDispatcherClient.start().subscribe( | ||
{ }, | ||
{ | ||
if (it is RetryExhaustedException) { | ||
logger.error("Failed to connect to SSE after retries, terminating application.", it) | ||
CoroutineScope(Dispatchers.IO).launch { | ||
terminationService.terminateApplication() | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
} |
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
147 changes: 0 additions & 147 deletions
147
src/main/kotlin/ch/srgssr/pillarbox/monitoring/event/SetupService.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.