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

fix(api): update image version handling and remove SENTRY_RELEASE property #196

Merged
merged 1 commit into from
Dec 10, 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
10 changes: 2 additions & 8 deletions api/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Settings(BaseSettings):
def check_image_version(cls, v):
if v == "":
return None
if v.startswith("v"):
return v[1:]
if v and not v.startswith("v"):
return f"v{v}"
return v

@model_validator(mode="before")
Expand Down Expand Up @@ -75,11 +75,5 @@ def SQLALCHEMY_DATABASE_URI(self) -> MariaDBDsn:
path=self.MARIADB_DB,
)

@computed_field
@property
def SENTRY_RELEASE(self) -> str | None:
if self.APP_ENV == "production":
return f"{self.APP_PACKAGE}@{self.IMAGE_VERSION}"


settings = Settings()
4 changes: 2 additions & 2 deletions api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
sentry_sdk.init(
dsn=settings.SENTRY_DSN,
environment=settings.APP_ENV,
release=settings.SENTRY_RELEASE,
release=settings.IMAGE_VERSION,
enable_tracing=True,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
Expand Down Expand Up @@ -48,4 +48,4 @@ def hello():

@app.get("/health")
def health_check():
return {"status": "healthy", "version": settings.SENTRY_RELEASE or "dev"}
return {"status": "healthy", "version": settings.IMAGE_VERSION or "dev"}
14 changes: 5 additions & 9 deletions api/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ def test_settings_defaults():
str(settings.SQLALCHEMY_DATABASE_URI)
== "mysql+pymysql://user:password@localhost:3306/test_db"
)
assert settings.SENTRY_RELEASE is None


def test_settings_with_custom_settings():
custom = Settings(
APP_NAME="api",
APP_PACKAGE="api2",
APP_ENV="production",
IMAGE_VERSION="1.0.0",
IMAGE_VERSION="v1.0.0",
MARIADB_SERVER="127.0.0.1",
MARIADB_PORT=3307,
MARIADB_USER="user2",
Expand All @@ -41,7 +40,7 @@ def test_settings_with_custom_settings():
assert custom.APP_NAME == "api"
assert custom.APP_PACKAGE == "api2"
assert custom.APP_ENV == "production"
assert custom.IMAGE_VERSION == "1.0.0"
assert custom.IMAGE_VERSION == "v1.0.0"
assert custom.MARIADB_SERVER == "127.0.0.1"
assert custom.MARIADB_PORT == 3307
assert custom.MARIADB_USER == "user2"
Expand All @@ -52,16 +51,13 @@ def test_settings_with_custom_settings():
str(custom.SQLALCHEMY_DATABASE_URI)
== "mysql+pymysql://user2:[email protected]:3307/test_db2"
)
assert custom.SENTRY_RELEASE == "[email protected]"


def test_v_prefixed_image_version():
def test_image_version_without_v_prefix():
custom = Settings(
APP_ENV="production",
IMAGE_VERSION="v1.0.0",
IMAGE_VERSION="1.0.0",
)
assert custom.IMAGE_VERSION == "1.0.0"
assert custom.SENTRY_RELEASE == "[email protected]"
assert custom.IMAGE_VERSION == "v1.0.0"


def test_settings_missing_password():
Expand Down
Loading