Skip to content

feat: add additional graphs in the cost insights view - #751

Open
nilushancosta wants to merge 1 commit into
openchoreo:mainfrom
nilushancosta:cost-insights
Open

feat: add additional graphs in the cost insights view#751
nilushancosta wants to merge 1 commit into
openchoreo:mainfrom
nilushancosta:cost-insights

Conversation

@nilushancosta

@nilushancosta nilushancosta commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Purpose

This PR extends the graphs tab in the cost insights view. So far there was only a stacked bar chart in it. This PR adds more graphs to display additional information to users at namespace, project and component levels
openchoreo/openchoreo#4381

Goals

Show more insights to users through additional graphs

Approach

  • Added the following graphs to the cost insights view
    • Spend forecast: Shows the spend up until now for a calendar month and the forecast at the current rate and if cost recommendations are applied
    • Cost vs efficiency: A scatter-plot which shows the cost vs efficiency. This helps users identify at a glance, the items which would provide the greatest savings
    • Line chart of cost over time
  • Added a curve to the stacked barchart as an overlay to show the cost after applying recommendations
  • Made legend items clickable in all charts so users can enable/disable items from charts
  • Added tooltips for the charts to explain what they show
  • Added unit tests

Screenshots

Please note that the cost values shown in these screenshots do not reflect the actual cost of running these components at the given CPU and memory requests in OpenChoreo. The costs have been manually inflated for testing purposes

Light theme
Screenshot 2026-08-07 at 14 17 00

Screenshot 2026-08-07 at 14 10 13

Dark theme
Screenshot 2026-08-07 at 14 17 18

Screenshot 2026-08-07 at 14 11 53

Overlay curve at the component level showing the cost after applying recommendations
Screenshot 2026-08-07 at 14 13 03

Summary by CodeRabbit

  • New Features
    • Added cost-efficiency, forecast divergence, and cost-over-time visualizations.
    • Added interactive chart legends, tooltips, projected savings overlays, and empty states.
    • Added chart titles with informational tooltips.
    • Added savings details to cost summaries and efficiency explanations.
    • Added separate Graphs view controls and time-series granularity selection.
  • Bug Fixes
    • Improved handling of missing forecast or cost data with clear empty-state messages.
  • Tests
    • Added coverage for chart rendering, legends, tooltips, forecasts, savings calculations, and empty states.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Changeset detected — the following file(s) will be released with this PR:

.changeset/cost-insights-graphs-dashboard.md

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@nilushancosta, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1bfeec47-a2c6-408e-8de6-994f46d5678b

📥 Commits

Reviewing files that changed from the base of the PR and between 5835c5f and ad41922.

📒 Files selected for processing (13)
  • .changeset/cost-insights-graphs-dashboard.md
  • plugins/openchoreo-observability/src/components/CostInsights/CostEfficiencyScatter.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraphs.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostLineChart.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/ForecastDivergenceChart.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/ForecastDivergenceChart.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/chartUtils.test.ts
  • plugins/openchoreo-observability/src/components/CostInsights/costAggregation.test.ts
  • plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts
  • plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.test.ts
  • plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.ts
📝 Walkthrough

Walkthrough

Cost Insights now fetches separate summary and graph data, calculates recommendation savings and forecasts, and renders forecast, efficiency, line, and composed charts through a new graph view.

Changes

Cost Insights data pipeline

