@@ -16,23 +16,7 @@ import (
16
16
)
17
17
18
18
const (
19
- queryCostPerCPU = `
20
- avg by (spot) (node_cpu_hourly_cost{cluster="%s"}
21
- * on (cluster, node) group_left(spot)
22
- group by (cluster, node, spot) (
23
- label_replace(
24
- label_join(kubecost_node_is_spot == 1, "node", "", "exported_instance")
25
- ,"spot", "true", "", ""
26
- )
27
- or on (cluster, node)
28
- label_replace(
29
- label_join(kubecost_node_is_spot == 0, "node", "", "exported_instance")
30
- ,"spot", "false", "", ""
31
- )
32
- )
33
- )
34
- `
35
- cloudcostExporterQueryCostPerCpu = `
19
+ queryCostPerCpu = `
36
20
avg by (price_tier) (
37
21
cloudcost_aws_ec2_instance_cpu_usd_per_core_hour{cluster_name="%s"}
38
22
or
@@ -41,24 +25,7 @@ avg by (spot) (node_cpu_hourly_cost{cluster="%s"}
41
25
cloudcost_gcp_gke_instance_cpu_usd_per_core_hour{cluster_name="%s"}
42
26
)
43
27
`
44
-
45
28
queryMemoryCost = `
46
- avg by (spot) (node_ram_hourly_cost{cluster="%s"}
47
- * on (cluster, node) group_left(spot)
48
- group by (cluster, node, spot) (
49
- label_replace(
50
- label_join(kubecost_node_is_spot == 1, "node", "", "exported_instance")
51
- ,"spot", "true", "", ""
52
- )
53
- or on (cluster, node)
54
- label_replace(
55
- label_join(kubecost_node_is_spot == 0, "node", "", "exported_instance")
56
- ,"spot", "false", "", ""
57
- )
58
- )
59
- )
60
- `
61
- cloudcostExporterQueryMemoryCost = `
62
29
avg by (price_tier) (
63
30
cloudcost_aws_ec2_instance_memory_usd_per_gib_hour{cluster_name="%s"}
64
31
or
@@ -67,13 +34,9 @@ avg by (spot) (node_ram_hourly_cost{cluster="%s"}
67
34
cloudcost_gcp_gke_instance_memory_usd_per_gib_hour{cluster_name="%s"}
68
35
)
69
36
`
37
+
38
+ // TODO(@Pokom): update this query with azure's PVC's cost once https://github.com/grafana/cloudcost-exporter/issues/236 is merged in
70
39
queryPersistentVolumeCost = `
71
- avg_over_time(
72
- avg(
73
- pv_hourly_cost{cluster="%s"}
74
- )[24h:1m]
75
- )`
76
- cloudcostQueryPersistentVolumeCost = `
77
40
avg(
78
41
cloudcost_aws_ec2_persistent_volume_usd_per_hour{persistentvolume!="", state="in-use"}
79
42
/ on (persistentvolume) group_left() (
112
75
113
76
// Client is a client for the cost model.
114
77
type Client struct {
115
- client api.Client
116
- useCloudCostExporterMetrics bool
78
+ client api.Client
117
79
}
118
80
119
81
// Clients bundles the dev and prod client in one struct.
@@ -124,11 +86,10 @@ type Clients struct {
124
86
125
87
// ClientConfig is the configuration for the cost model client.
126
88
type ClientConfig struct {
127
- Address string
128
- HTTPConfigFile string
129
- Username string
130
- Password string
131
- UseCloudCostExporterMetrics bool
89
+ Address string
90
+ HTTPConfigFile string
91
+ Username string
92
+ Password string
132
93
}
133
94
134
95
// NewClient creates a new cost model client with the given configuration.
@@ -168,8 +129,7 @@ func NewClient(config *ClientConfig) (*Client, error) {
168
129
return nil , err
169
130
}
170
131
return & Client {
171
- client : client ,
172
- useCloudCostExporterMetrics : config .UseCloudCostExporterMetrics ,
132
+ client : client ,
173
133
}, nil
174
134
}
175
135
@@ -189,12 +149,7 @@ func NewClients(prodConfig, devConfig *ClientConfig) (*Clients, error) {
189
149
190
150
// GetCostPerCPU returns the average cost per CPU for a given cluster.
191
151
func (c * Client ) GetCostPerCPU (ctx context.Context , cluster string ) (Cost , error ) {
192
- query := fmt .Sprintf (queryCostPerCPU , cluster )
193
- // TODO: Remove this once we've removed support for OpenCost
194
- if c .useCloudCostExporterMetrics {
195
- slog .Info ("GetMemoryCost" , "cluster" , cluster , "message" , "using cloudcost exporter metrics" )
196
- query = fmt .Sprintf (cloudcostExporterQueryCostPerCpu , cluster , cluster , cluster )
197
- }
152
+ query := fmt .Sprintf (queryCostPerCpu , cluster , cluster , cluster )
198
153
results , err := c .query (ctx , query )
199
154
if err != nil {
200
155
return Cost {}, err
@@ -204,12 +159,7 @@ func (c *Client) GetCostPerCPU(ctx context.Context, cluster string) (Cost, error
204
159
205
160
// GetMemoryCost returns the cost per memory for a given cluster
206
161
func (c * Client ) GetMemoryCost (ctx context.Context , cluster string ) (Cost , error ) {
207
- query := fmt .Sprintf (queryMemoryCost , cluster )
208
- // TODO: Remove this once we've removed support for OpenCost
209
- if c .useCloudCostExporterMetrics {
210
- slog .Info ("GetMemoryCost" , "cluster" , cluster , "message" , "using cloudcost exporter metrics" )
211
- query = fmt .Sprintf (cloudcostExporterQueryMemoryCost , cluster , cluster , cluster )
212
- }
162
+ query := fmt .Sprintf (queryMemoryCost , cluster , cluster , cluster )
213
163
results , err := c .query (ctx , query )
214
164
if err != nil {
215
165
return Cost {}, err
@@ -235,11 +185,7 @@ func (c *Client) GetNodeCount(ctx context.Context, cluster string) (int, error)
235
185
236
186
// GetCostForPersistentVolume returns the average cost per persistent volume for a given cluster
237
187
func (c * Client ) GetCostForPersistentVolume (ctx context.Context , cluster string ) (Cost , error ) {
238
- query := fmt .Sprintf (queryPersistentVolumeCost , cluster )
239
- if c .useCloudCostExporterMetrics {
240
- slog .Info ("GetCostForPersistentVolume" , "cluster" , cluster , "message" , "using cloudcost exporter metrics" )
241
- query = fmt .Sprintf (cloudcostQueryPersistentVolumeCost , cluster , cluster , cluster , cluster )
242
- }
188
+ query := fmt .Sprintf (queryPersistentVolumeCost , cluster , cluster , cluster , cluster )
243
189
results , err := c .query (ctx , query )
244
190
if err != nil {
245
191
return Cost {}, err
0 commit comments