Skip to content

Commit

Permalink
feat: made uptime kuma config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilczaja committed Nov 26, 2024
1 parent 19c48d7 commit a8ecec3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ interface DeploymentEnvironmentConfiguration {
fun realmName(): String
fun clientId(): String
fun clientSecret(): String
fun kumaName(): String
fun kumaName(): Optional<String>
}

interface DataCatalogConfig {
fun hideOfflineDataOffersAfter(): Duration
fun catalogPagePageSize(): Int
fun dataspaceNames(): DataspaceNames
fun kumaName(): String
fun kumaName(): Optional<String>

interface DataspaceNames {
fun connectorIds(): Map<String, String>
Expand All @@ -50,7 +50,7 @@ interface DeploymentEnvironmentConfiguration {

interface LoggingHouseConfig {
fun url(): String
fun kumaName(): String
fun kumaName(): Optional<String>
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,26 @@ import de.sovity.authorityportal.web.utils.TimeUtils
import io.quarkus.logging.Log
import io.quarkus.scheduler.Scheduled
import jakarta.enterprise.context.ApplicationScoped
import org.eclipse.microprofile.config.inject.ConfigProperty
import org.jooq.DSLContext
import org.jooq.impl.DSL
import java.time.OffsetDateTime
import java.util.Optional

@ApplicationScoped
class ComponentStatusService(
val dsl: DSLContext,
val uptimeKumaClient: UptimeKumaClient,
val timeUtils: TimeUtils
val timeUtils: TimeUtils,
@ConfigProperty(name = "authority-portal.kuma.api-key") val uptimeKumaApiKey: Optional<String>
) {

@Scheduled(every = "30s")
fun fetchComponentStatuses() {
if (uptimeKumaApiKey.isEmpty) {
return
}

val componentsStatusByEnvironment = uptimeKumaClient.getStatusByEnvironments()

componentsStatusByEnvironment.forEach { (env, componentStatuses) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import io.quarkus.logging.Log
import jakarta.enterprise.context.ApplicationScoped
import org.eclipse.microprofile.config.inject.ConfigProperty
import java.util.Base64
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

@ApplicationScoped
class UptimeKumaClient(
val deploymentEnvironmentService: DeploymentEnvironmentService,
val uptimeKumaClientResource: UptimeKumaClientResource,
@ConfigProperty(name = "authority-portal.kuma.api-key") val uptimeKumaApiKey: String,
@ConfigProperty(name = "authority-portal.kuma.api-key") val uptimeKumaApiKey: Optional<String>,
) {

fun getStatusByEnvironments(): Map<String, ComponentStatusOverview> {
Expand All @@ -43,12 +44,18 @@ class UptimeKumaClient(
envConfig: DeploymentEnvironment
): ComponentStatusOverview =
ComponentStatusOverview().also {
it.daps = getComponentStatus(envConfig.daps().kumaName(), response)
it.catalogCrawler = getComponentStatus(envConfig.dataCatalog().kumaName(), response)
it.daps = getComponentStatus(
envConfig.daps().kumaName().get(),
response
).takeUnless { envConfig.daps().kumaName().getOrNull().isNullOrBlank() }
it.catalogCrawler = getComponentStatus(
envConfig.dataCatalog().kumaName().get(),
response
).takeUnless { envConfig.dataCatalog().kumaName().getOrNull().isNullOrBlank() }
it.loggingHouse = getComponentStatus(
envConfig.loggingHouse().get().kumaName(),
envConfig.loggingHouse().get().kumaName().get(),
response
).takeUnless { envConfig.loggingHouse().getOrNull()?.kumaName().isNullOrBlank() }
).takeUnless { envConfig.loggingHouse().getOrNull()?.kumaName()?.getOrNull().isNullOrBlank() }
}

private fun getComponentStatus(componentName: String, response: String): ComponentStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ import jakarta.enterprise.context.ApplicationScoped
import jakarta.enterprise.inject.Produces
import org.eclipse.microprofile.config.inject.ConfigProperty
import java.net.URI
import java.util.Optional

@ApplicationScoped
class UptimeKumaClientResourceFactory {

class UptimeKumaClientResourceFactory(
@ConfigProperty(name = "authority-portal.kuma.metrics-url")
lateinit var uptimeKumaUrl: String
val uptimeKumaUrl: Optional<String>
) {

@Produces
@ApplicationScoped
fun uptimeKumaRestClient(): UptimeKumaClientResource {
fun uptimeKumaRestClient(): UptimeKumaClientResource? {
if (uptimeKumaUrl.isEmpty) {
return null
}

return QuarkusRestClientBuilder.newBuilder()
.baseUri(uptimeKumaUrl.let(URI::create))
.baseUri(URI.create(uptimeKumaUrl.get()))
.build(UptimeKumaClientResource::class.java)!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,43 +105,33 @@ quarkus.oidc-client.sovity.client-enabled=false
%dev.authority-portal.invitation.expiration=43200
%dev.authority-portal.caas.sovity.url=https://url
%dev.authority-portal.caas.sovity.limit-per-organization=1
%dev.authority-portal.kuma.metrics-url=https://url
%dev.authority-portal.kuma.api-key=secret

%test.authority-portal.base-url=https://localhost:4200
%test.authority-portal.config.api-key=secret
%test.authority-portal.invitation.expiration=60
%test.authority-portal.caas.sovity.url=https://url
%test.authority-portal.caas.sovity.limit-per-organization=1
%test.authority-portal.kuma.metrics-url=https://url
%test.authority-portal.kuma.api-key=secret

# Deployment environment configurations
%dev.authority-portal.deployment.environments.test.title=Test
%dev.authority-portal.deployment.environments.test.position=0
%dev.authority-portal.deployment.environments.test.data-catalog.hide-offline-data-offers-after=15m
%dev.authority-portal.deployment.environments.test.data-catalog.catalog-page-page-size=10
%dev.authority-portal.deployment.environments.test.data-catalog.dataspace-names.default=MDS
%dev.authority-portal.deployment.environments.test.data-catalog.kuma-name=broker
%dev.authority-portal.deployment.environments.test.daps.url=https://url
%dev.authority-portal.deployment.environments.test.daps.realm-name=realm
%dev.authority-portal.deployment.environments.test.daps.client-id=client
%dev.authority-portal.deployment.environments.test.daps.client-secret=secret
%dev.authority-portal.deployment.environments.test.daps.kuma-name="DEV mds daps"
%dev.authority-portal.deployment.environments.test.logging-house.url=https://url
%dev.authority-portal.deployment.environments.test.logging-house.kuma-name="DEV mds logging-house"

%dev.authority-portal.deployment.environments.dev.title=Dev
%dev.authority-portal.deployment.environments.dev.position=1
%dev.authority-portal.deployment.environments.dev.data-catalog.hide-offline-data-offers-after=15m
%dev.authority-portal.deployment.environments.dev.data-catalog.catalog-page-page-size=10
%dev.authority-portal.deployment.environments.dev.data-catalog.dataspace-names.default=MDS
%dev.authority-portal.deployment.environments.dev.data-catalog.kuma-name=broker
%dev.authority-portal.deployment.environments.dev.daps.url=https://url
%dev.authority-portal.deployment.environments.dev.daps.realm-name=realm
%dev.authority-portal.deployment.environments.dev.daps.client-id=client
%dev.authority-portal.deployment.environments.dev.daps.client-secret=secret
%dev.authority-portal.deployment.environments.dev.daps.kuma-name="DEV mds daps"
%dev.authority-portal.deployment.environments.dev.data-catalog.dataspace-names.connector-ids.\"MDSL1234XX.C1234XX\"="Mobilithek"

# Test properties
Expand All @@ -150,27 +140,19 @@ quarkus.oidc-client.sovity.client-enabled=false
%test.authority-portal.deployment.environments.test.data-catalog.hide-offline-data-offers-after=15m
%test.authority-portal.deployment.environments.test.data-catalog.catalog-page-page-size=10
%test.authority-portal.deployment.environments.test.data-catalog.dataspace-names.default=MDS
%test.authority-portal.deployment.environments.test.data-catalog.kuma-name=broker
%test.authority-portal.deployment.environments.test.daps.url=https://url
%test.authority-portal.deployment.environments.test.daps.realm-name=realm
%test.authority-portal.deployment.environments.test.daps.client-id=client
%test.authority-portal.deployment.environments.test.daps.client-secret=secret
%test.authority-portal.deployment.environments.test.daps.kuma-name="DEV mds daps"
%test.authority-portal.deployment.environments.test.logging-house.url=https://url
%test.authority-portal.deployment.environments.test.logging-house.kuma-name="DEV mds logging-house"

%test.authority-portal.deployment.environments.other-environment.title=Test Environment
%test.authority-portal.deployment.environments.other-environment.position=0
%test.authority-portal.deployment.environments.other-environment.data-catalog.hide-offline-data-offers-after=15m
%test.authority-portal.deployment.environments.other-environment.data-catalog.catalog-page-page-size=10
%test.authority-portal.deployment.environments.other-environment.data-catalog.dataspace-names.default=MDS
%test.authority-portal.deployment.environments.other-environment.data-catalog.kuma-name=broker
%test.authority-portal.deployment.environments.other-environment.daps.url=https://url
%test.authority-portal.deployment.environments.other-environment.daps.realm-name=realm
%test.authority-portal.deployment.environments.other-environment.daps.client-id=client
%test.authority-portal.deployment.environments.other-environment.daps.client-secret=secret
%test.authority-portal.deployment.environments.other-environment.daps.kuma-name="DEV mds daps"
%test.authority-portal.deployment.environments.other-environment.logging-house.url=https://url
%test.authority-portal.deployment.environments.other-environment.logging-house.kuma-name="DEV mds logging-house"

%dev.authority-portal.seed.scenario=dev

0 comments on commit a8ecec3

Please sign in to comment.