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

Add --show-total to show full cost alongside diff and --hide-diff to hide diff info #146

Merged
merged 7 commits into from
Mar 22, 2023

Conversation

michaelmdresser
Copy link
Contributor

@michaelmdresser michaelmdresser commented Mar 10, 2023

What does this PR change?

See release note.

How does this PR impact users? (This is the kind of thing that goes in release notes!)

  • Added --show-total and --hide-diff flags to kubectl cost predict. "Total" cost is the expected monthly cost of each workload if the new spec were applied to your cluster. "Diff" cost (the default) is the expected monthly cost change of applying each new spec to your cluster.

Links to Issues or ZD tickets this PR addresses or fixes

https://kubecost.atlassian.net/browse/CORE-113

How was this PR tested?

→ go run cmd/kubectl-cost/kubectl-cost.go predict -r michaelkc -f ./test/multi.yaml --show-total
 OBJECT                      QTY  Δ QTY  RESOURCE UNIT   COST PER UNIT      COST/MO     Δ COST/MO    % CHANGE 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 default deployment            9  +8.97  CPU cores           23.08 USD   207.68 USD   +206.99 USD  +29900.00% 
 nginx-deployment                                                                                             
                               6  +5.94  RAM GiB              3.09 USD    18.56 USD    +18.38 USD  +10140.00% 
                                                                                                              
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 kubecost deployment          15    +15  CPU millicores      0.023 USD     0.35 USD     +0.35 USD             
 kubecost-cost-analyzer                                                                                       
                               9     +9  RAM MiB            0.0030 USD     0.03 USD     +0.03 USD             
                                                                                                              
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 michaelkc deployment          1   -209  CPU millicores      0.023 USD     0.02 USD     -4.82 USD     -99.52% 
 michaelkc-cost-analyzer                                                                                      
                               1   -109  RAM MiB            0.0030 USD     0.00 USD     -0.33 USD     -99.09% 
                                                                                                              
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 default deployment           10    +10  CPU cores           23.08 USD   230.76 USD   +230.76 USD             
 nginx-deployment-2                                                                                           
                              35    +35  RAM GiB              3.09 USD   108.26 USD   +108.26 USD             
                                                                                                              
                               5     +5  GPUs               693.50 USD  3467.50 USD  +3467.50 USD             
                                                                                                              
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 default pod nginx-pod       350   +350  CPU millicores      0.023 USD     8.08 USD     +8.08 USD             
                             200   +200  RAM MiB            0.0030 USD     0.60 USD     +0.60 USD             
                            ──────────────────────────────────────────────────────────────────────────────────
                             350   +350  CPU millicores      0.023 USD     8.08 USD     +8.08 USD             
                             200   +200  RAM MiB            0.0030 USD     0.60 USD     +0.60 USD             
                               3     +3  GPUs               693.50 USD  2080.50 USD  +2080.50 USD             
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
 TOTAL MONTHLY COST                                                     6131.02 USD  +6124.97 USD             
→ go run cmd/kubectl-cost/kubectl-cost.go predict -r michaelkc -f ./test/multi.yaml --show-total --hide-diff
 OBJECT                      QTY  RESOURCE UNIT   COST PER UNIT      COST/MO 
─────────────────────────────────────────────────────────────────────────────
 default deployment            9  CPU cores           23.08 USD   207.68 USD 
 nginx-deployment                                                            
                               6  RAM GiB              3.09 USD    18.56 USD 
                                                                             
─────────────────────────────────────────────────────────────────────────────
 kubecost deployment          15  CPU millicores      0.023 USD     0.35 USD 
 kubecost-cost-analyzer                                                      
                               9  RAM MiB            0.0030 USD     0.03 USD 
                                                                             
─────────────────────────────────────────────────────────────────────────────
 michaelkc deployment          1  CPU millicores      0.023 USD     0.02 USD 
 michaelkc-cost-analyzer                                                     
                               1  RAM MiB            0.0030 USD     0.00 USD 
                                                                             
─────────────────────────────────────────────────────────────────────────────
 default deployment           10  CPU cores           23.08 USD   230.76 USD 
 nginx-deployment-2                                                          
                              35  RAM GiB              3.09 USD   108.26 USD 
                                                                             
                               5  GPUs               693.50 USD  3467.50 USD 
                                                                             
─────────────────────────────────────────────────────────────────────────────
 default pod nginx-pod       350  CPU millicores      0.023 USD     8.08 USD 
                             200  RAM MiB            0.0030 USD     0.60 USD 
                            ─────────────────────────────────────────────────
                             350  CPU millicores      0.023 USD     8.08 USD 
                             200  RAM MiB            0.0030 USD     0.60 USD 
                               3  GPUs               693.50 USD  2080.50 USD 
─────────────────────────────────────────────────────────────────────────────
 TOTAL MONTHLY COST                                              6131.02 USD 
→ go run cmd/kubectl-cost/kubectl-cost.go predict -r michaelkc -f ./test/multi.yaml --hide-diff           
Error: validate: validating display options: ShowTotal and HideDiff cannot be set such that no data will be shown
exit status 1

Have you made an update to documentation?

Yes, the help text.

@michaelmdresser michaelmdresser changed the title Add --show-new to show full cost alongside diff Add --show-new to show full cost alongside diff and --hide-diff to hide diff info Mar 10, 2023
Signed-off-by: Michael Dresser <[email protected]>
Signed-off-by: Michael Dresser <[email protected]>
@michaelmdresser michaelmdresser marked this pull request as ready for review March 21, 2023 20:47
@michaelmdresser michaelmdresser changed the title Add --show-new to show full cost alongside diff and --hide-diff to hide diff info Add --show-total to show full cost alongside diff and --hide-diff to hide diff info Mar 21, 2023
Copy link
Contributor

@nickcurie nickcurie left a comment

Choose a reason for hiding this comment

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

Looks like some of my work from #145 was nuked

Comment on lines 69 to 68
cmd.Flags().StringVar(&predictO.avgUsageWindow, "window-usage", "2d", "The window of Kubecost data to calculate historical average usage from, if historical data exists. See https://github.com/kubecost/docs/blob/master/allocation.md#querying for a detailed explanation of what can be passed here.")
cmd.Flags().StringVar(&predictO.resourceCostWindow, "window-cost", "7d offset 48h", "The window of Kubecost data to base resource costs on. Defaults with an offset of 48h to incorporate reconciled data if reconciliation is set up. See https://github.com/kubecost/docs/blob/master/allocation.md#querying for a detailed explanation of what can be passed here.")
cmd.Flags().StringVar(&predictO.window, "window", "2d", "The window of cost data to base resource costs on. See https://github.com/kubecost/docs/blob/master/allocation.md#querying for a detailed explanation of what can be passed here.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the intention to get rid of the split window parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! No! Good catch. I'll fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for the find.

pkg/cmd/predict.go Outdated Show resolved Hide resolved
Copy link
Contributor

@nickcurie nickcurie left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding back the split window

@michaelmdresser michaelmdresser merged commit 88dc6f0 into main Mar 22, 2023
@michaelmdresser michaelmdresser deleted the mmd/predict-add-show-new-flag branch March 22, 2023 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants