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

[Internal][Executor] Add commit id to version api #2496

Merged
merged 4 commits into from
Mar 27, 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
6 changes: 4 additions & 2 deletions src/promptflow/promptflow/executor/_service/apis/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from fastapi.responses import PlainTextResponse

from promptflow._utils.feature_utils import get_feature_list
from promptflow.executor._service.utils.service_utils import get_executor_version
from promptflow._version import VERSION
from promptflow.executor._service.utils.service_utils import get_commit_id

router = APIRouter()

Expand All @@ -20,6 +21,7 @@ def health_check():
def version():
return {
"status": "healthy",
"version": get_executor_version(),
"version": VERSION,
"commit_id": get_commit_id(),
"feature_list": get_feature_list(),
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ def update_and_get_operation_context(context_dict: Mapping[str, Any]) -> Operati
return operation_context
# update operation context with context_dict
operation_context.update(context_dict)
# update user agent to operation context
executor_user_agent = get_executor_version()
operation_context.append_user_agent(executor_user_agent)
# update promptflow version to operation context
operation_context.append_user_agent(f"promptflow/{VERSION}")
return operation_context


def get_executor_version():
def get_commit_id():
"""Get commit id from BUILD_INFO environment variable.

BUILD_INFO is a json string in the promptflow-python image, like
'{
"build_number": "20240326.v2",
"date": "2024-03-27 05:12:33",
"commit_id": "...",
"branch": "main"
}'
"""
build_info = os.environ.get("BUILD_INFO", "")
try:
build_info_dict = json.loads(build_info)
return "promptflow-executor/" + build_info_dict["build_number"]
return build_info_dict["commit_id"]
except Exception:
return "promptflow-executor/" + VERSION
return "unknown"


def generate_error_response(ex: Union[dict, Exception]):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from fastapi.testclient import TestClient

from promptflow._version import VERSION


@pytest.mark.unittest
class TestCommonApis:
Expand All @@ -11,12 +13,13 @@ def test_health(self, executor_client: TestClient):

def test_version(self, monkeypatch, executor_client: TestClient):
# mock the BUILD_INFO env variable
monkeypatch.setenv("BUILD_INFO", '{"build_number": "20240131.v1"}')
monkeypatch.setenv("BUILD_INFO", '{"commit_id": "test-commit-id"}')

response = executor_client.get("/version")
assert response.status_code == 200

response = response.json()
assert response["status"] == "healthy"
assert response["version"] == "promptflow-executor/20240131.v1"
assert response["version"] == VERSION
assert response["commit_id"] == "test-commit-id"
assert isinstance(response["feature_list"], list)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from promptflow.executor._service.contracts.execution_request import BaseExecutionRequest, FlowExecutionRequest
from promptflow.executor._service.utils.service_utils import (
generate_error_response,
get_executor_version,
get_commit_id,
get_log_context,
set_environment_variables,
update_and_get_operation_context,
Expand Down Expand Up @@ -63,22 +63,19 @@ def test_update_and_get_operation_context(self, monkeypatch):
"user_agent": "dummy_user_agent",
"request_id": "dummy_request_id",
}
# mock the BUILD_INFO env variable
monkeypatch.setenv("BUILD_INFO", '{"build_number": "20240131.v1"}')

operation_context = update_and_get_operation_context(context_dict)
assert operation_context.user_agent == "dummy_user_agent promptflow-executor/20240131.v1 promptflow/0.0.1"
assert operation_context.user_agent == "dummy_user_agent promptflow/0.0.1"
assert operation_context.request_id == "dummy_request_id"

def test_get_executor_version(self, monkeypatch):
def test_get_commit_id(self, monkeypatch):
# mock have the BUILD_INFO env variable
monkeypatch.setenv("BUILD_INFO", '{"build_number": "20240131.v1"}')
executor_version = get_executor_version()
assert executor_version == "promptflow-executor/20240131.v1"
monkeypatch.setenv("BUILD_INFO", '{"commit_id": "test-commit-id"}')
commit_id = get_commit_id()
assert commit_id == "test-commit-id"
# mock do not have the BUILD_INFO env variable
monkeypatch.setenv("BUILD_INFO", "")
executor_version = get_executor_version()
assert executor_version == "promptflow-executor/0.0.1"
commit_id = get_commit_id()
assert commit_id == "unknown"

def test_generate_error_response(self):
non_pf_ex = ValueError("Test exception")
Expand Down
Loading