Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor config values #31

Merged
merged 1 commit into from
Jan 31, 2024
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
5 changes: 0 additions & 5 deletions configs/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ app:
port: 8000
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

http:
port: 8080
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

rpc:
port: 50051
Expand All @@ -22,7 +20,6 @@ logging:
level_app: debug
level_libs: info
handlers: [console]

syslog_app: null
syslog_facility: null
syslog_mapping: null
Expand All @@ -31,8 +28,6 @@ logging:
postgres:
host: postgres
port: 5432
user: postgres
password: postgres
database: featureflags
timeout: 10

Expand Down
5 changes: 0 additions & 5 deletions configs/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ app:
port: 8000
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

http:
port: 8080
host: 0.0.0.0
reload: True
thread_limiter_total_tokens: 40

rpc:
port: 50051
Expand All @@ -22,7 +20,6 @@ logging:
level_app: debug
level_libs: info
handlers: [console]

syslog_app: null
syslog_facility: null
syslog_mapping: null
Expand All @@ -31,8 +28,6 @@ logging:
postgres:
host: postgres-test
port: 5432
user: postgres
password: postgres
database: featureflags-test
timeout: 10

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ services:
PYTHONIOENCODING: UTF-8
PYTHONUNBUFFERED: 1
CONFIG_PATH: configs/local.yaml
PGUSER: postgres
PGPASS: postgres
networks:
- main
volumes:
Expand Down
10 changes: 5 additions & 5 deletions featureflags/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import yaml
from pydantic import Field
from pydantic_settings import BaseSettings

log = logging.getLogger(__name__)
Expand All @@ -17,7 +18,6 @@ class LoggingSettings(BaseSettings):
level_app: str
level_libs: str
handlers: list[str]

syslog_app: str | None
syslog_facility: str | None
syslog_mapping: dict | None
Expand All @@ -27,8 +27,8 @@ class LoggingSettings(BaseSettings):
class PostgresSettings(BaseSettings):
host: str
port: int
user: str
password: str
user: str = Field(..., alias="PGUSER")
password: str = Field(..., alias="PGPASS")
database: str
timeout: int = 10

Expand Down Expand Up @@ -56,14 +56,14 @@ class AppSettings(BaseSettings):
port: int = 8000
host: str = "0.0.0.0"
reload: bool = False
thread_limiter_total_tokens: int = 40
max_concurrent_threads: int = 40


class HttpSettings(BaseSettings):
port: int = 8080
host: str = "0.0.0.0"
reload: bool = False
thread_limiter_total_tokens: int = 40
max_concurrent_threads: int = 40


class RpcSettings(BaseSettings):
Expand Down
3 changes: 2 additions & 1 deletion featureflags/http/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ async def startup() -> None:
"""Application startup functions."""

# https://github.com/tiangolo/fastapi/discussions/8587
# Adjust this value to limit the number of concurrent threads.
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = config.http.thread_limiter_total_tokens
limiter.total_tokens = config.http.max_concurrent_threads

await container.init_resources()

Expand Down
15 changes: 0 additions & 15 deletions featureflags/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ def configure_logging(package: str) -> None:
logging.root.setLevel(config.logging.level_libs.upper())
logging.getLogger(package).setLevel(config.logging.level_app.upper())

if "logevo" in config.logging.handlers:
if len(config.logging.handlers) > 1:
raise ValueError("logevo handler must be used alone")

try:
import logevo

logevo.configure_logging()
except ImportError as e:
raise ImportError(
"logevo handler is used but 'logevo' package is not installed"
) from e
else:
log.info("Logevo configured")

if "console" in config.logging.handlers:
logging.root.addHandler(create_console_handler())

Expand Down
3 changes: 2 additions & 1 deletion featureflags/web/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ async def startup() -> None:
"""Application startup functions."""

# https://github.com/tiangolo/fastapi/discussions/8587
# Adjust this value to limit the number of concurrent threads.
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = config.app.thread_limiter_total_tokens
limiter.total_tokens = config.app.max_concurrent_threads

await container.init_resources()

Expand Down
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading