Skip to content

Commit 4259708

Browse files
committed
feat: MongoDB yapılandırmasında iyileştirmeler yapıldı; bağlantı kontrolü eklendi ve gereksiz dosyalar kaldırıldı
1 parent bce1036 commit 4259708

File tree

12 files changed

+83
-217
lines changed

12 files changed

+83
-217
lines changed

.github/workflows/activity-log-service-ci-cd.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ jobs:
3636
path: ~/.m2
3737
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
3838
restore-keys: ${{ runner.os }}-m2
39-
40-
- name: Check and remove Firestore configuration if exists
41-
run: |
42-
FIRESTORE_CONFIG_PATH="activity-log-service/src/main/java/com/craftpilot/activitylogservice/config/FirestoreConfig.java"
43-
if [ -f "$FIRESTORE_CONFIG_PATH" ]; then
44-
echo "Removing FirestoreConfig.java file"
45-
rm "$FIRESTORE_CONFIG_PATH"
46-
fi
47-
39+
4840
- name: Build commons library (if needed)
4941
run: |
5042
if [ -d "craft-pilot-commons" ]; then
@@ -196,7 +188,7 @@ jobs:
196188
echo "=== MongoDB'nin hazır olduğunu kontrol ediliyor ==="
197189
mongo_ready=false
198190
for i in {1..10}; do
199-
if docker exec -t activity-log-service curl -s mongodb:27017 > /dev/null 2>&1; then
191+
if docker exec -t activity-log-service wget -q --spider --timeout=2 http://mongodb:27017 > /dev/null 2>&1 || docker exec -t activity-log-service nc -z -w2 mongodb 27017 > /dev/null 2>&1; then
200192
echo "✓ MongoDB erişilebilir durumdadır"
201193
mongo_ready=true
202194
break

.github/workflows/analytics-service-ci-cd.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ jobs:
103103
-e MANAGEMENT_HEALTH_VALIDATE_GROUP_MEMBERSHIP=false \
104104
-e LOGGING_LEVEL_COM_CRAFTPILOT=DEBUG \
105105
-e LOGGING_LEVEL_COM_GOOGLE_CLOUD=DEBUG \
106+
-e MONGODB_URI=${{ secrets.MONGODB_URI }} \
107+
-e KAFKA_BOOTSTRAP_SERVERS=kafka:9092 \
108+
-e KAFKA_ENABLED=${KAFKA_ENABLED:-false} \
106109
${{ secrets.DOCKERHUB_USERNAME }}/analytics-service:latest-arm64
107110
108111
echo "=== Waiting for Container to Start ==="

analytics-service/src/main/java/com/craftpilot/analyticsservice/config/MongoIndexConfig.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
import org.springframework.scheduling.annotation.Async;
1515
import org.springframework.scheduling.annotation.EnableAsync;
1616

17+
import com.mongodb.MongoSocketException;
1718
import com.mongodb.MongoSocketOpenException;
1819
import com.mongodb.MongoTimeoutException;
20+
import com.mongodb.ServerAddress;
21+
import com.mongodb.connection.ServerSettings;
1922

2023
import lombok.extern.slf4j.Slf4j;
2124
import reactor.core.publisher.Mono;
2225
import java.time.Duration;
26+
import java.net.InetAddress;
27+
import java.net.UnknownHostException;
2328

