Skip to content

Commit a9d05d3

Browse files
Add parameter idle (default true) which toggles includeIdle and idle query params to Allocation API (#164)
* Force includeIdle=true for Opencost Signed-off-by: Michael Dresser <[email protected]> * Include idle based on parameter Signed-off-by: Michael Dresser <[email protected]> * Rename idle param for ease Signed-off-by: Michael Dresser <[email protected]> --------- Signed-off-by: Michael Dresser <[email protected]>
1 parent f32996c commit a9d05d3

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

pkg/cmd/aggregatedcommandbuilder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func runAggregatedAllocationCommand(ko *utilities.KubeOptions, o AggregatedAlloc
7676
"window": o.window,
7777
"aggregate": strings.Join(aggregation, ","),
7878
"accumulate": "true",
79+
"includeIdle": fmt.Sprintf("%t", o.includeIdle),
80+
"idle": fmt.Sprintf("%t", o.includeIdle),
7981
"filterNamespaces": o.filterNamespace,
8082
},
8183
QueryBackendOptions: o.QueryBackendOptions,

pkg/cmd/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
type CostOptions struct {
1616
window string
1717
filterNamespace string
18+
includeIdle bool
1819

1920
isHistorical bool
2021

@@ -24,6 +25,7 @@ type CostOptions struct {
2425
func addCostOptionsFlags(cmd *cobra.Command, options *CostOptions) {
2526
cmd.Flags().StringVar(&options.window, "window", "1d", "The window of data to query. See https://github.com/kubecost/docs/blob/master/allocation.md#querying for a detailed explanation of what can be passed here.")
2627
cmd.Flags().BoolVar(&options.isHistorical, "historical", false, "show the total cost during the window instead of the projected monthly rate based on the data in the window")
28+
cmd.Flags().BoolVar(&options.includeIdle, "idle", true, "include the __idle__ cost row in the response")
2729

2830
query.AddQueryBackendOptionsFlags(cmd, &options.QueryBackendOptions)
2931
}

pkg/cmd/label.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ func runCostLabel(ko *utilities.KubeOptions, no *CostOptionsLabel) error {
8181
allocations, err := query.QueryAllocation(query.AllocationParameters{
8282
Ctx: context.Background(),
8383
QueryParams: map[string]string{
84-
"window": no.window,
85-
"aggregate": strings.Join(aggregation, ","),
86-
"accumulate": "true",
84+
"window": no.window,
85+
"aggregate": strings.Join(aggregation, ","),
86+
"accumulate": "true",
87+
"includeIdle": fmt.Sprintf("%t", no.includeIdle),
88+
"idle": fmt.Sprintf("%t", no.includeIdle),
8789
},
8890
QueryBackendOptions: no.QueryBackendOptions,
8991
})

pkg/cmd/tui.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ func runTUI(ko *utilities.KubeOptions, do display.AllocationDisplayOptions, qo q
278278
queriedAllocs, err := query.QueryAllocation(query.AllocationParameters{
279279
Ctx: queryContext,
280280
QueryParams: map[string]string{
281-
"window": windowOptions[windowIndex],
282-
"aggregate": strings.Join(aggregation, ","),
283-
"accumulate": "true",
281+
"window": windowOptions[windowIndex],
282+
"aggregate": strings.Join(aggregation, ","),
283+
"accumulate": "true",
284+
"includeIdle": "true",
284285
},
285286
QueryBackendOptions: qo,
286287
})

0 commit comments

Comments
 (0)