Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add table output to diff #2454

Merged
merged 2 commits into from
May 9, 2023
Merged

feat: add table output to diff #2454

merged 2 commits into from
May 9, 2023

Conversation

hugorut
Copy link
Contributor

@hugorut hugorut commented May 8, 2023

Adds summary table to diff output to improve understanding about cost diffs between projects. This table only shows projects with cost diffs. e.g:

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name                                                                 ┃ Previous   ┃ New        ┃ Diff         ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ infracost/infracost/cmd/infracost/testdata                           ┃ $0.00      ┃ $1,361     ┃ +$1,361      ┃
┃ infracost/infracost/cmd/infracost/testdata/terraform_v0.14_plan.json ┃ $41        ┃ $81        ┃ +$41 (+100%) ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
2 projects had no cost estimate changes, rerun with --show-skipped to see details

Zero diff projects are ignored to make this consistent with GitHub comments. This PR also:

  • removes the verbose "no cost estimate change" line to just be a count unless --show-skipped is included
  • reformats the errored projects to be above the table so that the table is explicitly the last output

@hugorut hugorut self-assigned this May 8, 2023
@hugorut hugorut requested review from aliscott and removed request for aliscott May 8, 2023 13:17
Adds summary table to diff output to improve understanding about cost diffs between projects. This table only shows porjects with cost diffs. Zero diff projects are ignored to make this consistent with GitHub comments. Along with the table this PR also:

* removes the verbose "no cost estimate change" line to just be a count unless --show-skipped is included
* reformats the errored projects to be above the table so that the table is explicitly the last output
@aliscott
Copy link
Member

aliscott commented May 8, 2023

@hugorut when I have a change in project with a long name the wrapping looks a bit odd. Should we:

  1. Middle truncate project names like we do with infracost comment?
  2. Or, add forced line wrapping for projects with long names.

@aliscott
Copy link
Member

aliscott commented May 8, 2023

Also, should we right-align the Previous and New columns like we do in the Infracost comment?

t.SetStyle(table.StyleBold)
t.Style().Format.Header = text.FormatDefault
t.AppendHeader(table.Row{
"Name",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Name",
"Project",

To keep it consistent with Infracost comment

s += fmt.Sprintf("\nThe following projects have no cost estimate changes: %s", strings.Join(noDiffProjects, ", "))
s += fmt.Sprintf("\nRun the following command to see their breakdown: %s", ui.PrimaryString("infracost breakdown --path=/path/to/code"))
s += "\n\n"
if hasDiffProjects && out.DiffTotalMonthlyCost != nil && out.DiffTotalMonthlyCost.GreaterThan(decimal.Zero) {
Copy link
Member

Choose a reason for hiding this comment

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

This hides any decreasing costs. I think this should check the absolute value of out.DiffTotalMonthlyCost

Are projects shown based on the same logic as the comment's showProject function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hides any decreasing costs. I think this should check the absolute value of out.DiffTotalMonthlyCost

👍

Are projects shown based on the same logic as the comment's showProject function?

No but i'll update so it does

@alikhajeh1
Copy link
Member

This is great! A few suggestions:

  • The colors are confusing as the diff output shows red for - but the table shows green for -. Also, red text might be harder to read. So maybe don't use colors for the summary table?
  • Add a sentence at the top of the table "Infracost estimate: monthly cost will increase by $X" in the same way we do for the PR comment as that's the ultimate summary line, but without the percentage (as we're going to get rid of the total % from that line). This also clarifies that the table columns are all showing monthly numbers.
  • Update the numbers in the table to the same logic as the rest of the CLI for decimals, i.e. don't show decimals unless the number is <1 (ROUND_COSTS_ABOVE in the dashboard, not sure what it's called in the CLI code)

@hugorut hugorut closed this May 9, 2023
@hugorut hugorut reopened this May 9, 2023
@hugorut
Copy link
Contributor Author

hugorut commented May 9, 2023

  1. Middle truncate project names like we do with infracost comment?

👍

Also, should we right-align the Previous and New columns like we do in the Infracost comment?

👍

* use `showProject` logic to hide/show projects
* truncate long project names
* add overview cost increase line
* remove colours from table
* align table columns
@hugorut
Copy link
Contributor Author

hugorut commented May 9, 2023

@aliscott I've made changes request by you and ali, table looks like this now:

──────────────────────────────────
Infracost estimate: monthly cost will increase by $41 (+100%) ↑

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Project                                                          ┃ Previous   ┃ New        ┃ Diff         ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ infracost/infracost/cmd/infraco...data/terraform_v0.14_plan.json ┃        $41 ┃        $81 ┃ +$41 (+100%) ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛

I've made the following changes:

  • Use showProject logic to hide/show projects
  • Truncated long project names
  • added overview cost increase line. This contains the % as this is what we use across the CLI and comment, so I kept it consistent so as not to confuse user. When we remove this from the other places (as @alikhajeh1 mentioned) we can remove from here.
  • Removed colours from table
  • Right aligned table columns

@alikhajeh1 the table already uses the rounding logic so I'm not sure if you've see something different?

Copy link
Member

@aliscott aliscott left a comment

Choose a reason for hiding this comment

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

❤️ it

@hugorut hugorut merged commit 344d310 into master May 9, 2023
10 checks passed
@alikhajeh1
Copy link
Member

@hugorut re the rounding, it only works on positive numbers, if the diff is <0 then we always seem to show decimals. Can we change that behavior so the absolute value is used to decide?

┃ test                               ┃    $24,773 ┃       $794 ┃ -$23,978.59 (-97%) ┃

@vdmgolub vdmgolub deleted the feat/diff-table branch May 9, 2023 14:20
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.

None yet

3 participants