Skip to content

Commit

Permalink
Merge pull request #525 from LerianStudio/feature/MIDAZ-517
Browse files Browse the repository at this point in the history
Feature/MIDAZ-517
  • Loading branch information
MartinezAvellan authored Feb 18, 2025
2 parents 5eacb6d + a03dcdd commit f34afa8
Show file tree
Hide file tree
Showing 30 changed files with 539 additions and 152 deletions.
3 changes: 3 additions & 0 deletions components/audit/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ services:
- audit_network
- infra_network
- auth_network
depends_on:
- midaz-audit-server
- midaz-audit-signer

midaz-audit-db:
container_name: midaz-audit-db
Expand Down
5 changes: 5 additions & 0 deletions components/infra/.env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# INFRA

# PG BOUNCER
DB_PGBOUNCER_PORT=5706

# DB POSTGRESQL PRIMARY AND REPLICA
DB_HOST=midaz-postgres-primary
DB_USER=midaz
DB_PASSWORD=lerian
DB_PORT=5701
MAX_CONNECTIONS=3000
SHARED_BUFFERS=1GB

DB_REPLICA_HOST=midaz-postgres-replica
DB_REPLICA_USER=midaz
Expand Down
27 changes: 27 additions & 0 deletions components/infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ services:
-c max_wal_senders=10
-c max_replication_slots=10
-c hot_standby_feedback=on
-c max_connections=${MAX_CONNECTIONS}
-c shared_buffers=${SHARED_BUFFERS}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
Expand All @@ -96,10 +98,18 @@ services:
echo 'Waiting for midaz-postgres-primary to connect...'
sleep 1s
done
echo 'Backup done..., starting midaz-postgres-replica...'
chmod 0700 /var/lib/postgresql/data
# Ensure the port is set to use for the replica
sed -i 's/^#port.*/port = ${DB_REPLICA_PORT}/' /var/lib/postgresql/data/postgresql.conf
# Define database max conn
sed -i 's/^#*max_connections.*/max_connections = ${MAX_CONNECTIONS}/' /var/lib/postgresql/data/postgresql.conf
# Define database shared buffers
sed -i 's/^#*shared_buffers.*/shared_buffers = ${SHARED_BUFFERS}/' /var/lib/postgresql/data/postgresql.conf
fi
exec postgres -c config_file=/var/lib/postgresql/data/postgresql.conf
"
Expand All @@ -112,6 +122,23 @@ services:
midaz-postgres-primary:
condition: service_healthy

midaz-pgbouncer:
image: edoburu/pgbouncer
container_name: midaz-pgbouncer
restart: always
ports:
- ${DB_PGBOUNCER_PORT}:${DB_PGBOUNCER_PORT}
volumes:
- ./pgbouncer/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini:ro
- ./pgbouncer/userlist.txt:/etc/pgbouncer/userlist.txt:ro
environment:
- DATABASES_HOST=localhost
networks:
- infra_network
depends_on:
- midaz-postgres-primary
- midaz-postgres-replica

midaz-otel-lgtm:
container_name: midaz-otel-lgtm
image: grafana/otel-lgtm:latest
Expand Down
21 changes: 21 additions & 0 deletions components/infra/pgbouncer/pgbouncer.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pgbouncer.ini

[databases]
transaction_primary = host=midaz-postgres-primary port=5701 dbname=transaction
transaction_replica = host=midaz-postgres-replica port=5702 dbname=transaction

onboarding_primary = host=midaz-postgres-primary port=5701 dbname=onboarding
onboarding_replica = host=midaz-postgres-replica port=5702 dbname=onboarding

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 5706
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
pool_mode = transaction
admin_users = postgres
ignore_startup_parameters = extra_float_digits

max_client_conn = 3000
default_pool_size = 2500
server_idle_timeout = 30
1 change: 1 addition & 0 deletions components/infra/pgbouncer/userlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"midaz" "lerian"
18 changes: 18 additions & 0 deletions components/infra/rabbitmq/etc/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"name": "transaction_balance_queue",
"vhost": "/",
"durable": true
},
{
"name": "balance_retry_queue",
"vhost": "/",
"durable": true
}
],
"exchanges": [
Expand All @@ -84,6 +89,12 @@
"vhost": "/",
"type": "direct",
"durable": true
},
{
"name": "balance_retry_queue_exchange",
"vhost": "/",
"type": "direct",
"durable": true
}
],
"bindings": [
Expand All @@ -100,6 +111,13 @@
"destination": "transaction_balance_queue",
"destination_type": "queue",
"routing_key": "transaction_balance_key"
},
{
"source": "balance_retry_queue_exchange",
"vhost": "/",
"destination": "balance_retry_queue",
"destination_type": "queue",
"routing_key": "balance_retry_queue_key"
}
]
}
29 changes: 23 additions & 6 deletions components/onboarding/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,34 @@ SERVER_PORT=3000
SERVER_ADDRESS=:${SERVER_PORT}

