-
Notifications
You must be signed in to change notification settings - Fork 77
[AgentOps][Code Quality] Better organization for env [1/n] #443
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """Centralized configuration for the Traceroot backend. | ||
|
|
||
| All environment variables are read once at import time via Pydantic Settings. | ||
| Services import ``settings`` from this module instead of calling os.getenv(). | ||
|
|
||
| Environment variables are loaded from .env by entrypoints (rest/main.py, | ||
| worker/celery_app.py) before this module is first imported. | ||
| """ | ||
|
|
||
| from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
|
||
|
|
||
| class ClickHouseSettings(BaseSettings): | ||
| """ClickHouse connection settings. | ||
|
|
||
| Env vars: CLICKHOUSE_HOST, CLICKHOUSE_PORT, CLICKHOUSE_NATIVE_PORT, | ||
| CLICKHOUSE_USER, CLICKHOUSE_PASSWORD, CLICKHOUSE_DATABASE | ||
| """ | ||
|
|
||
| model_config = SettingsConfigDict(env_prefix="CLICKHOUSE_") | ||
|
|
||
| host: str = "localhost" | ||
| port: int = 8123 | ||
| native_port: int = 9000 | ||
| user: str = "clickhouse" | ||
| password: str = "clickhouse" | ||
| database: str = "default" | ||
|
|
||
|
|
||
| class S3Settings(BaseSettings): | ||
| """S3/MinIO settings for trace data storage. | ||
|
|
||
| Env vars: S3_ENDPOINT_URL, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, | ||
| S3_BUCKET_NAME, S3_REGION | ||
| """ | ||
|
|
||
| model_config = SettingsConfigDict(env_prefix="S3_") | ||
|
|
||
| endpoint_url: str | None = None | ||
| access_key_id: str | None = None | ||
| secret_access_key: str | None = None | ||
| bucket_name: str = "traceroot" | ||
| region: str = "us-east-1" | ||
|
|
||
|
|
||
| class RedisSettings(BaseSettings): | ||
| """Redis settings for Celery broker and result backend. | ||
|
|
||
| Env vars: REDIS_URL, REDIS_RESULT_URL | ||
| """ | ||
|
|
||
| model_config = SettingsConfigDict(env_prefix="REDIS_") | ||
|
|
||
| url: str = "redis://localhost:6379/0" | ||
| result_url: str = "redis://localhost:6379/1" | ||
|
|
||
|
|
||
| class Settings(BaseSettings): | ||
| """Root settings for the Traceroot backend. | ||
|
|
||
| Nested settings (clickhouse, s3, redis) each read from their own | ||
| prefixed env vars. Top-level fields read from unprefixed env vars. | ||
| """ | ||
|
|
||
| # CORS | ||
| cors_origins: list[str] = ["http://localhost:3000"] | ||
|
|
||
| # Internal communication (Python <-> Next.js) | ||
| traceroot_ui_url: str = "http://localhost:3000" | ||
| internal_api_secret: str = "" | ||
|
|
||
| # Service-specific settings | ||
| clickhouse: ClickHouseSettings = ClickHouseSettings() | ||
| s3: S3Settings = S3Settings() | ||
| redis: RedisSettings = RedisSettings() | ||
|
|
||
|
|
||
| settings = Settings() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty internal secret
internal_api_secretdefaults to"", which means the backend can start up withoutINTERNAL_API_SECRETand then all internal auth calls that sendX-Internal-Secretwill fail at runtime (or, if the frontend is also configured with an empty secret, effectively disables the shared-secret check). If the intent is “fail fast at startup”, this should be validated as non-empty (no default) so misconfiguration is caught immediately.