Layer / File(s) Summary
Savings and forecast data pipeline
plugins/openchoreo-observability/src/components/CostInsights/types.ts, plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts, plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.ts, plugins/openchoreo-observability/src/components/CostInsights/*test*
Adds recommendation savings, forecast types, forecast calculations, separate series data, and related aggregation and fetching tests.

Chart foundation and visualizations

Layer / File(s) Summary
Shared chart foundation
plugins/openchoreo-observability/src/components/CostInsights/chartUtils.ts, plugins/openchoreo-observability/src/components/CostInsights/ChartTitle.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostLineChart.tsx, plugins/openchoreo-observability/src/components/CostInsights/*test*
Adds shared palettes, formatting helpers, chart titles, interactive legends, tooltips, and empty states.
Forecast, efficiency, and overlay charts
plugins/openchoreo-observability/src/components/CostInsights/ForecastDivergenceChart.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostEfficiencyScatter.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx, plugins/openchoreo-observability/src/components/CostInsights/*test*
Adds forecast projection lines, ranked efficiency bubbles, and composed cost charts with optional recommendation overlays.

Page integration

Layer / File(s) Summary
Graph page integration and supporting UI
plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraphs.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostInsightsFilters.tsx, plugins/openchoreo-observability/src/components/CostInsights/CostSummaryCards.tsx, plugins/openchoreo-observability/src/components/CostInsights/*test*
Composes the graph view, moves granularity selection into that view, simplifies filters, limits summary cards to table view, and adds efficiency guidance.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CostInsightsPage
  participant useCostInsights
  participant costAggregation
  participant CostInsightsGraphs
  CostInsightsPage->>useCostInsights: request cost insights
  useCostInsights->>costAggregation: provide costs, series, and recommendations
  costAggregation-->>useCostInsights: return summary, series, savings, and forecast
  useCostInsights-->>CostInsightsPage: return CostInsightsData
  CostInsightsPage->>CostInsightsGraphs: pass CostInsightsData and granularity
  CostInsightsGraphs->>CostInsightsGraphs: render forecast, efficiency, and cost charts
Loading

Possibly related PRs

Suggested reviewers: stefinie123

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the purpose, goals, approach, screenshots, and unit tests but omits most required template sections. Add the missing sections, including user stories, release note, documentation, training, certification, marketing, automation details, security checks, testing environment, and related items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding additional graphs to the Cost Insights view.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.test.tsx (1)

20-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for hiding the summary cards in graph view.

CostInsightsPage.tsx now renders CostSummaryCards only when view !== 'graph' (lines 282-286). No test covers this branch. Add a case that renders the page with view=graph and asserts the summary cards are absent while cost-graph is present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.test.tsx`
around lines 20 - 21, Add a test case in the CostInsightsPage test suite that
renders CostInsightsPage with view set to graph, asserts CostSummaryCards are
absent, and verifies the mocked cost-graph element is present. Reuse the
existing render setup and selectors from the suite.
plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx (1)

80-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the legend toggle state into a shared hook.

The same hidden state and toggle function exist in CostLineChart.tsx, CostEfficiencyScatter.tsx, and ForecastDivergenceChart.tsx. A shared useHiddenSeries hook in chartUtils (or a small hook module) removes the duplication and keeps the toggle semantics identical across the four charts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx`
around lines 80 - 88, The duplicated hidden-series state and toggle logic in
CostInsightsGraph.tsx, CostLineChart.tsx, CostEfficiencyScatter.tsx, and
ForecastDivergenceChart.tsx should be extracted into a shared useHiddenSeries
hook in chartUtils or a dedicated hook module. Update each chart to consume the
hook while preserving the existing Set-based state and toggle behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts`:
- Around line 380-383: Update the forecast calculation around baseline and
forkTotal so prior-month values from totalActual are excluded when the selected
window crosses a month boundary; derive the fork from current-month elapsed time
at rate, or skip the forecast until windowStart is within the current month. Add
a test covering a window that spans the month boundary.
- Around line 264-276: Update the aggregation around
recommendedTotalsByDimension and totalSaving to build current totals by
dimension, then sum Math.max(0, currentDimensionTotal -
recommendedDimensionTotal) only for dimensions present in the recommended totals
map. Do not use recSum > 0 as the availability check; preserve zero-cost
recommendations and exclude stale environments from claimed savings. Add
coverage for both zero-cost recommendations and stale environments.

In
`@plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx`:
- Around line 90-103: Update the data memo’s total calculation to exclude keys
marked hidden when summing seriesKeys, so the post-recommendation overlay
matches the visible stack. Include hidden in the memo dependency array and
preserve the existing behavior when no overlay is enabled.

In
`@plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.ts`:
- Around line 102-109: Update the isGraph branch in the cost-loading flow to
catch failures from the granular api.getCosts request and substitute an empty
CostItem series for that environment. Keep the surrounding accumulated cost,
previous cost, and recommendation data fulfilled so summary, forecast, and
scatter results remain available while the time-series chart reflects partial
data.

---

Nitpick comments:
In
`@plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx`:
- Around line 80-88: The duplicated hidden-series state and toggle logic in
CostInsightsGraph.tsx, CostLineChart.tsx, CostEfficiencyScatter.tsx, and
ForecastDivergenceChart.tsx should be extracted into a shared useHiddenSeries
hook in chartUtils or a dedicated hook module. Update each chart to consume the
hook while preserving the existing Set-based state and toggle behavior.

In
`@plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.test.tsx`:
- Around line 20-21: Add a test case in the CostInsightsPage test suite that
renders CostInsightsPage with view set to graph, asserts CostSummaryCards are
absent, and verifies the mocked cost-graph element is present. Reuse the
existing render setup and selectors from the suite.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6341c0a0-a107-42c8-a0fb-0ffaa0d827b2

📥 Commits

Reviewing files that changed from the base of the PR and between 67ba0da and 5835c5f.

📒 Files selected for processing (23)
  • plugins/openchoreo-observability/src/components/CostInsights/ChartTitle.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/ChartTitle.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostEfficiencyScatter.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostEfficiencyScatter.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsFilters.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsFilters.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraph.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsGraphs.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostInsightsPage.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostLineChart.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostLineChart.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostSummaryCards.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/CostSummaryCards.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/ForecastDivergenceChart.test.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/ForecastDivergenceChart.tsx
  • plugins/openchoreo-observability/src/components/CostInsights/chartUtils.ts
  • plugins/openchoreo-observability/src/components/CostInsights/costAggregation.test.ts
  • plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts
  • plugins/openchoreo-observability/src/components/CostInsights/types.ts
  • plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.test.ts
  • plugins/openchoreo-observability/src/components/CostInsights/useCostInsights.ts

Comment thread plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts Outdated
Comment thread plugins/openchoreo-observability/src/components/CostInsights/costAggregation.ts Outdated
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Signed-off-by: Nilushan Costa <nilushan@wso2.com>
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.

1 participant