Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def get_secret_value(secret_name: str, region_name: str) -> str:
"PASSWORD": DB_PASSWORD,
"HOST": os.environ.get("DB_SERVICE_HOST"),
"PORT": os.environ.get("DB_SERVICE_PORT"),
# Database connection pool optimization
"CONN_MAX_AGE": 600, # Keep connections alive for 10 minutes
"OPTIONS": {
"MAX_CONNS": 20, # Maximum number of connections
"MIN_CONNS": 5, # Minimum number of connections
"connect_timeout": 10, # Connection timeout in seconds
"options": "-c default_transaction_isolation=read_committed"
}
}
}

Expand All @@ -138,6 +146,11 @@ def get_secret_value(secret_name: str, region_name: str) -> str:
'level': 'INFO',
'propagate': True,
},
'django.db.backends': {
'handlers': ['console'],
'level': 'WARNING', # Log slow queries
'propagate': False,
},
},
}

Expand Down Expand Up @@ -180,4 +193,4 @@ def get_secret_value(secret_name: str, region_name: str) -> str:
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package org.springframework.samples.petclinic.customers.model;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
* Repository class for <code>Owner</code> domain objects All method names are compliant with Spring Data naming
Expand All @@ -27,4 +30,14 @@
* @author Michael Isvy
* @author Maciej Szarlinski
*/
public interface OwnerRepository extends JpaRepository<Owner, Integer> { }
public interface OwnerRepository extends JpaRepository<Owner, Integer> {

/**
* Custom delete method to prevent StackOverflowError in deleteAllInBatch
* Uses native SQL to avoid Hibernate HQL parsing issues
*/
@Modifying
@Transactional
@Query(value = "DELETE FROM owners", nativeQuery = true)
void deleteAllOwners();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ spring:
config:
import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/}

# HTTP client timeout configuration to prevent ResourceAccessException
server:
tomcat:
connection-timeout: 60000 # 60 seconds
keep-alive-timeout: 60000

# RestTemplate and WebClient timeout configuration
rest:
client:
connection-timeout: 30000 # 30 seconds
read-timeout: 60000 # 60 seconds

eureka:
instance:
preferIpAddress: true
Expand All @@ -16,6 +28,7 @@ logging:
root: OFF
org.springframework.samples.petclinic.customers.web.PetResource: INFO
org.springframework.samples.petclinic.customers.aws.SqsService: FATAL
org.springframework.web.client.RestTemplate: WARN # Log HTTP client errors
pattern:
level: trace_id=%mdc{trace_id} span_id=%mdc{span_id} trace_flags=%mdc{trace_flags} %5p

Expand Down