# DB POSTGRESQL PRIMARY AND REPLICA
DB_HOST=midaz-postgres-primary
#DB_HOST=midaz-postgres-primary
#DB_USER=midaz
#DB_NAME=onboarding
#DB_PASSWORD=lerian
#DB_PORT=5701

#DB_REPLICA_HOST=midaz-postgres-replica
#DB_REPLICA_USER=midaz
#DB_REPLICA_NAME=onboarding
#DB_REPLICA_PASSWORD=lerian
#DB_REPLICA_PORT=5702

DB_MAX_OPEN_CONNS=3000
DB_MAX_IDLE_CONNS=3000

# DB PGBOUNCE PRIMARY
DB_HOST=midaz-pgbouncer
DB_USER=midaz
DB_NAME=onboarding
DB_NAME=onboarding_primary
DB_PASSWORD=lerian
DB_PORT=5701
DB_PORT=5706

DB_REPLICA_HOST=midaz-postgres-replica
# DB PGBOUNCE REPLICA
DB_REPLICA_HOST=midaz-pgbouncer
DB_REPLICA_USER=midaz
DB_REPLICA_NAME=onboarding
DB_REPLICA_NAME=onboarding_replica
DB_REPLICA_PASSWORD=lerian
DB_REPLICA_PORT=5702
DB_REPLICA_PORT=5706

# MONGO DB
#MONGO_URI=mongodb+srv
Expand Down
36 changes: 27 additions & 9 deletions components/transaction/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,34 @@ APP_CONTEXT=/transaction/v1
SERVER_PORT=3001
SERVER_ADDRESS=:${SERVER_PORT}

# DB POSTGRESQL PRIMARY
DB_HOST=midaz-postgres-primary
# DB POSTGRESQL PRIMARY AND REPLICA
#DB_HOST=midaz-postgres-primary
#DB_USER=midaz
#DB_NAME=transaction
#DB_PASSWORD=lerian
#DB_PORT=5701
#
#DB_REPLICA_HOST=midaz-postgres-replica
#DB_REPLICA_USER=midaz
#DB_REPLICA_NAME=transaction
#DB_REPLICA_PASSWORD=lerian
#DB_REPLICA_PORT=5702

DB_MAX_OPEN_CONNS=3000
DB_MAX_IDLE_CONNS=3000

# DB PGBOUCE PRIMARY AND REPLICA
DB_HOST=midaz-pgbouncer
DB_USER=midaz
DB_NAME=transaction
DB_NAME=transaction_primary
DB_PASSWORD=lerian
DB_PORT=5701
DB_PORT=5706

# DB POSTGRESQL REPLICA
DB_REPLICA_HOST=midaz-postgres-replica
DB_REPLICA_HOST=midaz-pgbouncer
DB_REPLICA_USER=midaz
DB_REPLICA_NAME=transaction
DB_REPLICA_NAME=transaction_replica
DB_REPLICA_PASSWORD=lerian
DB_REPLICA_PORT=5702
DB_REPLICA_PORT=5706

# MONGO DB
#MONGO_URI=mongodb+srv
Expand Down Expand Up @@ -69,6 +84,9 @@ RABBITMQ_DEFAULT_PASS=lerian
RABBITMQ_AUDIT_EXCHANGE=audit_exchange
RABBITMQ_AUDIT_KEY=audit_key
RABBITMQ_QUEUE=transaction_balance_queue
RABBITMQ_BALANCE_RETRY_EXCHANGE=balance_retry_queue_exchange
RABBITMQ_BALANCE_RETRY_KEY=balance_retry_queue_key
RABBITMQ_BALANCE_RETRY_QUEUE=balance_retry_queue

# SWAGGER
SWAGGER_TITLE=Transaction API
Expand All @@ -81,7 +99,7 @@ SWAGGER_LEFT_DELIMITER={{
SWAGGER_RIGHT_DELIMITER=}}

# AUDIT
AUDIT_LOG_ENABLED=true
AUDIT_LOG_ENABLED=false

# PAGINATION
MAX_PAGINATION_LIMIT=100
Expand Down
Loading

0 comments on commit f34afa8

Please sign in to comment.