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(data-warehouse): add workload and savings report tables to cast ai (#118993)

Tom Owersb85576759482
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 a54f97b66486..b16eb992c6a4 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
@@ -2257,10 +2257,10 @@ Today (3): `cluster_cost_reports`, `cluster_savings_history`, `clusters`
Diffed against: <https://api.cast.ai/v1/spec/openapi.json>
-- [ ] `Workload cost report (GET /v1/cost-reports/clusters/{clusterId}/workload-costs)` — attribute Kubernetes spending to workloads, namespaces, and teams (high)
-- [ ] `Cluster savings report (GET /v1/cost-reports/clusters/{clusterId}/savings)` — measure realized savings from downscaling and spot instances, separately from estimated savings (high)
-- [ ] `Workload efficiency report (GET /v1/cost-reports/clusters/{clusterId}/workload-efficiency)` — identify workloads with excess CPU or memory allocation (medium)
-- [ ] `Workload data transfer costs (GET /v1/cost-reports/clusters/{clusterId}/datatransfer-costs)` — attribute network transfer spending to workloads and traffic destinations (medium)
+- [x] `Workload cost report (GET /v1/cost-reports/clusters/{clusterId}/workload-costs)` — attribute Kubernetes spending to workloads, namespaces, and teams (high)
+- [x] `Cluster savings report (GET /v1/cost-reports/clusters/{clusterId}/savings)` — measure realized savings from downscaling and spot instances, separately from estimated savings (high)
+- [x] `Workload efficiency report (GET /v1/cost-reports/clusters/{clusterId}/workload-efficiency)` — identify workloads with excess CPU or memory allocation (medium)
+- [x] `Workload data transfer costs (GET /v1/cost-reports/clusters/{clusterId}/datatransfer-costs)` — attribute network transfer spending to workloads and traffic destinations (medium)
- [ ] `Cluster resource usage (GET /v1/cost-reports/clusters/{clusterId}/resource-usage)` — compare resource consumption with cluster costs over time (medium)
- [ ] `Cluster nodes (GET /v1/kubernetes/external-clusters/{clusterId}/nodes)` — analyze node inventory, instance types, and capacity within each imported cluster (medium)
- [ ] `Workload event metrics (GET /v1/cost-reports/clusters/{clusterId}/workload-event-metrics)` — connect memory failures and workload events with optimization and cost changes (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/canonical_descriptions.py
index 6384cbaa06f8..aa425ca06d7a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/canonical_descriptions.py
@@ -87,4 +87,68 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"optimizedSpotOnly": "Estimated cost under a spot-only optimization strategy.",
},
},
+ "cluster_savings_reports": {
+ "description": (
+ "Realized savings for a cluster, bucketed by time interval and split into savings "
+ "from downscaling and savings from spot instances."
+ ),
+ "docs_url": "https://docs.cast.ai/docs/cost-reports",
+ "columns": {
+ "cluster_id": "Identifier of the cluster this savings entry belongs to.",
+ "timestamp": "Start of the time bucket this savings entry covers.",
+ "downscalingSavings": "Savings from downscaling the cluster in the time bucket.",
+ "spotSavings": "Savings from running on spot instances in the time bucket.",
+ },
+ },
+ "workload_cost_reports": {
+ "description": (
+ "Compute cost of each workload in a cluster over the sync's report window, with "
+ "daily cost metrics, workload labels, and a cost summary."
+ ),
+ "docs_url": "https://docs.cast.ai/docs/cost-reports",
+ "columns": {
+ "cluster_id": "Identifier of the cluster the workload runs in.",
+ "workloadName": "Name of the workload.",
+ "workloadType": "Type of the workload (e.g. Deployment, StatefulSet).",
+ "namespace": "Kubernetes namespace the workload is in.",
+ "costMetrics": "Daily cost, resource, and pod count metrics of the workload.",
+ "labels": "Labels of the workload, as name/value pairs.",
+ "summary": "Total and average cost of the workload over the report window.",
+ },
+ },
+ "workload_efficiency_reports": {
+ "description": (
+ "Requested, used, and wasted CPU and memory of each workload in a cluster over the "
+ "sync's report window, with the cost impact of the waste."
+ ),
+ "docs_url": "https://docs.cast.ai/docs/cost-reports",
+ "columns": {
+ "cluster_id": "Identifier of the cluster the workload runs in.",
+ "workloadName": "Name of the workload.",
+ "workloadType": "Type of the workload (e.g. Deployment, StatefulSet).",
+ "namespace": "Kubernetes namespace the workload is in.",
+ "requests": "CPU and memory GiB the workload requests.",
+ "usage": "CPU and memory GiB the workload uses.",
+ "waste": "CPU and memory GiB the workload requests but does not use.",
+ "costImpact": "Cost of the wasted resources, by on-demand, spot, and spot-fallback lifecycle.",
+ "totalCostImpact": "Total cost impact of the workload. Sum of cost impacts by lifecycle.",
+ },
+ },
+ "workload_data_transfer_costs": {
+ "description": (
+ "Network data transfer bytes and cost of each workload in a cluster over the sync's "
+ "report window, split by traffic type (internet, inter-region, inter-zone, intra-zone, cloud API)."
+ ),
+ "docs_url": "https://docs.cast.ai/docs/cost-reports",
+ "columns": {
+ "cluster_id": "Identifier of the cluster the workload runs in.",
+ "workloadName": "Name of the workload.",
+ "workloadType": "Type of the workload (e.g. Deployment, StatefulSet).",
+ "namespace": "Kubernetes namespace the workload is in.",
+ "egressMetrics": "Daily egress bytes and cost of the workload, by traffic type.",
+ "ingressMetrics": "Daily ingress bytes and cost of the workload, by traffic type.",
+ "totalCost": "Total data transfer cost of the workload over the report window.",
+ "totalBytes": "Total bytes the workload transferred over the report window.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/cast_ai.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/cast_ai.py
index 44ea44867ea6..6ce5af13a2b5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/cast_ai.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/cast_ai.py
@@ -6,7 +6,6 @@ from typing import Any, Optional, cast
from products.warehouse_sources.backend.temporal.data_imports.sources.cast_ai.settings import (
CASTAI_BASE_URL,
CASTAI_ENDPOINTS,
- COST_REPORT_STEP_SECONDS,
DEFAULT_LOOKBACK_DAYS,
CastAiEndpointConfig,
)
@@ -22,6 +21,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
build_dependent_resource,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ BasePaginator,
+ JSONResponseCursorPaginator,
SinglePagePaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
@@ -34,11 +35,15 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
[email protected](frozen=True)
class CastAiResumeConfig:
- # Opaque framework checkpoint (fan-out resume state for the two report endpoints; the
+ # Opaque framework checkpoint (fan-out resume state for the report endpoints; the
# "clusters" list has no pagination and is never resumed).
paginator_state: dict[str, Any]
+ # The report window of the run that saved the checkpoint. A resumed run reuses it, so the
+ # rows written before the restart and after it aggregate over the same period.
+ window_start: str | None = None
+ window_end: str | None = None
def _format_time_value(value: Any) -> str:
@@ -103,15 +108,13 @@ def get_resource(endpoint: str) -> EndpointResource:
}
-def _report_incremental_config_factory(start_param: str, end_param: str) -> Any:
- end_value = _now()
-
+def _report_incremental_config_factory(start_param: str, end_param: str, initial_value: str, end_value: str) -> Any:
def factory(field: str) -> IncrementalConfig:
return {
"cursor_path": field,
"start_param": start_param,
"end_param": end_param,
- "initial_value": _default_lookback_start(),
+ "initial_value": initial_value,
"end_value": end_value,
"convert": _format_time_value,
}
@@ -146,29 +149,42 @@ def cast_ai_source(
endpoint_config = CASTAI_ENDPOINTS[endpoint]
initial_paginator_state: Optional[dict[str, Any]] = None
+ resume_config: Optional[CastAiResumeConfig] = None
if resumable_source_manager.can_resume():
resume_config = resumable_source_manager.load_state()
if resume_config is not None:
initial_paginator_state = resume_config.paginator_state
+ window_start = (resume_config.window_start if resume_config else None) or _default_lookback_start()
+ window_end = (resume_config.window_end if resume_config else None) or _now()
+
def save_checkpoint(state: Optional[dict[str, Any]]) -> None:
# Only persist when there's somewhere to resume to; the Redis TTL handles cleanup.
if state:
- resumable_source_manager.save_state(CastAiResumeConfig(paginator_state=dict(state)))
+ resumable_source_manager.save_state(
+ CastAiResumeConfig(paginator_state=dict(state), window_start=window_start, window_end=window_end)
+ )
if endpoint_config.fanout:
- start_param, end_param = (
- ("startTime", "endTime") if endpoint == "cluster_cost_reports" else ("fromDate", "toDate")
- )
+ if endpoint_config.window_params is None:
+ raise ValueError(f"Fan-out endpoint '{endpoint}' must declare its report window params")
+ start_param, end_param = endpoint_config.window_params
# These reports require a time window on every request (full refresh included) so the
# literal defaults below are always present; when incremental sync is enabled the
# framework's incremental config overwrites them with the real last-synced watermark.
child_params_extra: dict[str, Any] = {
- start_param: _default_lookback_start(),
- end_param: _now(),
+ start_param: window_start,
+ end_param: window_end,
}
- if endpoint == "cluster_cost_reports":
- child_params_extra["stepSeconds"] = COST_REPORT_STEP_SECONDS
+ if endpoint_config.step_seconds is not None:
+ child_params_extra["stepSeconds"] = endpoint_config.step_seconds
+ child_paginator: BasePaginator = (
+ JSONResponseCursorPaginator(
+ cursor_path="nextCursor", cursor_param="page.cursor", raise_on_repeated_cursor=True
+ )
+ if endpoint_config.cursor_paginated
+ else SinglePagePaginator()
+ )
dependent_resource = cast(
Iterable[Any],
@@ -183,10 +199,12 @@ def cast_ai_source(
db_incremental_field_last_value=db_incremental_field_last_value,
should_use_incremental_field=should_use_incremental_field,
incremental_field=incremental_field,
- incremental_config_factory=_report_incremental_config_factory(start_param, end_param),
+ incremental_config_factory=_report_incremental_config_factory(
+ start_param, end_param, window_start, window_end
+ ),
page_size_param=None,
parent_endpoint_extra={"paginator": SinglePagePaginator(), "data_selector": "items"},
- child_endpoint_extra={"paginator": SinglePagePaginator(), "data_selector": "items"},
+ child_endpoint_extra={"paginator": child_paginator, "data_selector": "items"},
child_params_extra=child_params_extra,
resume_hook=save_checkpoint,
initial_paginator_state=initial_paginator_state,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/settings.py
index 21385d44a80b..f46ce94bf50f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/settings.py
@@ -18,6 +18,10 @@ DEFAULT_LOOKBACK_DAYS = 30
# is our own choice, not a vendor default.
COST_REPORT_STEP_SECONDS = 3600
+# Workload reports return one row per workload with the per-step metrics nested inside it, so a
+# daily step keeps each row's nested array to ~30 entries over the default window.
+WORKLOAD_REPORT_STEP_SECONDS = 86400
+
TIMESTAMP_INCREMENTAL: IncrementalField = {
"label": "timestamp",
"type": IncrementalFieldType.DateTime,
@@ -33,19 +37,38 @@ CREATED_AT_INCREMENTAL: IncrementalField = {
}
-@dataclass
+@dataclass(frozen=False)
class CastAiEndpointConfig:
name: str
path: str
incremental_fields: list[IncrementalField] = field(default_factory=list)
default_incremental_field: str | None = None
partition_key: str | None = None
- # Unused: every endpoint here is an unpaginated single-response report/list, so callers
- # always pass page_size_param=None. Kept only to satisfy the shared fan-out helper's protocol.
+ # Unused: no endpoint documents a page size limit, so callers always pass page_size_param=None
+ # and let the server pick. Kept only to satisfy the shared fan-out helper's protocol.
page_size: int = 0
sort_mode: Literal["asc", "desc"] = "asc"
primary_key: str | list[str] = "id"
fanout: DependentEndpointConfig | None = None
+ # Required report window params, as (start, end).
+ window_params: tuple[str, str] | None = None
+ step_seconds: int | None = None
+ # Workload reports page with `page.cursor` and return the next cursor as `nextCursor`.
+ cursor_paginated: bool = False
+
+
+def _cluster_fanout() -> DependentEndpointConfig:
+ return DependentEndpointConfig(
+ parent_name="clusters",
+ resolve_param="clusterId",
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": "cluster_id"},
+ )
+
+
+# Workload names are only unique within a namespace and workload type in one cluster.
+WORKLOAD_PRIMARY_KEY = ["cluster_id", "namespace", "workloadType", "workloadName"]
CASTAI_ENDPOINTS: dict[str, CastAiEndpointConfig] = {
@@ -66,13 +89,9 @@ CASTAI_ENDPOINTS: dict[str, CastAiEndpointConfig] = {
# The row identifier is only unique within a cluster (one entry per time bucket), and
# this table aggregates every cluster, so the cluster id is part of the key.
primary_key=["cluster_id", "timestamp"],
- fanout=DependentEndpointConfig(
- parent_name="clusters",
- resolve_param="clusterId",
- resolve_field="id",
- include_from_parent=["id"],
- parent_field_renames={"id": "cluster_id"},
- ),
+ fanout=_cluster_fanout(),
+ window_params=("startTime", "endTime"),
+ step_seconds=COST_REPORT_STEP_SECONDS,
),
"cluster_savings_history": CastAiEndpointConfig(
name="cluster_savings_history",
@@ -81,13 +100,47 @@ CASTAI_ENDPOINTS: dict[str, CastAiEndpointConfig] = {
default_incremental_field="createdAt",
partition_key="createdAt",
primary_key=["cluster_id", "createdAt"],
- fanout=DependentEndpointConfig(
- parent_name="clusters",
- resolve_param="clusterId",
- resolve_field="id",
- include_from_parent=["id"],
- parent_field_renames={"id": "cluster_id"},
- ),
+ fanout=_cluster_fanout(),
+ window_params=("fromDate", "toDate"),
+ ),
+ "cluster_savings_reports": CastAiEndpointConfig(
+ name="cluster_savings_reports",
+ path="/v1/cost-reports/clusters/{clusterId}/savings",
+ incremental_fields=[TIMESTAMP_INCREMENTAL],
+ default_incremental_field="timestamp",
+ partition_key="timestamp",
+ primary_key=["cluster_id", "timestamp"],
+ fanout=_cluster_fanout(),
+ window_params=("startTime", "endTime"),
+ step_seconds=COST_REPORT_STEP_SECONDS,
+ ),
+ # The workload reports aggregate each workload over the requested window and carry no
+ # row-level timestamp, so they are full refresh over the default lookback window.
+ "workload_cost_reports": CastAiEndpointConfig(
+ name="workload_cost_reports",
+ path="/v1/cost-reports/clusters/{clusterId}/workload-costs",
+ primary_key=WORKLOAD_PRIMARY_KEY,
+ fanout=_cluster_fanout(),
+ window_params=("startTime", "endTime"),
+ step_seconds=WORKLOAD_REPORT_STEP_SECONDS,
+ cursor_paginated=True,
+ ),
+ "workload_efficiency_reports": CastAiEndpointConfig(
+ name="workload_efficiency_reports",
+ path="/v1/cost-reports/clusters/{clusterId}/workload-efficiency",
+ primary_key=WORKLOAD_PRIMARY_KEY,
+ fanout=_cluster_fanout(),
+ window_params=("startTime", "endTime"),
+ cursor_paginated=True,
+ ),
+ "workload_data_transfer_costs": CastAiEndpointConfig(
+ name="workload_data_transfer_costs",
+ path="/v1/cost-reports/clusters/{clusterId}/datatransfer-costs",
+ primary_key=WORKLOAD_PRIMARY_KEY,
+ fanout=_cluster_fanout(),
+ window_params=("startTime", "endTime"),
+ step_seconds=WORKLOAD_REPORT_STEP_SECONDS,
+ cursor_paginated=True,
),
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/tests/test_cast_ai.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/tests/test_cast_ai.py
index e0c5094476e2..50ef1c0756dd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/tests/test_cast_ai.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cast_ai/tests/test_cast_ai.py
@@ -1,5 +1,4 @@
from datetime import UTC, datetime
-from typing import cast
from unittest.mock import Mock, patch
@@ -14,7 +13,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.cast_ai.ca
get_resource,
validate_credentials,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.cast_ai.settings import COST_REPORT_STEP_SECONDS
+from products.warehouse_sources.backend.temporal.data_imports.sources.cast_ai.settings import (
+ COST_REPORT_STEP_SECONDS,
+ WORKLOAD_PRIMARY_KEY,
+ WORKLOAD_REPORT_STEP_SECONDS,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.cast_ai.source import CastAiSource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.testing import (
ScriptedResponse,
@@ -46,22 +49,17 @@ class TestCastAiDateFormatting:
class TestCastAiIncrementalConfigFactory:
def test_produces_start_and_end_params(self) -> None:
- factory = _report_incremental_config_factory("startTime", "endTime")
+ factory = _report_incremental_config_factory(
+ "startTime", "endTime", "2026-02-01T00:00:00Z", "2026-03-01T00:00:00Z"
+ )
config = factory("timestamp")
assert config["cursor_path"] == "timestamp"
assert config["start_param"] == "startTime"
assert config["end_param"] == "endTime"
+ assert config["initial_value"] == "2026-02-01T00:00:00Z"
+ assert config["end_value"] == "2026-03-01T00:00:00Z"
assert config["convert"] is _format_time_value
- # initial_value/end_value are RFC 3339 strings usable as literal query params.
- datetime.strptime(cast(str, config["initial_value"]), "%Y-%m-%dT%H:%M:%SZ")
- datetime.strptime(cast(str, config["end_value"]), "%Y-%m-%dT%H:%M:%SZ")
-
- def test_end_value_is_stable_across_calls(self) -> None:
- # Both report endpoints must request the same "now" snapshot within one sync, so the
- # value is captured once at factory-creation time, not per field.
- factory = _report_incremental_config_factory("fromDate", "toDate")
- assert factory("createdAt")["end_value"] == factory("timestamp")["end_value"]
class TestCastAiGetResource:
@@ -117,7 +115,8 @@ class TestCastAiSourceTopLevel:
resume_hook = mock_rest_api_resource.call_args.kwargs["resume_hook"]
resume_hook({"offset": 1})
- manager.save_state.assert_called_once_with(CastAiResumeConfig(paginator_state={"offset": 1}))
+ manager.save_state.assert_called_once()
+ assert manager.save_state.call_args.args[0].paginator_state == {"offset": 1}
manager.save_state.reset_mock()
resume_hook(None)
@@ -164,29 +163,74 @@ class TestCastAiFanoutRowFormat:
assert result.response.primary_keys == ["cluster_id", "createdAt"]
+class TestCastAiWorkloadPagination:
+ @parameterized.expand(
+ [
+ ("workload_cost_reports",),
+ ("workload_efficiency_reports",),
+ ("workload_data_transfer_costs",),
+ ]
+ )
+ def test_walks_cursor_pages_per_cluster(self, endpoint: str) -> None:
+ workload = {"namespace": "default", "workloadType": "Deployment"}
+ result = SourceDriver(CastAiSource(), CastAiSourceConfig(api_key="key")).run(
+ endpoint,
+ [
+ ScriptedResponse(json={"items": [{"id": "cluster-1"}]}),
+ ScriptedResponse(json={"items": [{**workload, "workloadName": "api"}], "nextCursor": "page-2"}),
+ ScriptedResponse(json={"items": [{**workload, "workloadName": "worker"}], "nextCursor": ""}),
+ ],
+ )
+
+ assert result.raised is None
+ assert result.params("page.cursor") == [None, None, "page-2"]
+ # The report window is required on every page, not only the first.
+ assert result.requests[2].param("startTime") == result.requests[1].param("startTime") is not None
+ assert result.requests[2].param("endTime") == result.requests[1].param("endTime") is not None
+ # Every checkpoint carries the window its rows cover, so a resumed run requests the same one.
+ assert {(state.window_start, state.window_end) for state in result.saved_states} == {
+ (result.requests[1].param("startTime"), result.requests[1].param("endTime"))
+ }
+ assert result.rows == [
+ {**workload, "workloadName": "api", "cluster_id": "cluster-1"},
+ {**workload, "workloadName": "worker", "cluster_id": "cluster-1"},
+ ]
+ assert result.response is not None
+ assert result.response.primary_keys == WORKLOAD_PRIMARY_KEY
+
+
class TestCastAiFanoutWiring:
@parameterized.expand(
[
- ("cluster_cost_reports", "startTime", "endTime", True),
- ("cluster_savings_history", "fromDate", "toDate", False),
+ ("cluster_cost_reports", "cost", "startTime", "endTime", COST_REPORT_STEP_SECONDS),
+ ("cluster_savings_history", "estimated-savings-history", "fromDate", "toDate", None),
+ ("cluster_savings_reports", "savings", "startTime", "endTime", COST_REPORT_STEP_SECONDS),
+ ("workload_cost_reports", "workload-costs", "startTime", "endTime", WORKLOAD_REPORT_STEP_SECONDS),
+ ("workload_efficiency_reports", "workload-efficiency", "startTime", "endTime", None),
+ (
+ "workload_data_transfer_costs",
+ "datatransfer-costs",
+ "startTime",
+ "endTime",
+ WORKLOAD_REPORT_STEP_SECONDS,
+ ),
]
)
def test_fanout_wiring_per_endpoint(
- self, endpoint: str, start_param: str, end_param: str, expects_step_seconds: bool
+ self, endpoint: str, report: str, start_param: str, end_param: str, step_seconds: int | None
) -> None:
- child_path = (
- "/v1/cost-reports/clusters/{cluster_id}/cost"
- if endpoint == "cluster_cost_reports"
- else "/v1/cost-reports/clusters/{cluster_id}/estimated-savings-history"
- )
- cursor_field = "timestamp" if endpoint == "cluster_cost_reports" else "createdAt"
+ child_path = f"/v1/cost-reports/clusters/{{cluster_id}}/{report}"
result = SourceDriver(CastAiSource(), CastAiSourceConfig(api_key="key")).run(
endpoint,
[
ScriptedResponse(json={"items": [{"id": "cluster-1"}, {"id": "cluster-2"}]}),
- ScriptedResponse(json={"items": [{cursor_field: "2026-03-01T00:00:00Z"}]}),
+ ScriptedResponse(json={"items": [{"timestamp": "2026-03-01T00:00:00Z"}]}),
],
- resume_state=CastAiResumeConfig(paginator_state={"completed": [child_path.format(cluster_id="cluster-1")]}),
+ resume_state=CastAiResumeConfig(
+ paginator_state={"completed": [child_path.format(cluster_id="cluster-1")]},
+ window_start="2026-02-01T00:00:00Z",
+ window_end="2026-03-01T00:00:00Z",
+ ),
)
assert result.raised is None
@@ -195,14 +239,12 @@ class TestCastAiFanoutWiring:
child_path.format(cluster_id="cluster-2"),
]
assert result.params("limit") == [None, None]
- assert result.rows == [{cursor_field: "2026-03-01T00:00:00Z", "cluster_id": "cluster-2"}]
+ assert result.rows == [{"timestamp": "2026-03-01T00:00:00Z", "cluster_id": "cluster-2"}]
assert result.requests[0].param(start_param) is None
assert result.requests[0].param(end_param) is None
- assert result.requests[1].param(start_param) is not None
- assert result.requests[1].param(end_param) is not None
- assert (result.requests[1].param("stepSeconds") is not None) is expects_step_seconds
- if expects_step_seconds:
- assert result.requests[1].param("stepSeconds") == str(COST_REPORT_STEP_SECONDS)
+ assert result.requests[1].param(start_param) == "2026-02-01T00:00:00Z"
+ assert result.requests[1].param(end_param) == "2026-03-01T00:00:00Z"
+ assert result.requests[1].param("stepSeconds") == (str(step_seconds) if step_seconds else None)
assert result.saved_states == [
CastAiResumeConfig(
paginator_state={
@@ -212,7 +254,9 @@ class TestCastAiFanoutWiring:
],
"current": None,
"child_state": None,
- }
+ },
+ window_start="2026-02-01T00:00:00Z",
+ window_end="2026-03-01T00:00:00Z",
)
]