Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/pre-processing-service/app/api/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#๋ชจ๋“ˆ ํ…Œ์Šคํ„ฐ๋ฅผ ์œ„ํ•œ endpoint -> ์ถ”ํ›„ ์‚ญ์ œ ์˜ˆ์ •
api_router.include_router(test.router, prefix="/tests", tags=["Test"])

@api_router.get("/")
@api_router.get("/ping")
async def root():
return {"message": "์„œ๋ฒ„ ์‹คํ–‰์ค‘์ž…๋‹ˆ๋‹ค."}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gltkorea.icebang.common.health.api;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gltkorea.icebang.common.health.service.FastApiClient;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class HealthCheckController {

private final FastApiClient fastApiClient;

/**
* Spring Boot์™€ FastAPI ์„œ๋ฒ„ ๊ฐ„์˜ ์—ฐ๊ฒฐ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ํ—ฌ์Šค ์ฒดํฌ API
*
* @return FastAPI ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ์˜ ์‘๋‹ต
*/
@GetMapping("/ping")
public ResponseEntity<String> pingFastApi() {
String result = fastApiClient.ping();

if (result.startsWith("ERROR")) {
// FastAPI ์—ฐ๊ฒฐ ์‹คํŒจ ์‹œ 503 Service Unavailable ์ƒํƒœ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
return ResponseEntity.status(503).body(result);
}

// ์„ฑ๊ณต ์‹œ 200 OK ์ƒํƒœ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ FastAPI๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์‘๋‹ต("PONG" ๋“ฑ) ๋ฐ˜ํ™˜
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.gltkorea.icebang.common.health.service;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class FastApiClient {

// WebConfig์—์„œ ์ƒ์„ฑํ•˜๊ณ  ํƒ€์ž„์•„์›ƒ์ด ์„ค์ •๋œ RestTemplate Bean์„ ์ฃผ์ž…๋ฐ›์Šต๋‹ˆ๋‹ค.
private final RestTemplate restTemplate;

// FastAPI ์„œ๋ฒ„์˜ ping ์—”๋“œํฌ์ธํŠธ URL์„ ์ƒ์ˆ˜๋กœ ํ•˜๋“œ์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค.
private static final String FASTAPI_PING_URL = "http://localhost:8000/ping";

/**
* FastAPI ์„œ๋ฒ„์˜ /ping ์—”๋“œํฌ์ธํŠธ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์—ฐ๊ฒฐ์„ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
*
* @return ์—ฐ๊ฒฐ ์„ฑ๊ณต ์‹œ FastAPI๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์‘๋‹ต, ์‹คํŒจ ์‹œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€
*/
public String ping() {
log.info("Attempting to connect to FastAPI server at: {}", FASTAPI_PING_URL);

try {
// FastAPI ์„œ๋ฒ„์— GET ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , ์‘๋‹ต์„ String์œผ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.
// WebConfig์— ์„ค์ •๋œ 5์ดˆ ํƒ€์ž„์•„์›ƒ์ด ์—ฌ๊ธฐ์„œ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
String response = restTemplate.getForObject(FASTAPI_PING_URL, String.class);
log.info("Successfully received response from FastAPI: {}", response);
return response;
} catch (RestClientException e) {
// RestClientException์€ ์—ฐ๊ฒฐ ์‹คํŒจ, ํƒ€์ž„์•„์›ƒ ๋“ฑ ๋ชจ๋“  ํ†ต์‹  ์˜ค๋ฅ˜๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.
log.error(
"Failed to connect to FastAPI server at {}. Error: {}", FASTAPI_PING_URL, e.getMessage());
return "ERROR: Cannot connect to FastAPI";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum SecurityEndpoints {
PUBLIC(
"/",
"/ping",
"/v0/auth/login",
"/api/public/**",
"/health",
Expand Down
Loading