Repository: ansible/eda-server
Pull request #1225: chore: add more versions to startup log
Author: login: Alex-Izquierdo
Created: 2025-02-27T13:11:57Z | Merged: 2025-03-10T17:58:10Z

Follow up https://github.com/ansible/eda-server/pull/1216 by adding some package version that I think are relevant. 
Refactor `get_eda_version` to `get_package_version` for a more general purpose helper. 
Update tests accordingly




Diff:
diff --git a/src/aap_eda/api/views/config.py b/src/aap_eda/api/views/config.py
index 1195a5705..dc9351de8 100644
--- a/src/aap_eda/api/views/config.py
+++ b/src/aap_eda/api/views/config.py
@@ -20,7 +20,7 @@
 from rest_framework.views import APIView
 
 from aap_eda.api.serializers import ConfigSerializer
-from aap_eda.utils import get_eda_version
+from aap_eda.utils import get_package_version
 
 
 class ConfigView(APIView):
@@ -38,7 +38,7 @@ class ConfigView(APIView):
     def get(self, request):
         data = {
             "time_zone": settings.TIME_ZONE,
-            "version": get_eda_version(),
+            "version": get_package_version("aap-eda"),
             "deployment_type": settings.DEPLOYMENT_TYPE,
         }
 
diff --git a/src/aap_eda/settings/default.py b/src/aap_eda/settings/default.py
index f2b25b828..d41c0c711 100644
--- a/src/aap_eda/settings/default.py
+++ b/src/aap_eda/settings/default.py
@@ -564,7 +564,7 @@ def get_rq_queues() -> dict:
 
 SPECTACULAR_SETTINGS = {
     "TITLE": "Event Driven Ansible API",
-    "VERSION": utils.get_eda_version(),
+    "VERSION": utils.get_package_version("aap-eda"),
     "SERVE_INCLUDE_SCHEMA": False,
     "SCHEMA_PATH_PREFIX": f"/{API_PREFIX}/v[0-9]",
     "SCHEMA_PATH_PREFIX_TRIM": True,
diff --git a/src/aap_eda/utils/__init__.py b/src/aap_eda/utils/__init__.py
index c675edca0..c093e260f 100644
--- a/src/aap_eda/utils/__init__.py
+++ b/src/aap_eda/utils/__init__.py
@@ -21,10 +21,10 @@ def str_to_bool(value: str) -> bool:
     return value.lower() in ("yes", "true", "1")
 
 
-def get_eda_version() -> str:
-    """Return EDA version as defined in the aap-eda package."""
+def get_package_version(package_name: str) -> str:
+    """Return version of the given package."""
     try:
-        return importlib.metadata.version("aap-eda")
+        return importlib.metadata.version(package_name)
     except importlib.metadata.PackageNotFoundError:
-        logger.error("Cannot read version from aap-eda package")
+        logger.error("Cannot read version from %s package", package_name)
         return "unknown"
diff --git a/src/aap_eda/utils/logging.py b/src/aap_eda/utils/logging.py
index 36b603a89..48e25f19d 100644
--- a/src/aap_eda/utils/logging.py
+++ b/src/aap_eda/utils/logging.py
@@ -17,7 +17,7 @@
 
 from django.conf import settings
 
-from aap_eda.utils import get_eda_version
+from aap_eda.utils import get_package_version
 
 
 class UnconditionalLogger:
@@ -75,13 +75,25 @@ def log(self, *args, **kwargs):
     "EVENT_STREAM_BASE_URL",
 ]
 
+LOGGING_PACKAGE_VERSIONS = [
+    "podman",
+    "kubernetes",
+    "django-ansible-base",
+]
+
 
 def startup_logging(logger: logging.Logger) -> None:
     """Log unconditional messages for startup."""
     unconditional_logger = UnconditionalLogger(logger)
 
-    unconditional_logger.log(f"Starting eda-server {get_eda_version()}")
+    unconditional_logger.log(
+        f"Starting eda-server {get_package_version('aap-eda')}",
+    )
     unconditional_logger.log(f"Python version: {platform.python_version()}")
+    for pkg in LOGGING_PACKAGE_VERSIONS:
+        unconditional_logger.log(
+            f"{pkg} library version: {get_package_version(pkg)}",
+        )
     unconditional_logger.log(
         f"Platform: {platform.platform()} {platform.architecture()}",
     )
