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

Cleaner version display format #504

Merged
merged 1 commit into from
Sep 16, 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
49 changes: 37 additions & 12 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ beautifulsoup4 = "^4.12.3"
django-allauth = {extras = ["socialaccount"], version = "^0.63.2"}
django-login-required-middleware = "^0.9.0"
django-s3-file-field = {version = "^1.0.1", extras = ["s3"]}
parver = "^0.5"

[tool.poetry.group.dev.dependencies]
django-stubs = "^4.2.7"
Expand Down
13 changes: 12 additions & 1 deletion rdwatch/core/views/server_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any

from ninja import Field, Router, Schema
from parver import Version

from django.http import HttpRequest

Expand Down Expand Up @@ -40,6 +41,16 @@ def get_status(request: HttpRequest):
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)

parsed_version = Version.parse(api.version)

version = 'v'
version += '.'.join(str(v) for v in parsed_version.release)

# If this is a pre-release version, include the pre-release version string
post_num: int | None = parsed_version.post
if post_num is not None:
version += f'.post{post_num}+{parsed_version.local}'
Comment on lines +50 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between api.version and the string constructed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the current version is not a tagged release, they differ only slightly. For example, for the latest commit on this branch

print(api.version)  # prints '1.10.2.post5.dev0+b074e39c'
print(version)  # prints 'v1.10.2.post5+b074e39c'

The main motivation behind this change is to make it look more user friendly when the curent version is a tagged release, which looks like this

print(api.version)  # prints '1.12+b074e39c'
print(version)  # prints 'v1.12'


try:
smartflow_status = SmartFlowClient().get_health().to_dict()
except Exception:
Expand All @@ -49,6 +60,6 @@ def get_status(request: HttpRequest):
uptime=uptime,
hostname=hostname,
ip=ip,
rdwatch_version=api.version,
rdwatch_version=version,
smartflow=smartflow_status,
)
Loading