Skip to content
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: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ endif
# The goals that start or recreate services, or hand a plain `docker compose` what they would, the only ones that ask docker compose for the CPU limits the collector reports as cores deployed
USAGE_GOALS := dev ci up infra apply apply-services print-compose-env
.tmp/profile.mk: FORCE
@python3 scripts/resolve_profile.py $(if $(KAFBAT_GATED),--unpublished kafbat) $(if $(HYPERDX_GATED),--unpublished hyperdx) $(RESOLVE_LOCAL_ARGS) $(if $(filter $(USAGE_GOALS),$(MAKECMDGOALS)),--usage)
@python3 scripts/resolve_profile.py $(if $(KAFBAT_GATED),--unpublished kafbat) $(RESOLVE_LOCAL_ARGS) $(if $(filter $(USAGE_GOALS),$(MAKECMDGOALS)),--usage)
ifneq ($(PROXY_TLS_START),)
@if grep -qx 'export DFE_AUTH_RESOLVED := true' $@; then echo "DFE_PROXY_TLS=true cannot start with the auth profile: oauth2-proxy serves no TLS here, so the https callbacks it registers with the IdP never answer. Set DFE_AUTH_ENABLED=false (or drop auth from the profile) to keep TLS. Set DFE_PROXY_TLS=false to keep the auth profile" >&2; exit 1; fi
endif
Expand Down
9 changes: 0 additions & 9 deletions scripts/resolve_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ class _AdminUi:
probe_url="http://kafka-ui:8080",
origin_var="",
),
"hyperdx": _AdminUi(
name="Search",
purpose="Logs, metrics and traces",
port_var="DFE_HYPERDX_APP_PORT",
default_port="8090",
# The proxy carrying dfe-hyperdx's host port, so one probe answers for both.
probe_url="http://dfe-hyperdx-proxy:8090",
origin_var="DFE_HYPERDX_APP_URL",
),
}

# Footprint components a profile may declare: yaml key -> (env override, default
Expand Down
101 changes: 26 additions & 75 deletions scripts/tests/test_admin_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
"purpose": "Topics, consumer groups and lag",
"probe_url": "http://kafka-ui:8080",
}
_HYPERDX = {
"name": "Search",
"purpose": "Logs, metrics and traces",
"probe_url": "http://dfe-hyperdx-proxy:8090",
}

# A profile per transport. The matrix sets each footprint env var it varies and the env var wins over the profile's key
_TRANSPORT_PROFILES = {"kafka": "slim-kafka", "grpc": "slim-grpc"}
Expand Down Expand Up @@ -89,10 +84,6 @@ def _kafbat(url: str) -> dict[str, str]:
return {**_KAFBAT, "url": url}


def _hyperdx(url: str) -> dict[str, str]:
return {**_HYPERDX, "url": url}


