Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse_sources): add hetzner network members table (#113219)

Tom Owersf731105dbce3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index c25bc1851995..9274084a70b8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -4023,6 +4023,7 @@ Diffed against: <https://docs.hetzner.cloud/cloud.spec.json>
- [x] `GET /zones` — DNS zones, now part of the Cloud API and not exposed at all today (medium)
- [ ] `GET /zones/{id_or_name}/rrsets` — DNS records per zone — the actual queryable rows behind zones (medium)
- [x] `GET /load_balancers/{id}/metrics` — connections, throughput and requests per load balancer for capacity analysis (medium)
+- [x] `GET /networks/{id}/members` — servers and load balancers attached to each network, with their private IP and attach status (medium)
Note: Note the payload's doc url (docs.hetzner.cloud) is an HTML docs site; the OpenAPI 3.1 spec lives at https://docs.hetzner.cloud/cloud.spec.json (docs.hetzner.cloud/spec.json 404s). Coverage of the plain list collections is essentially complete — every other GET collection in the spec is already synced.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/canonical_descriptions.py
index 3c58ce35456b..8080e602dd65 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/canonical_descriptions.py
@@ -272,4 +272,17 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"value": "Sample value: a count for open_connections, per second for the rates, bytes/s for bandwidth.",
},
},
+ "network_members": {
+ "description": "Servers and load balancers attached to each private network, with their IP inside the network.",
+ "docs_url": _API_DOCS,
+ "columns": {
+ "network_id": "ID of the network the resource is attached to.",
+ "type": "Type of the attached resource: server or load_balancer.",
+ "id": "ID of the attached server or load balancer.",
+ "ip": "IP address of the resource within the network.",
+ "alias_ips": "Additional IP addresses of the resource within the network.",
+ "subnet": "IP range of the subnet the resource is attached to, in CIDR notation.",
+ "status": "Status of the resource within the network: ok, attaching, detaching, updating or error.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/hetzner.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/hetzner.py
index d93f900fb3f7..341f44e163ae 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/hetzner.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/hetzner.py
@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.hetzner.settings import (
+ HETZNER_CHILD_ENDPOINTS,
HETZNER_ENDPOINTS,
HETZNER_METRICS_ENDPOINTS,
)
@@ -290,6 +291,56 @@ def hetzner_metrics_source(
)
+def hetzner_child_source(
+ api_token: str,
+ endpoint: str,
+ resumable_source_manager: ResumableSourceManager[HetznerResumeConfig],
+) -> SourceResponse:
+ config = HETZNER_CHILD_ENDPOINTS[endpoint]
+ parent = HETZNER_ENDPOINTS[config.parent]
+
+ def items() -> Iterator[list[dict[str, Any]]]:
+ client = RESTClient(
+ base_url=HETZNER_BASE_URL,
+ headers=_non_secret_headers(),
+ auth=BearerTokenAuth(api_token),
+ allow_redirects=False,
+ request_timeout=REQUEST_TIMEOUT,
+ )
+ parent_params = {"per_page": PAGE_SIZE, "sort": parent.sort}
+
+ for resources in client.paginate(
+ parent.path, params=parent_params, paginator=_list_paginator(), data_selector=parent.response_key
+ ):
+ for resource in resources:
+ yielded = False
+ try:
+ for page in client.paginate(
+ f"{parent.path}/{resource['id']}{config.path_suffix}",
+ params={"per_page": PAGE_SIZE, "sort": config.sort},
+ paginator=_list_paginator(),
+ data_selector=config.response_key,
+ ):
+ if page:
+ yielded = True
+ yield [{config.parent_id_column: resource["id"], **row} for row in page]
+ except HTTPError as e:
+ # The resource was deleted after the parent list was read.
+ if e.response is None or e.response.status_code != 404:
+ raise
+ if not yielded:
+ resumable_source_manager.safe_point()
+
+ return SourceResponse(
+ name=endpoint,
+ items=items,
+ primary_keys=config.primary_keys,
+ sort_mode="asc",
+ partition_count=1,
+ partition_size=1,
+ )
+
+
def validate_credentials(api_token: str) -> tuple[bool, str | None]:
"""One cheap authenticated probe to confirm the token is genuine. Hetzner project tokens grant
read access to every resource in the project (a read-only token still reads all of them), so
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/settings.py
index 99ad5877b2d9..a342ca06f680 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/settings.py
@@ -36,6 +36,20 @@ class HetznerMetricsEndpointConfig:
metric_types: str
+@dataclass(frozen=True)
+class HetznerChildEndpointConfig:
+ name: str
+ # Key into HETZNER_ENDPOINTS for the list whose resources the child list fans out over.
+ parent: str
+ # Column carrying the parent resource id on every child row.
+ parent_id_column: str
+ # Path under `{parent path}/{id}`, e.g. "/members".
+ path_suffix: str
+ response_key: str
+ primary_keys: list[str]
+ sort: str
+
+
# The Hetzner Cloud API exposes no server-side timestamp filter on any list endpoint (no
# `created_since` / `updated_after` / `id_gt`), so every table is full refresh only — there is no
# cursor that would make an "incremental" sync cheaper than re-reading every page. Actions are
@@ -189,7 +203,22 @@ HETZNER_METRICS_ENDPOINTS: dict[str, HetznerMetricsEndpointConfig] = {
),
}
-ENDPOINTS = (*HETZNER_ENDPOINTS.keys(), *HETZNER_METRICS_ENDPOINTS.keys())
+# Per-parent lists with no timestamps and no server-side filter, so full refresh only.
+HETZNER_CHILD_ENDPOINTS: dict[str, HetznerChildEndpointConfig] = {
+ # Servers and load balancers attached to each network. Their ids come from separate id spaces,
+ # and one resource can join several networks, so the key needs the network id and the type.
+ "network_members": HetznerChildEndpointConfig(
+ name="network_members",
+ parent="networks",
+ parent_id_column="network_id",
+ path_suffix="/members",
+ response_key="members",
+ primary_keys=["network_id", "type", "id"],
+ sort="id:asc",
+ ),
+}
+
+ENDPOINTS = (*HETZNER_ENDPOINTS.keys(), *HETZNER_METRICS_ENDPOINTS.keys(), *HETZNER_CHILD_ENDPOINTS.keys())
_TIMESTAMP_FIELD = IncrementalField(
label="timestamp",
@@ -200,5 +229,6 @@ _TIMESTAMP_FIELD = IncrementalField(
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
**{name: [] for name in HETZNER_ENDPOINTS},
+ **{name: [] for name in HETZNER_CHILD_ENDPOINTS},
**{name: [_TIMESTAMP_FIELD] for name in HETZNER_METRICS_ENDPOINTS},
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/source.py
index ea13b43ccce8..d77ed199cad8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/source.py
@@ -23,12 +23,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
)
from products.warehouse_sources.backend.temporal.data_imports.sources.hetzner.hetzner import (
HetznerResumeConfig,
+ hetzner_child_source,
hetzner_metrics_source,
hetzner_source,
validate_credentials as validate_hetzner_credentials,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.hetzner.settings import (
ENDPOINTS,
+ HETZNER_CHILD_ENDPOINTS,
HETZNER_METRICS_ENDPOINTS,
INCREMENTAL_FIELDS,
)
@@ -134,6 +136,12 @@ Create a token under **Security > API tokens** in the [Hetzner Cloud Console](ht
if inputs.should_use_incremental_field
else None,
)
+ if inputs.schema_name in HETZNER_CHILD_ENDPOINTS:
+ return hetzner_child_source(
+ api_token=config.api_token,
+ endpoint=inputs.schema_name,
+ resumable_source_manager=resumable_source_manager,
+ )
return hetzner_source(
api_token=config.api_token,
endpoint=inputs.schema_name,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner.py
index 99b54920df93..6a4f8d9ff2c3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner.py
@@ -17,6 +17,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.hetzner.he
HETZNER_BASE_URL,
METRICS_RETENTION,
HetznerResumeConfig,
+ hetzner_child_source,
hetzner_metrics_source,
hetzner_source,
validate_credentials,
@@ -350,6 +351,63 @@ class TestMetrics:
assert [(r["server_id"], r["value"]) for r in rows] == [(2, 1.0)]
+class TestNetworkMembers:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_pages_members_of_each_network_and_tags_rows_with_network_id(self, MockSession) -> None:
+ session = MockSession.return_value
+ member = {"type": "server", "ip": "10.0.1.2", "status": "ok", "alias_ips": [], "subnet": "10.0.1.0/24"}
+ sent = _wire_requests(
+ session,
+ [
+ _page([{"id": 1}, {"id": 2}], endpoint="networks"),
+ _page([{**member, "id": 7}], endpoint="members", last_page=2),
+ _page([{**member, "id": 8, "type": "load_balancer"}], endpoint="members", last_page=2),
+ _page([{**member, "id": 7}], endpoint="members"),
+ ],
+ )
+
+ rows = _rows(
+ hetzner_child_source(
+ api_token="token", endpoint="network_members", resumable_source_manager=_make_manager()
+ )
+ )
+
+ assert [(r["network_id"], r["type"], r["id"]) for r in rows] == [
+ (1, "server", 7),
+ (1, "load_balancer", 8),
+ (2, "server", 7),
+ ]
+ assert [url for url, _ in sent] == [
+ f"{HETZNER_BASE_URL}/networks",
+ f"{HETZNER_BASE_URL}/networks/1/members",
+ f"{HETZNER_BASE_URL}/networks/1/members",
+ f"{HETZNER_BASE_URL}/networks/2/members",
+ ]
+ assert sent[1][1] == {"per_page": 50, "sort": "id:asc", "page": 1}
+ assert sent[2][1]["page"] == 2
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_deleted_or_empty_network_is_skipped(self, MockSession) -> None:
+ session = MockSession.return_value
+ _wire_requests(
+ session,
+ [
+ _page([{"id": 1}, {"id": 2}, {"id": 3}], endpoint="networks"),
+ _json_response({"error": {"code": "not_found"}}, status=404, reason="Not Found"),
+ _page([], endpoint="members"),
+ _page([{"type": "server", "id": 9}], endpoint="members"),
+ ],
+ )
+ manager = _make_manager()
+
+ rows = _rows(
+ hetzner_child_source(api_token="token", endpoint="network_members", resumable_source_manager=manager)
+ )
+
+ assert rows == [{"network_id": 3, "type": "server", "id": 9}]
+ assert manager.safe_point.call_count == 2
+
+
class TestRetries:
@parameterized.expand([("rate_limited", 429), ("server_error", 503)])
@mock.patch(SLEEP_PATCH, lambda *_: None)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner_source.py
index 46334f411081..d52f0c04e572 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hetzner/tests/test_hetzner_source.py
@@ -80,6 +80,7 @@ class TestHetznerSource:
("list", "servers", ["id"]),
("server_metrics", "server_metrics", ["server_id", "metric", "timestamp"]),
("load_balancer_metrics", "load_balancer_metrics", ["load_balancer_id", "metric", "timestamp"]),
+ ("network_members", "network_members", ["network_id", "type", "id"]),
]
)
def test_source_for_pipeline_routes_schema(self, _name: str, schema_name: str, primary_keys: list[str]) -> None: