Skip to content

Commit

Permalink
Billing hail batch layout (#633)
Browse files Browse the repository at this point in the history
* Added simple Total Cost By Batch Page.

* Removing debug prints.

* Fixed autoselect day format.

* Fixing day format for autoselect (missing leading 0)

* Added first draft of billing page to show detail SKU per selected cost category over selected time periods (day, week, month or invoice month)

* Small fix for BillingCostByBatch page, disable search if searchBy is empty or < 6 chars.

* New: Billing API GET namespaces, added namespace to allowed fields for total cost.

* Implemented HorizontalStackedBarChart, updated Billing By Invoice Month page to enable toggle between chart and table view.

* ADD: Cost by Analysis page

* ADD: add start of Analysis grid

* ADD: add start of Analysis grid

* FIX: table fixes for the HailBatchGrid

* API: api changes to enable query of the raw table

* API: fixed and working with updated get_total_cost endpoint

* API: fix typing of get_total_cost (default return is now a list[dict] and can be converted in the layer/route to a specific output type

* API: add endpoint to get costs by batch_id

* API: done

* IN PROGRESS: modifying Cost By Analysis to use new endpoints

* IN PROGRESS: changes to Cost By Analysis, linking with backend API.

* IN PROGRESS: changes to Cost By Analysis, grid grouping by ar/batch/job.

* NEW: finalising Cost By Analysis page

* ADD: durations to Cost By Analysis page

---------

Co-authored-by: Milo Hyben <[email protected]>
  • Loading branch information
violetbrina and milo-hyben authored Dec 21, 2023
1 parent d97b5b7 commit 80dd3c1
Show file tree
Hide file tree
Showing 15 changed files with 1,198 additions and 103 deletions.
35 changes: 34 additions & 1 deletion api/routes/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from models.models.billing import (
BillingColumn,
BillingCostBudgetRecord,
BillingHailBatchCostRecord,
BillingQueryModel,
BillingRowRecord,
BillingTotalCostQueryModel,
Expand Down Expand Up @@ -297,6 +298,38 @@ async def query_billing(
return records


@router.get(
'/cost-by-ar-guid/{ar_guid}',
response_model=BillingHailBatchCostRecord,
operation_id='costByArGuid',
)
@alru_cache(maxsize=10, ttl=BILLING_CACHE_RESPONSE_TTL)
async def get_cost_by_ar_guid(
author: str = get_author,
ar_guid: str = None,
) -> BillingHailBatchCostRecord:
"""Get Hail Batch costs by AR GUID"""
billing_layer = initialise_billing_layer(author)
records = await billing_layer.get_cost_by_ar_guid(ar_guid)
return records


@router.get(
'/cost-by-batch-id/{batch_id}',
response_model=BillingHailBatchCostRecord,
operation_id='costByBatchId',
)
@alru_cache(maxsize=10, ttl=BILLING_CACHE_RESPONSE_TTL)
async def get_cost_by_batch_id(
author: str = get_author,
batch_id: str = None,
) -> BillingHailBatchCostRecord:
"""Get Hail Batch costs by Batch ID"""
billing_layer = initialise_billing_layer(author)
records = await billing_layer.get_cost_by_batch_id(batch_id)
return records


@router.post(
'/total-cost',
response_model=list[BillingTotalCostRecord],
Expand Down Expand Up @@ -503,7 +536,7 @@ async def get_total_cost(
"""
billing_layer = initialise_billing_layer(author)
records = await billing_layer.get_total_cost(query)
return records
return [BillingTotalCostRecord.from_json(record) for record in records]


@router.get(
Expand Down
5 changes: 3 additions & 2 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
BQ_AGGREG_EXT_VIEW = os.getenv('SM_GCP_BQ_AGGREG_EXT_VIEW')
BQ_BUDGET_VIEW = os.getenv('SM_GCP_BQ_BUDGET_VIEW')
BQ_GCP_BILLING_VIEW = os.getenv('SM_GCP_BQ_BILLING_VIEW')
BQ_BATCHES_VIEW = os.getenv('SM_GCP_BQ_BATCHES_VIEW')

# This is to optimise BQ queries, DEV table has data only for Mar 2023
BQ_DAYS_BACK_OPTIMAL = 30 # Look back 30 days for optimal query
BILLING_CACHE_RESPONSE_TTL = 3600 # 1 Hour
BQ_DAYS_BACK_OPTIMAL = 30 # Look back 30 days for optimal query
BILLING_CACHE_RESPONSE_TTL = 3600 # 1 Hour


def get_default_user() -> str | None:
Expand Down
Loading

0 comments on commit 80dd3c1

Please sign in to comment.