diff --git a/tests/integration/api/test_config.py b/tests/integration/api/test_config.py
index c6d782557..e72924ff6 100644
--- a/tests/integration/api/test_config.py
+++ b/tests/integration/api/test_config.py
@@ -14,7 +14,7 @@
 import pytest
 from django.conf import settings
 
-from aap_eda.utils import get_eda_version
+from aap_eda.utils import get_package_version
 from tests.integration.constants import api_url_v1
 
 
@@ -24,6 +24,6 @@ def test_v1_config(admin_client):
     assert response.status_code == 200
     assert response.data == {
         "time_zone": settings.TIME_ZONE,
-        "version": get_eda_version(),
+        "version": get_package_version("aap-eda"),
         "deployment_type": settings.DEPLOYMENT_TYPE,
     }
diff --git a/tests/unit/test_logging.py b/tests/unit/test_logging.py
index 7acbfda65..b38b4bd2e 100644
--- a/tests/unit/test_logging.py
+++ b/tests/unit/test_logging.py
@@ -4,7 +4,7 @@
 from django.conf import settings
 from django.test import override_settings
 
-from aap_eda.utils import get_eda_version
+from aap_eda.utils import get_package_version
 from aap_eda.utils.logging import SETTINGS_LIST_FOR_LOGGING, startup_logging
 
 
@@ -15,7 +15,7 @@ def test_startup_logging(caplog_factory):
     startup_logging(logger)
 
     assert "Starting eda-server" in caplog.text
-    assert get_eda_version() in caplog.text
+    assert get_package_version("aap-eda") in caplog.text
     assert "Python version" in caplog.text
     assert platform.python_version() in caplog.text
     for setting in SETTINGS_LIST_FOR_LOGGING:
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index b9a373da0..4ef22afde 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -22,7 +22,11 @@
 from rest_framework import serializers
 
 from aap_eda.core.utils.strings import extract_variables
-from aap_eda.utils import get_eda_version, str_to_bool
+from aap_eda.utils import (
+    get_package_version,
+    logger as utils_logger,
+    str_to_bool,
+)
 from aap_eda.utils.openapi import generate_query_params
 
 
@@ -45,12 +49,15 @@ def test_str_to_bool(value, expected):
     assert str_to_bool(value) == expected
 
 
-def test_get_eda_version():
-    assert get_eda_version() == version("aap-eda")
+def test_get_package_version(caplog_factory):
+    eda_caplog = caplog_factory(utils_logger)
+    assert get_package_version("aap-eda") == version("aap-eda")
+    assert get_package_version("podman") == version("podman")
 
-    # assert outcome when aap-eda package is not found
+    # assert outcome when package is not found
     with patch("importlib.metadata.version", side_effect=PackageNotFoundError):