def _exports(*, path: Path) -> dict[str, str]:
"""Return the make exports one .tmp/profile.mk carries."""
values: dict[str, str] = {}
Expand Down Expand Up @@ -165,8 +156,8 @@ def _links(
@pytest.mark.parametrize("auth", [False, True], ids=["open", "auth"])
@pytest.mark.parametrize(
"unpublished",
[(), ("kafbat",), ("hyperdx",), ("hyperdx", "kafbat")],
ids=["all-published", "kafbat-gated", "hyperdx-gated", "infra-killed"],
[(), ("kafbat",)],
ids=["all-published", "kafbat-gated"],
)
@pytest.mark.parametrize("hyperdx", [False, True], ids=["no-hyperdx", "hyperdx"])
@pytest.mark.parametrize("kafbat", [False, True], ids=["no-kafbat", "kafbat"])
Expand Down Expand Up @@ -201,28 +192,21 @@ def test_a_ui_is_listed_exactly_where_it_runs_and_is_published(

browser = origin or "http://localhost"
want = []
# No broker, no Kafka UI: the grpc transport never starts Kafbat.
# No broker, no Kafka UI: the grpc transport never starts Kafbat. dfe-hyperdx is
# never listed, because dfe-ui frames it.
if transport == "kafka" and kafbat and "kafbat" not in unpublished:
want.append(_kafbat(f"{browser}:8081"))
if hyperdx and "hyperdx" not in unpublished:
want.append(_hyperdx(f"{browser}:8090"))
assert links == want
assert [_engine_refusals(entry) for entry in links] == [[] for _ in links]


@pytest.mark.parametrize(
("profile", "want"),
[
("slim-grpc", [_hyperdx("http://localhost:8090")]),
(
"slim-kafka",
[_kafbat("http://localhost:8081"), _hyperdx("http://localhost:8090")],
),
("single-grpc", [_hyperdx("http://localhost:8090")]),
(
"single-kafka",
[_kafbat("http://localhost:8081"), _hyperdx("http://localhost:8090")],
),
("slim-grpc", []),
("slim-kafka", [_kafbat("http://localhost:8081")]),
("single-grpc", []),
("single-kafka", [_kafbat("http://localhost:8081")]),
],
)
def test_every_profile_lists_what_its_footprint_runs(
Expand All @@ -235,7 +219,7 @@ def test_every_profile_lists_what_its_footprint_runs(
assert _links(monkeypatch=monkeypatch, tmp_path=tmp_path, profile=profile) == want


def test_behind_the_auth_profile_both_links_take_the_proxy_origin(
def test_behind_the_auth_profile_the_link_takes_the_proxy_origin(
dotenv: Path, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
"""The browser comes back on the proxy's callback, so that is where it is sent."""
Expand All @@ -250,30 +234,7 @@ def test_behind_the_auth_profile_both_links_take_the_proxy_origin(
**_AUTH_SETTINGS,
)

assert links == [
_kafbat(f"{_PROXY_ORIGIN}:8081"),
_hyperdx(f"{_PROXY_ORIGIN}:8090"),
]


def test_without_auth_hyperdx_takes_its_own_app_url(
dotenv: Path, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
"""With no proxy running, the proxy origin names nothing and the app URL wins."""
links = _links(
monkeypatch=monkeypatch,
tmp_path=tmp_path,
profile="slim-kafka",
DFE_HYPERDX_ENABLED="true",
DFE_EXTERNAL_ORIGIN=_ORIGIN,
DFE_OAUTH2_PROXY_EXTERNAL_ORIGIN=_PROXY_ORIGIN,
DFE_HYPERDX_APP_URL=_HYPERDX_APP_URL,
)

assert links == [
_kafbat(f"{_ORIGIN}:8081"),
_hyperdx(f"{_HYPERDX_APP_URL}:8090"),
]
assert links == [_kafbat(f"{_PROXY_ORIGIN}:8081")]


def test_a_moved_host_port_moves_the_link_and_not_the_probe(
Expand All @@ -284,13 +245,9 @@ def test_a_moved_host_port_moves_the_link_and_not_the_probe(
tmp_path=tmp_path,
profile="single-kafka",
KAFBAT_PORT="18081",
DFE_HYPERDX_APP_PORT="18090",
)

assert links == [
_kafbat("http://localhost:18081"),
_hyperdx("http://localhost:18090"),
]
assert links == [_kafbat("http://localhost:18081")]


def test_a_trailing_slash_on_the_origin_is_not_carried_into_the_url(
Expand All @@ -299,26 +256,26 @@ def test_a_trailing_slash_on_the_origin_is_not_carried_into_the_url(
links = _links(
monkeypatch=monkeypatch,
tmp_path=tmp_path,
profile="slim-grpc",
profile="slim-kafka",
DFE_EXTERNAL_ORIGIN=f"{_ORIGIN}/",
)

assert links == [_hyperdx(f"{_ORIGIN}:8090")]
assert links == [_kafbat(f"{_ORIGIN}:8081")]


def test_the_origin_is_read_from_dotenv_where_an_operator_sets_it(
dotenv: Path, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
"""Compose reads .env for the port bindings, so the links read the same file."""
dotenv.write_text(
f"DFE_EXTERNAL_ORIGIN={_ORIGIN}\nDFE_HYPERDX_APP_PORT=18090\n",
f"DFE_EXTERNAL_ORIGIN={_ORIGIN}\nKAFBAT_PORT=18081\n",
encoding="utf-8",
newline="\n",
)

links = _links(monkeypatch=monkeypatch, tmp_path=tmp_path, profile="slim-grpc")
links = _links(monkeypatch=monkeypatch, tmp_path=tmp_path, profile="slim-kafka")

assert links == [_hyperdx(f"{_ORIGIN}:18090")]
assert links == [_kafbat(f"{_ORIGIN}:18081")]


def test_an_unpublished_name_the_resolver_does_not_know_is_refused(
Expand All @@ -339,10 +296,10 @@ def test_an_unpublished_name_the_resolver_does_not_know_is_refused(
@pytest.mark.parametrize(
("entry", "refusal"),
[
({**_hyperdx("http://localhost:8090"), "icon": "x"}, "unknown field 'icon'"),
(_hyperdx("http://someone@localhost:8090"), "url carries credentials"),
(_hyperdx("localhost:8090"), "url is not an absolute http(s) URL"),
({**_hyperdx("http://localhost:8090"), "purpose": " "}, "purpose is missing"),
({**_kafbat("http://localhost:8081"), "icon": "x"}, "unknown field 'icon'"),
(_kafbat("http://someone@localhost:8081"), "url carries credentials"),
(_kafbat("localhost:8081"), "url is not an absolute http(s) URL"),
({**_kafbat("http://localhost:8081"), "purpose": " "}, "purpose is missing"),
],
)
def test_the_shape_check_refuses_what_the_engine_refuses(
Expand Down Expand Up @@ -449,31 +406,25 @@ def _through_make(*, cwd: Path, **settings: str) -> tuple[str, str]:
"DFE_BIND_SCOPE": "all",
"DFE_EXTERNAL_ORIGIN": _ORIGIN,
}
_BOTH_ON_ORIGIN = [_kafbat(f"{_ORIGIN}:8081"), _hyperdx(f"{_ORIGIN}:8090")]
_KAFBAT_ON_ORIGIN = [_kafbat(f"{_ORIGIN}:8081")]


@_needs_compose
@pytest.mark.parametrize(
("settings", "want"),
[
({}, [_kafbat("http://localhost:8081"), _hyperdx("http://localhost:8090")]),
(_SINGLE_ALL, _BOTH_ON_ORIGIN),
({}, [_kafbat("http://localhost:8081")]),
(_SINGLE_ALL, _KAFBAT_ON_ORIGIN),
({**_SINGLE_ALL, "DFE_INFRA_UIS_EXTERNAL": "false"}, []),
(
{**_SINGLE_ALL, "DFE_KAFBAT_UI_EXTERNAL": "false"},
[_hyperdx(f"{_ORIGIN}:8090")],
),
(
{**_SINGLE_ALL, "DFE_HYPERDX_UI_EXTERNAL": "false"},
[_kafbat(f"{_ORIGIN}:8081")],
),
({**_SINGLE_ALL, "DFE_KAFBAT_UI_EXTERNAL": "false"}, []),
({**_SINGLE_ALL, "DFE_HYPERDX_UI_EXTERNAL": "false"}, _KAFBAT_ON_ORIGIN),
(
{
**_SINGLE_ALL,
**_AUTH_SETTINGS,
"DFE_OAUTH2_PROXY_EXTERNAL_ORIGIN": _PROXY_ORIGIN,
},
[_kafbat(f"{_PROXY_ORIGIN}:8081"), _hyperdx(f"{_PROXY_ORIGIN}:8090")],
[_kafbat(f"{_PROXY_ORIGIN}:8081")],
),
({**_SINGLE_ALL, **_AUTH_SETTINGS, "DFE_INFRA_UIS_EXTERNAL": "false"}, []),
],
Expand Down
Loading