Skip to content

Commit 2f88d04

Browse files
committed
feat: set log and tracer before start server
Signed-off-by: ImMin5 <mino@megazone.com>
1 parent bb2fc2a commit 2f88d04

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

src/spaceone/core/fastapi/server.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
2-
import os
32

43
import uvicorn
4+
from anyio import to_thread
55
from fastapi import FastAPI
66
from fastapi.middleware.cors import CORSMiddleware
77

@@ -122,6 +122,8 @@ def _add_middlewares(app):
122122
def _init_fast_api():
123123
global_conf = config.get_global()
124124
server_info = ServerInfoManager()
125+
# set thread pool size
126+
to_thread.current_default_thread_limiter().total_tokens = global_conf.get('REST_MAX_THREAD_POOL', 40)
125127

126128
return FastAPI(
127129
title=global_conf.get('REST_TITLE', 'Document'),
@@ -131,39 +133,7 @@ def _init_fast_api():
131133
)
132134

133135

134-
def set_server_config_from_env():
135-
package = os.environ.get('SPACEONE_PACKAGE')
136-
host = os.environ['SPACEONE_HOST']
137-
module_path = tuple(os.environ.get('SPACEONE_MODULE_PATH').split(', '))
138-
port = os.environ.get('SPACEON_PORT')
139-
config_file = os.environ.get('SPACEONE_CONFIG_FILE')
140-
141-
# 1. Set a python path
142-
utils.set_python_path(package, module_path)
143-
144-
# 2. Initialize config from command argument
145-
config.init_conf(
146-
package=package,
147-
port=port
148-
)
149-
150-
# 3. Get service config from global_conf.py
151-
config.set_service_config()
152-
153-
# 4. Merge file conf
154-
if config_file:
155-
config.set_file_conf(config_file)
156-
157-
158136
def fast_api_app():
159-
set_server_config_from_env()
160-
161-
# Enable logging configuration\
162-
set_logger()
163-
164-
# Set OTel Tracer and Metric|
165-
set_tracer()
166-
167137
app = _init_fast_api()
168138
app = _add_middlewares(app)
169139
app = _include_routers(app)
@@ -173,6 +143,12 @@ def fast_api_app():
173143
def serve():
174144
conf = config.get_global()
175145

146+
# Enable logging configuration\
147+
set_logger()
148+
149+
# Set OTel Tracer and Metric|
150+
set_tracer()
151+
176152
uvicorn_options = conf.get('UVICORN_OPTIONS', {})
177153

178154
_LOGGER.info(f'Start REST Server ({config.get_service()}): '

0 commit comments

Comments
 (0)