-        assert get_eda_version() == "unknown"
+        assert get_package_version("aap-eda") == "unknown"
+        assert "Cannot read version" in eda_caplog.text
 
 
 @pytest.mark.parametrize(


Reviews:
user: login: ttuffin
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-02-27T13:17:53Z
user: login: ttuffin
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T10:10:21Z
user: login: Dostonbek1
body: looks good to me, except for one minor nitpick below.
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-03T13:26:20Z
user: login: Alex-Izquierdo
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-03T13:44:38Z

Review comments:
diff_hunk: @@ -21,10 +21,10 @@ def str_to_bool(value: str) -> bool:
     return value.lower() in ("yes", "true", "1")
 
 
-def get_eda_version() -> str:
-    """Return EDA version as defined in the aap-eda package."""
+def get_package_version(package_name: str) -> str:
+    """Return version of the given package."""
     try:
-        return importlib.metadata.version("aap-eda")
+        return importlib.metadata.version(package_name)
     except importlib.metadata.PackageNotFoundError:
-        logger.error("Cannot read version from aap-eda package")
+        logger.error("Cannot read version from %s package", package_name)
path: src/aap_eda/utils/__init__.py
user: login: Dostonbek1
body: Should we use f-string here, for better readability?
created_at: 2025-03-03T13:24:44Z
author_association: MEMBER
diff_hunk: @@ -21,10 +21,10 @@ def str_to_bool(value: str) -> bool:
     return value.lower() in ("yes", "true", "1")
 
 
-def get_eda_version() -> str:
-    """Return EDA version as defined in the aap-eda package."""
+def get_package_version(package_name: str) -> str:
+    """Return version of the given package."""
     try:
-        return importlib.metadata.version("aap-eda")
+        return importlib.metadata.version(package_name)
     except importlib.metadata.PackageNotFoundError:
-        logger.error("Cannot read version from aap-eda package")
+        logger.error("Cannot read version from %s package", package_name)
path: src/aap_eda/utils/__init__.py
user: login: Alex-Izquierdo
body: Actually I believe we are doing it wrongly in most of the places with f-strings in logger since it is by default an unsafe method. 
Refs:
https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/logging-format-interpolation.html
https://docs.python.org/3/library/logging.html#formatter-objects

created_at: 2025-03-03T13:44:38Z
author_association: COLLABORATOR

PR comments:
user: login: codecov-commenter
created_at: 2025-02-27T13:32:02Z
body: ## [Codecov](https://app.codecov.io/gh/ansible/eda-server/pull/1225?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 93.64%. Comparing base [(`7e922a9`)](https://app.codecov.io/gh/ansible/eda-server/commit/7e922a9168818ce631d2c2cabe4e66e623b83306?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) to head [(`ad18bc9`)](https://app.codecov.io/gh/ansible/eda-server/commit/ad18bc9c6796cec24a8d03ca03e7183c68216bd1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible).
> Report is 1 commits behind head on main.

```diff
@@           Coverage Diff           @@
##             main    #1225   +/-   ##
=======================================
  Coverage   93.64%   93.64%           
=======================================
  Files         277      277           
  Lines       15709    15715    +6     
=======================================
+ Hits        14710    14716    +6     
  Misses        999      999           
```

| [Flag](https://app.codecov.io/gh/ansible/eda-server/pull/1225/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) | Coverage Δ | |
|---|---|---|
| [unit-int-tests-3.11](https://app.codecov.io/gh/ansible/eda-server/pull/1225/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) | `93.57% <100.00%> (+<0.01%)` | :arrow_up: |
| [unit-int-tests-3.12](https://app.codecov.io/gh/ansible/eda-server/pull/1225/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) | `93.64% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Files with missing lines](https://app.codecov.io/gh/ansible/eda-server/pull/1225?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible) | Coverage Δ | |
|---|---|---|
| [src/aap\_eda/api/views/config.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=src%2Faap_eda%2Fapi%2Fviews%2Fconfig.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-c3JjL2FhcF9lZGEvYXBpL3ZpZXdzL2NvbmZpZy5weQ==) | `100.00% <100.00%> (ø)` | |
| [src/aap\_eda/settings/default.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=src%2Faap_eda%2Fsettings%2Fdefault.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-c3JjL2FhcF9lZGEvc2V0dGluZ3MvZGVmYXVsdC5weQ==) | `89.16% <ø> (ø)` | |
| [src/aap\_eda/utils/\_\_init\_\_.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=src%2Faap_eda%2Futils%2F__init__.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-c3JjL2FhcF9lZGEvdXRpbHMvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | |
| [src/aap\_eda/utils/logging.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=src%2Faap_eda%2Futils%2Flogging.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-c3JjL2FhcF9lZGEvdXRpbHMvbG9nZ2luZy5weQ==) | `96.96% <100.00%> (+0.30%)` | :arrow_up: |
| [tests/integration/api/test\_config.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=tests%2Fintegration%2Fapi%2Ftest_config.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-dGVzdHMvaW50ZWdyYXRpb24vYXBpL3Rlc3RfY29uZmlnLnB5) | `100.00% <100.00%> (ø)` | |
| [tests/unit/test\_logging.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=tests%2Funit%2Ftest_logging.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-dGVzdHMvdW5pdC90ZXN0X2xvZ2dpbmcucHk=) | `100.00% <100.00%> (ø)` | |
| [tests/unit/test\_utils.py](https://app.codecov.io/gh/ansible/eda-server/pull/1225?src=pr&el=tree&filepath=tests%2Funit%2Ftest_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ansible#diff-dGVzdHMvdW5pdC90ZXN0X3V0aWxzLnB5) | `100.00% <100.00%> (ø)` | |

<details><summary>🚀 New features to boost your workflow: </summary>

- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-03-10T17:47:39Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=ansible_eda-server&pullRequest=1225) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=ansible_eda-server&pullRequest=1225&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=ansible_eda-server&pullRequest=1225&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=ansible_eda-server&pullRequest=1225&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=ansible_eda-server&pullRequest=1225&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=ansible_eda-server&pullRequest=1225&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=ansible_eda-server&pullRequest=1225)


author_association: NONE