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

Update perf logging workflow to get branch+sha from gh context #2791

Merged
merged 1 commit into from
Jan 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
2 changes: 2 additions & 0 deletions .github/workflows/run_tests_in_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
env:
MLFLOW_TRACKING_SERVER_URI: ${{ vars.MLFLOW_TRACKING_SERVER_URI }}
BENCHMARK_RESULTS_CLEAR: ${{ vars.BENCHMARK_RESULTS_CLEAR }}
GH_CTX_REF_NAME: ${{ github.ref_name }}
GH_CTX_SHA: ${{ github.sha }}
run: tox -vv -e tests-${{ inputs.toxenv-task }}-${{ inputs.toxenv-pyver }}-${{ inputs.toxenv-ptver }} -- ${{ inputs.tests-dir }}
- name: Upload test results
uses: actions/upload-artifact@v3
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ def manage_tm_config_for_testing():

@pytest.fixture(autouse=True, scope="session")
def init_mlflow_tracking():
uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI", "http://localhost:8080")
mlflow.set_tracking_uri(uri=uri)
uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI")
if uri is not None:
mlflow.set_tracking_uri(uri=uri)

yield


@pytest.fixture(scope="session")
def fxt_mlflow_client():
uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI", "http://localhost:8080")
return mlflow.MlflowClient(uri)
uri = os.environ.get("MLFLOW_TRACKING_SERVER_URI")
return mlflow.MlflowClient(uri) if uri is not None else None
16 changes: 12 additions & 4 deletions tests/perf/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import re
import shutil
import subprocess
from datetime import datetime
from pathlib import Path
from typing import Dict, List
Expand Down Expand Up @@ -90,14 +89,16 @@ def fxt_output_root(request: pytest.FixtureRequest, tmp_path_factory: pytest.Tem
if output_root is None:
output_root = tmp_path_factory.mktemp("otx-benchmark")
data_str = datetime.now().strftime("%Y%m%d-%H%M%S")
commit_str = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("ascii").strip()
return Path(output_root) / (data_str + "-" + commit_str)
commit_str = os.environ.get("GH_CTX_SHA", "unknown")
print(f"Git SHA configured with {commit_str}")
return Path(output_root) / (data_str + "-" + commit_str[:7])


@pytest.fixture(scope="session")
def fxt_working_branch() -> str:
"""Git branch name for the current HEAD."""
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("ascii").strip()
branch = os.environ.get("GH_CTX_REF_NAME", "unknown")
print(f"working branch name fixture configured with {branch}")
return branch


Expand Down Expand Up @@ -241,6 +242,13 @@ def fxt_benchmark_summary(request: pytest.FixtureRequest, fxt_output_root: Path,
all_results.to_csv(output_path, index=False)
print(f" -> Saved to {output_path}.")

if fxt_mlflow_client is None:
print(
"Tracking server is not configured. for logging results, "
"set 'MLFLOW_TRACKING_SERVER_URI' environment variable to server URI ."
)
return

# logging to the mlflow for 'develop' or 'releases/x.x.x' branch
if fxt_working_branch == "develop" or bool(re.match("^releases/[0-9]+\.[0-9]+\.[0-9]+$", fxt_working_branch)):
version = VERSION
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ passenv =
{[testenv]passenv}
MLFLOW_TRACKING_SERVER_URI
BENCHMARK_RESULTS_CLEAR
GH_CTX_REF_NAME
GH_CTX_SHA
commands =
python -m pytest -ra --showlocals --csv={toxworkdir}/{envname}.csv {posargs:tests/integration/{[testenv]test_dir}}

Expand Down