Skip to content

Commit

Permalink
[PPABV-27] feat: add search feature flag to switch db connection base…
Browse files Browse the repository at this point in the history
…d on env var (#136)

* feat: add search feature flag to switch db connection based on env var

* fix: add missing env variable to helm files

* fix: rename pm db references to history db; add missing test property

* fix: rename env var and usages

* fix: run spotlessApply to pass code review in pipeline

---------

Co-authored-by: Simone infante <[email protected]>
  • Loading branch information
dylantangredi-bvt and infantesimone authored Oct 28, 2024
1 parent e3ce88e commit b030306
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 30 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MONGO_WAITING_QUEUE_MS=2000
MONGO_HEARTBEAT_FREQUENCY_MS=5000

SEARCH_DEAD_LETTER_QUEUE_MAPPING={ ALL: '*', ECOMMERCE: 'pagopa-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-ecommerce-notifications-service-errors-queue' }
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED=false

PERSONAL_DATA_VAULT_API_KEY=personal-data-vault-api-key
PERSONAL_DATA_VAULT_API_BASE_PATH="http://pagopa-pdv-mock:8080"
57 changes: 29 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,35 @@ to get a good default configuration.

If you want to customize the application environment, reference this table:

| Variable name | Description | type | default |
|-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|---------|
| DEFAULT_LOGGING_LEVEL | Default root application logging level | string | INFO |
| APP_LOGGING_LEVEL | Application logging level | string | INFO |
| WEB_LOGGING_LEVEL | Web logging level | string | INFO |
| MONGO_HOST | MongoDB ecommerce hostname instance | hostname (string) | |
| MONGO_PORT | Port where MongoDB is bound to in MongoDB host | number | |
| MONGO_USERNAME | MongoDB username used to connect to the database | string | |
| MONGO_PASSWORD | MongoDB password used to connect to the database | string | |
| MONGO_SSL_ENABLED | Whether SSL is enabled while connecting to MongoDB | string | |
| MONGO_PORT | Port used for connecting to MongoDB instance | string | |
| MONGO_MIN_POOL_SIZE | Min amount of connections to be retained into connection pool. See docs * | string | |
| MONGO_MAX_POOL_SIZE | Max amount of connections to be retained into connection pool.See docs * | string | |
| MONGO_MAX_IDLE_TIMEOUT_MS | Max timeout after which an idle connection is killed in milliseconds. See docs * | string | |
| MONGO_CONNECTION_TIMEOUT_MS | Max time to wait for a connection to be opened. See docs * | string | |
| MONGO_SOCKET_TIMEOUT_MS | Max time to wait for a command send or receive before timing out. See docs * | string | |
| MONGO_SERVER_SELECTION_TIMEOUT_MS | Max time to wait for a server to be selected while performing a communication with Mongo in milliseconds. See docs * | string | |
| MONGO_WAITING_QUEUE_MS | Max time a thread has to wait for a connection to be available in milliseconds. See docs * | string | |
| MONGO_HEARTBEAT_FREQUENCY_MS | Hearth beat frequency in milliseconds. This is an hello command that is sent periodically on each active connection to perform an health check. See docs * | string | |
| MONGO_REPLICA_SET_OPTION | The replica set connection string option valued with the name of the replica set. See docs * | string | |
| PERSONAL_DATA_VAULT_API_KEY | API Key for Personal Data Vault (PDV is used to safely encrypt PIIs, e.g. the user's email address) | string | |
| PERSONAL_DATA_VAULT_API_BASE_PATH | API base path for Personal Data Vault | string | |
| PM_ORACLE_HOST | PM Oracle DB hostname instance | hostname (string) | |
| PM_ORACLE_PORT | PM Oracle DB port | int | |
| PM_ORACLE_DATABASE_NAME | PM Oracle DB database name | string | |
| PM_ORACLE_USERNAME | PM Oracle DB username | string | |
| PM_ORACLE_PASSWORD | PM Oracle DB password | string | |
| SEARCH_DEAD_LETTER_QUEUE_MAPPING | Dead letter search criteria to queue name mapping | map(string,string) | |
| Variable name | Description | type | default |
|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|---------|
| DEFAULT_LOGGING_LEVEL | Default root application logging level | string | INFO |
| APP_LOGGING_LEVEL | Application logging level | string | INFO |
| WEB_LOGGING_LEVEL | Web logging level | string | INFO |
| MONGO_HOST | MongoDB ecommerce hostname instance | hostname (string) | |
| MONGO_PORT | Port where MongoDB is bound to in MongoDB host | number | |
| MONGO_USERNAME | MongoDB username used to connect to the database | string | |
| MONGO_PASSWORD | MongoDB password used to connect to the database | string | |
| MONGO_SSL_ENABLED | Whether SSL is enabled while connecting to MongoDB | string | |
| MONGO_PORT | Port used for connecting to MongoDB instance | string | |
| MONGO_MIN_POOL_SIZE | Min amount of connections to be retained into connection pool. See docs * | string | |
| MONGO_MAX_POOL_SIZE | Max amount of connections to be retained into connection pool.See docs * | string | |
| MONGO_MAX_IDLE_TIMEOUT_MS | Max timeout after which an idle connection is killed in milliseconds. See docs * | string | |
| MONGO_CONNECTION_TIMEOUT_MS | Max time to wait for a connection to be opened. See docs * | string | |
| MONGO_SOCKET_TIMEOUT_MS | Max time to wait for a command send or receive before timing out. See docs * | string | |
| MONGO_SERVER_SELECTION_TIMEOUT_MS | Max time to wait for a server to be selected while performing a communication with Mongo in milliseconds. See docs * | string | |
| MONGO_WAITING_QUEUE_MS | Max time a thread has to wait for a connection to be available in milliseconds. See docs * | string | |
| MONGO_HEARTBEAT_FREQUENCY_MS | Hearth beat frequency in milliseconds. This is an hello command that is sent periodically on each active connection to perform an health check. See docs * | string | |
| MONGO_REPLICA_SET_OPTION | The replica set connection string option valued with the name of the replica set. See docs * | string | |
| PERSONAL_DATA_VAULT_API_KEY | API Key for Personal Data Vault (PDV is used to safely encrypt PIIs, e.g. the user's email address) | string | |
| PERSONAL_DATA_VAULT_API_BASE_PATH | API base path for Personal Data Vault | string | |
| PM_ORACLE_HOST | PM Oracle DB hostname instance | hostname (string) | |
| PM_ORACLE_PORT | PM Oracle DB port | int | |
| PM_ORACLE_DATABASE_NAME | PM Oracle DB database name | string | |
| PM_ORACLE_USERNAME | PM Oracle DB username | string | |
| PM_ORACLE_PASSWORD | PM Oracle DB password | string | |
| SEARCH_DEAD_LETTER_QUEUE_MAPPING | Dead letter search criteria to queue name mapping | map(string,string) | |
| SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED | Whether the search by fiscal code is made through the history (false) or ecommerce (true) database | string | false |

(*): for Mongo connection string options
see [docs](https://www.mongodb.com/docs/drivers/java/sync/v4.3/fundamentals/connection/connection-options/#connection-options)
Expand Down
1 change: 1 addition & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ microservice-chart:
MONGO_HEARTBEAT_FREQUENCY_MS: "5000"
SEARCH_DEAD_LETTER_QUEUE_MAPPING: >
{ALL: '*', ECOMMERCE: 'pagopa-d-weu-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-d-weu-ecommerce-notifications-service-errors-queue'}
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED: "false"

envSecret:
OTEL_EXPORTER_OTLP_HEADERS: elastic-otel-token-header
Expand Down
2 changes: 2 additions & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ microservice-chart:
MONGO_REPLICA_SET_OPTION: "&replicaSet=globaldb"
SEARCH_DEAD_LETTER_QUEUE_MAPPING: >
{ALL: '*', ECOMMERCE: 'pagopa-p-weu-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-p-weu-ecommerce-notifications-service-errors-queue'}
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED: "false"

envSecret:
OTEL_EXPORTER_OTLP_HEADERS: elastic-otel-token-header
Expand Down Expand Up @@ -140,6 +141,7 @@ microservice-chart:
MONGO_REPLICA_SET_OPTION: "&replicaSet=globaldb"
SEARCH_DEAD_LETTER_QUEUE_MAPPING: >
{ALL: '*', ECOMMERCE: 'pagopa-p-weu-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-p-weu-ecommerce-notifications-service-errors-queue'}
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED: "false"

envSecret:
OTEL_EXPORTER_OTLP_HEADERS: elastic-otel-token-header
Expand Down
2 changes: 2 additions & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ microservice-chart:
MONGO_HEARTBEAT_FREQUENCY_MS: "5000"
SEARCH_DEAD_LETTER_QUEUE_MAPPING: >
{ALL: '*', ECOMMERCE: 'pagopa-u-weu-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-u-weu-ecommerce-notifications-service-errors-queue'}
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED: "false"

envSecret:
OTEL_EXPORTER_OTLP_HEADERS: elastic-otel-token-header
Expand Down Expand Up @@ -138,6 +139,7 @@ microservice-chart:
MONGO_HEARTBEAT_FREQUENCY_MS: "5000"
SEARCH_DEAD_LETTER_QUEUE_MAPPING: >
{ALL: '*', ECOMMERCE: 'pagopa-u-weu-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-u-weu-ecommerce-notifications-service-errors-queue'}
SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED: "false"

envSecret:
OTEL_EXPORTER_OTLP_HEADERS: elastic-otel-token-header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono

@RestController("PmV1Controller")
class PmController(@Autowired val pmService: PmService) : PmApi {
class PmController(
@Autowired val pmService: PmService,
@Value("\${search.pm.in.ecommerce.history.enabled:false}")
private val searchPmInEcommerceHistory: Boolean
) : PmApi {
private val logger = LoggerFactory.getLogger(this.javaClass)

override fun pmSearchTransaction(
Expand All @@ -25,7 +30,9 @@ class PmController(@Autowired val pmService: PmService) : PmApi {
pmSearchTransactionRequestDto: Mono<PmSearchTransactionRequestDto>,
exchange: ServerWebExchange
): Mono<ResponseEntity<SearchTransactionResponseDto>> {
logger.info("[HelpDesk controller] pmSearchTransaction")
logger.info(
"[HelpDesk controller] SearchTransaction using ${if (searchPmInEcommerceHistory) "v2 (ecommerce db)" else "v1 (history db)"} search"
)
return pmSearchTransactionRequestDto
.flatMap {
pmService.searchTransaction(
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ deadLetter.queueMapping=\${SEARCH_DEAD_LETTER_QUEUE_MAPPING}
#PDV configuration
confidentialDataManager.personalDataVault.apiKey=\${PERSONAL_DATA_VAULT_API_KEY}
confidentialDataManager.personalDataVault.apiBasePath=\${PERSONAL_DATA_VAULT_API_BASE_PATH}
# feature flags
search.pm.in.ecommerce.history.enabled=\${SEARCH_PM_IN_ECOMMERCE_HISTORY_ENABLED}
2 changes: 2 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ deadLetter.queueMapping={ ALL: '*', ECOMMERCE: 'pagopa-ecommerce-transactions-de
#PDV configuration
confidentialDataManager.personalDataVault.apiKey=personal-data-vault-api-key
confidentialDataManager.personalDataVault.apiBasePath=http://personal-data-vault-test-host/v1/api
# feature flags
search.pm.in.ecommerce.history.enabled=false

0 comments on commit b030306

Please sign in to comment.