From 595d95ad3e405b391a593834f5b54fd4f3dfa089 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 16 Nov 2024 14:53:27 +0000 Subject: [PATCH 1/4] feat : switch from sql to mongodb for event publication storage --- docker/docker-compose.yml | 21 +++++++++++++------ pom.xml | 2 +- src/main/resources/application-local.yml | 2 ++ src/main/resources/application.properties | 2 ++ .../migration/11-event-publication.sql | 12 ----------- 5 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 src/main/resources/db/changelog/migration/11-event-publication.sql diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 63cffd54..c5d95155 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -63,7 +63,7 @@ services: - folioman-network environment: - OTEL_METRIC_EXPORT_INTERVAL=500 - - ENABLE_LOGS_ALL=true + - ENABLE_LOGS_ALL=false ports: - "3000:3000" - "4317:4317" @@ -74,22 +74,31 @@ services: hostname: mongodb container_name: mongodb image: mongo:8.0.3 - restart: unless-stopped volumes: - mongodb:/data/db ports: - "27017:27017" - networks: - - folioman-network healthcheck: test: | mongosh --eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }" interval: 10s start_period: 30s - timeout: 5s - retries: 3 command: [ "/usr/bin/mongod", "--replSet", "rs0", "--bind_ip_all" ] + mongo-express: + image: mongo-express + container_name: mongo-express + ports: + - "8081:8081" + environment: + # - ME_CONFIG_MONGODB_ADMINUSERNAME=admin + # - ME_CONFIG_MONGODB_ADMINPASSWORD=passcode + - ME_CONFIG_MONGODB_SERVER=mongodb + - ME_CONFIG_BASICAUTH_USERNAME=admin + - ME_CONFIG_BASICAUTH_PASSWORD=pass + - ME_CONFIG_MONGODB_ENABLE_ADMIN=true + restart: unless-stopped + networks: folioman-network: driver: bridge diff --git a/pom.xml b/pom.xml index 08e127d7..1d37c56f 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,7 @@ org.springframework.modulith - spring-modulith-starter-jpa + spring-modulith-starter-mongodb org.mapstruct diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 23903936..6e634772 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -4,3 +4,5 @@ spring: url: jdbc:postgresql://localhost:5432/appdb username: appuser password: secret + hikari: + maximum-pool-size: 100 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a776943f..07b0d487 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,7 @@ spring.application.name=hilla-folioman server.port=${PORT:8080} logging.level.org.atmosphere = warn +spring.main.allow-bean-definition-overriding=true spring.mustache.check-template-location=false spring.mvc.problemdetails.enabled=true @@ -16,6 +17,7 @@ spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resources/**,resource spring.devtools.add-properties=false spring.modulith.events.republish-outstanding-events-on-restart=true +spring.modulith.events.completion-mode=archive spring.testcontainers.beans.startup=parallel spring.data.redis.repositories.enabled=false diff --git a/src/main/resources/db/changelog/migration/11-event-publication.sql b/src/main/resources/db/changelog/migration/11-event-publication.sql deleted file mode 100644 index d753c576..00000000 --- a/src/main/resources/db/changelog/migration/11-event-publication.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE IF NOT EXISTS event_publication -( - id UUID NOT NULL, - listener_id TEXT NOT NULL, - event_type TEXT NOT NULL, - serialized_event TEXT NOT NULL, - publication_date TIMESTAMP WITH TIME ZONE NOT NULL, - completion_date TIMESTAMP WITH TIME ZONE, - PRIMARY KEY (id) -); -CREATE INDEX IF NOT EXISTS event_publication_serialized_event_hash_idx ON event_publication USING hash(serialized_event); -CREATE INDEX IF NOT EXISTS event_publication_by_completion_date_idx ON event_publication (completion_date); From 29bbb44c3aa7f4e3f3683d0e4840fba46a9a2277 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 16 Nov 2024 14:57:58 +0000 Subject: [PATCH 2/4] enable lgtm --- pom.xml | 5 +++++ .../com/app/folioman/common/NoSQLContainersConfig.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/pom.xml b/pom.xml index 1d37c56f..d82b0f65 100644 --- a/pom.xml +++ b/pom.xml @@ -206,6 +206,11 @@ mongodb test + + org.testcontainers + grafana + test + com.redis.testcontainers testcontainers-redis diff --git a/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java b/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java index c9d54334..fb9250c2 100644 --- a/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java +++ b/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java @@ -1,10 +1,12 @@ package com.app.folioman.common; import com.redis.testcontainers.RedisStackContainer; +import java.time.Duration; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.grafana.LgtmStackContainer; import org.testcontainers.utility.DockerImageName; @TestConfiguration(proxyBeanMethods = false) @@ -22,4 +24,11 @@ RedisStackContainer redisStackContainer() { MongoDBContainer mongoDBContainer() { return new MongoDBContainer(DockerImageName.parse("mongo").withTag("8.0.3")); } + + @Bean + @ServiceConnection + LgtmStackContainer lgtmContainer() { + return new LgtmStackContainer(DockerImageName.parse("grafana/otel-lgtm:0.7.8")) + .withStartupTimeout(Duration.ofMinutes(2)); + } } From d4b57654beb70b443ae9d0e8485d222c9de1f83b Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 16 Nov 2024 15:08:01 +0000 Subject: [PATCH 3/4] fix : docker compose --- docker/docker-compose.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c5d95155..ba57abe5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -78,11 +78,16 @@ services: - mongodb:/data/db ports: - "27017:27017" + restart: unless-stopped + networks: + - folioman-network healthcheck: test: | mongosh --eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }" interval: 10s start_period: 30s + timeout: 5s + retries: 3 command: [ "/usr/bin/mongod", "--replSet", "rs0", "--bind_ip_all" ] mongo-express: @@ -90,6 +95,8 @@ services: container_name: mongo-express ports: - "8081:8081" + networks: + - folioman-network environment: # - ME_CONFIG_MONGODB_ADMINUSERNAME=admin # - ME_CONFIG_MONGODB_ADMINPASSWORD=passcode @@ -98,6 +105,9 @@ services: - ME_CONFIG_BASICAUTH_PASSWORD=pass - ME_CONFIG_MONGODB_ENABLE_ADMIN=true restart: unless-stopped + depends_on: + mongodb: + condition: service_healthy networks: folioman-network: From 75e4487afa1a8a3b432fc91e01a6b3ed31f5325a Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 16 Nov 2024 15:15:24 +0000 Subject: [PATCH 4/4] polish --- src/main/resources/application-local.yml | 2 +- src/main/resources/application.properties | 1 + .../app/folioman/common/NoSQLContainersConfig.java | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 6e634772..7804689a 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -5,4 +5,4 @@ spring: username: appuser password: secret hikari: - maximum-pool-size: 100 + maximum-pool-size: 25 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 07b0d487..6c169192 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -63,6 +63,7 @@ org.jobrunr.database.type=mongodb ################# MongoDB ############################# spring.data.mongodb.database=${MONGODB_DATABASE:jobrunr} spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/${spring.data.mongodb.database}} +spring.data.mongodb.repositories.type=none ################# Datasource micrometer ############### jdbc.datasource-proxy.query.enable-logging=true diff --git a/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java b/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java index fb9250c2..4db1977a 100644 --- a/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java +++ b/src/test/java/com/app/folioman/common/NoSQLContainersConfig.java @@ -9,6 +9,18 @@ import org.testcontainers.grafana.LgtmStackContainer; import org.testcontainers.utility.DockerImageName; +/** + * Test configuration for NoSQL and observability containers. + *

+ * Manages the following test containers: + *

    + *
  • Redis Stack - For caching and data structure operations
  • + *
  • MongoDB - Primary data store for event publications
  • + *
  • LGTM Stack - Observability stack (Loki, Grafana, Tempo, Mimir)
  • + *
+ * All containers are configured with service connection support for automatic + * property binding in the test context. + */ @TestConfiguration(proxyBeanMethods = false) public class NoSQLContainersConfig {