2429
@Configuration
2530
@Slf4j
@@ -44,6 +49,9 @@ public class MongoIndexConfig {
4449

4550
@Value("${mongodb.indexes.creation.startup-fail-fast:false}")
4651
private boolean startupFailFast;
52+
53+
@Value("${spring.data.mongodb.uri}")
54+
private String mongoUri;
4755

4856
@Autowired
4957
public MongoIndexConfig(ReactiveMongoTemplate mongoTemplate) {
@@ -62,9 +70,52 @@ public void initIndexesAfterStartup() {
6270
return;
6371
}
6472

73+
// MongoDB URI'dan host adresini çıkar ve bağlantı kontrolü yap
74+
try {
75+
String host = extractHostFromUri(mongoUri);
76+
if (host != null) {
77+
log.info("Testing connection to MongoDB host: {}", host);
78+
boolean hostResolvable = isHostResolvable(host);
79+
log.info("MongoDB host resolution test: {}", hostResolvable ? "SUCCESS" : "FAILED");
80+
if (!hostResolvable) {
81+
log.warn("MongoDB host cannot be resolved. This may cause connection problems.");
82+
}
83+
}
84+
} catch (Exception e) {
85+
log.warn("Could not extract or validate MongoDB host: {}", e.getMessage());
86+
}
87+
6588
// Indeks oluşturmayı async olarak başlat
6689
asyncCreateIndexes(0);
6790
}
91+
92+
private String extractHostFromUri(String uri) {
93+
try {
94+
// mongodb://username:password@host:port/database
95+
if (uri != null && uri.contains("@")) {
96+
String hostPart = uri.split("@")[1];
97+
if (hostPart.contains("/")) {
98+
hostPart = hostPart.split("/")[0];
99+
}
100+
if (hostPart.contains(":")) {
101+
return hostPart.split(":")[0];
102+
}
103+
return hostPart;
104+
}
105+
} catch (Exception e) {
106+
log.warn("Error extracting host from MongoDB URI: {}", e.getMessage());
107+
}
108+
return null;
109+
}
110+
111+
private boolean isHostResolvable(String host) {
112+
try {
113+
InetAddress.getByName(host);
114+
return true;
115+
} catch (UnknownHostException e) {
116+
return false;
117+
}
118+
}
68119

69120
@Async
70121
protected void asyncCreateIndexes(int attempt) {
@@ -128,7 +179,7 @@ private boolean testConnection() {
128179
}
129180

130181
@Retryable(
131-
value = {MongoSocketOpenException.class, MongoTimeoutException.class},
182+
value = {MongoSocketException.class, MongoTimeoutException.class},
132183
maxAttempts = 3,
133184
backoff = @Backoff(delay = 1000, multiplier = 2)
134185
)
@@ -158,7 +209,7 @@ private void createUsageMetricsIndexes() {
158209
}
159210

160211
@Retryable(
161-
value = {MongoSocketOpenException.class, MongoTimeoutException.class},
212+
value = {MongoSocketException.class, MongoTimeoutException.class},
162213
maxAttempts = 3,
163214
backoff = @Backoff(delay = 1000, multiplier = 2)
164215
)
@@ -182,7 +233,7 @@ private void createPerformanceMetricsIndexes() {
182233
}
183234

184235
@Retryable(
185-
value = {MongoSocketOpenException.class, MongoTimeoutException.class},
236+
value = {MongoSocketException.class, MongoTimeoutException.class},
186237
maxAttempts = 3,
187238
backoff = @Backoff(delay = 1000, multiplier = 2)
188239
)

analytics-service/src/main/resources/application.properties

Lines changed: 0 additions & 27 deletions
This file was deleted.

analytics-service/src/main/resources/application.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spring:
2020
fail-fast: false
2121
data:
2222
mongodb:
23-
uri: ${MONGODB_URI:mongodb://mongodb:27017/analytics}
23+
uri: ${MONGODB_URI:mongodb://craftpilot:secure_password@mongodb:27017/analytics?authSource=admin&retryWrites=true&w=majority}
2424
auto-index-creation: true
2525
connection-timeout: 30000
2626
socket-timeout: 60000
@@ -38,6 +38,9 @@ kafka:
3838
admin:
3939
fail-fast: false
4040
auto-create: true
41+
bootstrap-timeout: 10000
42+
operations-timeout: 10000
43+
close-timeout: 5000
4144

4245
# Add MongoDB resilience configuration
4346
mongodb:

credit-service/k8s/configmap.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

credit-service/k8s/deployment.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

credit-service/k8s/hpa.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

credit-service/k8s/service.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

credit-service/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spring:
6060
web-application-type: reactive
6161
data:
6262
mongodb:
63-
uri: ${MONGODB_URI:mongodb://craftpilot:secure_password@mongodb:27017/craftpilot?authSource=admin&retryWrites=true&w=majority}
63+
uri: ${MONGODB_URI:mongodb://craftpilot:secure_password@mongodb:27017/craftpilot?authSource=admin&retryWrites=true&w=majority&serverSelectionTimeoutMS=5000}
6464
database: ${MONGODB_DATABASE:craftpilot}
6565
connection-timeout: 30000
6666
socket-timeout: 60000

0 commit comments

Comments
 (0)