Skip to content

feat(monitoring): wire AwsCostCollectorService into cost scheduler#1085

Open
sadiqabubakar826-del wants to merge 1 commit into
rinafcode:mainfrom
sadiqabubakar826-del:feat/wire-aws-cost-collector-into-scheduler
Open

feat(monitoring): wire AwsCostCollectorService into cost scheduler#1085
sadiqabubakar826-del wants to merge 1 commit into
rinafcode:mainfrom
sadiqabubakar826-del:feat/wire-aws-cost-collector-into-scheduler

Conversation

@sadiqabubakar826-del

Copy link
Copy Markdown
Contributor

Wire real AWS Cost Explorer data into the hourly cost scheduler

Previously, CostSchedulerService published a hard-coded 0 as the hourly cost metric on every
cycle, making any capacity planning or cost alerting built on that metric reason from a
constant rather than real data. AwsCostCollectorService already existed and could fetch live
Cost Explorer data, but was never connected to the scheduler.

───────────────────────────────────────────────────────────────────────────────────────────────

Changes

AwsCostCollectorService

  • Removed the duplicate @Cron decorator and CostTrackingService injection — the service is now
    a pure data-fetcher.
  • collectHourlyCost() returns HourlyCostResult | null ({ amount, billingPeriod }) instead of
    writing the metric itself. Returns null on any failure or when the collector is disabled, so
    the caller can decide how to handle it.
  • billingPeriod is formatted as YYYY-MM-DD/YYYY-MM-DD, matching Cost Explorer's TimePeriod
    convention and making the reporting delay explicit.

CostTrackingService

  • recordHourlyCost(amount, billingPeriod?) now accepts an optional billing period.
  • The infrastructure_hourly_cost_usd gauge carries a billing_period label so dashboards and
    alert rules can see which window a data point describes.

CostSchedulerService

  • Injects AwsCostCollectorService and drives the collection cycle.
  • On success: records the real amount and billing period via CostTrackingService.
  • On failure (null result): leaves the previous gauge value unchanged and increments the
    cost_collection_failures_total counter — failures are visible without publishing a fabricated
    value.
  • No placeholder, no TODO.

cost-scheduler.service.spec.ts (new)

  • 8 tests covering: delegation to the collector, amount and billing period forwarding, failure
    counter incremented on each failed cycle, no metric write on failure, and no hard-coded
    placeholder published.

───────────────────────────────────────────────────────────────────────────────────────────────

Testing

pnpm test --testPathPattern="cost-scheduler" # 8/8 pass
pnpm test --testPathPattern="monitoring" # 61/61 pass (no regressions)
pnpm typecheck # clean

───────────────────────────────────────────────────────────────────────────────────────────────

Acceptance checklist

  • Cost metric sourced from Cost Explorer, not a constant
  • Collector failure leaves previous value and increments cost_collection_failures_total
  • Metric labelled with the billing period it describes
  • No placeholder or TODO remains in the scheduler

closes #1037

- Replace hardcoded placeholder (0) with real Cost Explorer data
- CostSchedulerService now delegates to AwsCostCollectorService.collectHourlyCost()
- On collector failure, skip metric update and increment cost_collection_failures_total counter
- Label infrastructure_hourly_cost_usd gauge with billing_period from Cost Explorer response
- Remove duplicate @Cron from AwsCostCollectorService (scheduler drives the cycle)
- Add billing_period label to CostTrackingService.recordHourlyCost()
- Add 8 tests covering success path, failure path, and no-placeholder hygiene
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@sadiqabubakar826-del Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the placeholder cloud billing figure in the cost monitoring scheduler

2 participants