Skip to content

Commit

Permalink
fix(dask): use correct REANA host port for Dask service URLs (#630)
Browse files Browse the repository at this point in the history
This PR is part of harmonizing the treatment of REANA_HOSTNAME
accross all REANA components. You can refer to other PRs below.

reanahub/reana#867
reanahub/reana-server#717

Closes reanahub/reana#865
  • Loading branch information
Alputer committed Jan 31, 2025
1 parent bb7b2ff commit 6819003
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
11 changes: 9 additions & 2 deletions reana_workflow_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from reana_db.models import JobStatus, RunStatus

from reana_workflow_controller.rest.utils import compose_base_reana_url
from reana_workflow_controller.version import __version__


Expand Down Expand Up @@ -277,8 +278,14 @@ def _parse_interactive_sessions_environments(env_var):
REANA_GITLAB_URL = "https://{}".format(REANA_GITLAB_HOST)
"""GitLab API URL"""

REANA_HOSTNAME = os.getenv("REANA_HOSTNAME", "CHANGE_ME")
"""REANA URL"""
REANA_HOSTNAME = os.getenv("REANA_HOSTNAME", "localhost")
"""REANA host name."""

REANA_HOSTPORT = os.getenv("REANA_HOSTPORT", "30443")
"""REANA host name port number."""

BASE_REANA_URL = compose_base_reana_url(REANA_HOSTNAME, REANA_HOSTPORT)
"""Base REANA URL."""

REANA_INGRESS_ANNOTATIONS = json.loads(os.getenv("REANA_INGRESS_ANNOTATIONS", "{}"))
"""REANA Ingress annotations defined by the administrator."""
Expand Down
4 changes: 2 additions & 2 deletions reana_workflow_controller/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
ALIVE_STATUSES,
PROGRESS_STATUSES,
REANA_GITLAB_URL,
REANA_HOSTNAME,
BASE_REANA_URL,
REANA_JOB_STATUS_CONSUMER_PREFETCH_COUNT,
)
from reana_workflow_controller.errors import REANAWorkflowControllerError
Expand Down Expand Up @@ -196,7 +196,7 @@ def _update_commit_status(workflow, status):
return
gitlab_access_token = gitlab_access_token_secret.value_str

target_url = f"https://{REANA_HOSTNAME}/api/workflows/{workflow.id_}/logs"
target_url = f"{BASE_REANA_URL}/api/workflows/{workflow.id_}/logs"
workflow_name = urlparse.quote_plus(workflow.git_repo)
system_name = "reana"
commit_status_url = (
Expand Down
16 changes: 16 additions & 0 deletions reana_workflow_controller/rest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ def is_uuid_v4(uuid_or_name: str) -> bool:
return uuid.hex == uuid_or_name.replace("-", "")


def compose_base_reana_url(hostname: str, hostport: int) -> str:
"""
Compose a REANA API base URL while omitting the default HTTPS port (443).
Args:
hostname (str): The REANA hostname.
hostport (int): The REANA host port.
Returns:
str: The full base URL.
"""
if hostport == 443:
return f"https://{hostname}"
return f"https://{hostname}:{hostport}"


def build_workflow_logs(workflow, steps=None, paginate=None):
"""Return the logs for all jobs of a workflow."""
from reana_workflow_controller.opensearch import build_opensearch_log_fetcher
Expand Down
4 changes: 2 additions & 2 deletions reana_workflow_controller/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
get_default_quota_resource,
)
from reana_workflow_controller.config import (
REANA_HOSTNAME,
BASE_REANA_URL,
DEFAULT_NAME_FOR_WORKFLOWS,
MAX_WORKFLOW_SHARING_MESSAGE_LENGTH,
)
Expand Down Expand Up @@ -631,7 +631,7 @@ def create_workflow(): # noqa
if requires_dask(workflow):
dask_service = Service(
name=get_dask_component_name(workflow.id_, "database_model_service"),
uri=f"https://{REANA_HOSTNAME}/{workflow_uuid}/dashboard/status",
uri=f"{BASE_REANA_URL}/{workflow_uuid}/dashboard/status",
type_=ServiceType.dask,
status=ServiceStatus.created,
)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
list_files_recursive_wildcard,
mv_files,
remove_files_recursive_wildcard,
compose_base_reana_url,
)


Expand Down Expand Up @@ -343,3 +344,17 @@ def test_mv_files(
assert target_path.exists()
if source_content:
assert target_path.read_text() == source_content


@pytest.mark.parametrize(
"hostname, hostport, expected_url",
[
("reana.cern.ch", 443, "https://reana.cern.ch"),
("reana.cern.ch", 30443, "https://reana.cern.ch:30443"),
("example.com", 443, "https://example.com"),
("example.com", 8080, "https://example.com:8080"),
],
)
def test_compose_reana_url(hostname, hostport, expected_url):
"""Test composing base reana url."""
assert compose_base_reana_url(hostname, hostport) == expected_url

0 comments on commit 6819003

Please sign in to comment.