Skip to content

Comments

Migrate to using cloudcost-exporter metrics#30

Merged
Pokom merged 4 commits intomainfrom
cloudcost-exporter-metrics-exp
Feb 24, 2025
Merged

Migrate to using cloudcost-exporter metrics#30
Pokom merged 4 commits intomainfrom
cloudcost-exporter-metrics-exp

Conversation

@Pokom
Copy link
Contributor

@Pokom Pokom commented Feb 5, 2025

First attempt at trying to migrate to using cloudcost-exporter metrics. Took a naive approach of adding a config to toggle cloudcost-exporter metrics. Added two new queries for cloudcost-exporter to get the avg cost of

  • Cpu cores
  • Memory (GiB)

Discovered that cloudcost-exporter does not implement cost of persistent storage(see grafana/cloudcost-exporter#236), so I'll pick that up in a separate PR.

To test out, follow the setup guide and run the estimator command:

go run ./cmd/estimator/ \
  -from $PWD/pkg/costmodel/testdata/resource/Deployment.json \
  -to $PWD/pkg/costmodel/testdata/resource/Deployment-more-requests.json \
  -http.config.file ~/.config/dev.yaml \
  -prometheus.address $PROMETHEUS_ADDRESS \
   dev-us-east-0

Since this releases the change behind a flag, we can merge this whenever we're comfortable and enable it when we're comfortable.

First attempt at trying to migrate to using cloudcost-exporter metrics.
Took a naive approach of adding a config to toggle cloudcost-exporter metrics.
Added three new queries for cloudcost-exporter to get the avg cost of
- Cpu cores
- Memory (GiB)
- Persistent Volumes

Discovered that cloudcost-exporter does not implement cost of persistent storage(see grafana/cloudcost-exporter#236).

To test out, follow the setup guide and run the estimator command:

```shell
go run ./cmd/estimator/ \
  -from $PWD/pkg/costmodel/testdata/resource/Deployment.json \
  -to $PWD/pkg/costmodel/testdata/resource/Deployment-more-requests.json \
  -http.config.file ~/.config/dev.yaml \
  -prometheus.address $PROMETHEUS_ADDRESS \
   dev-us-east-0

```

- relates #29
@Pokom Pokom requested a review from a team as a code owner February 5, 2025 02:42
Comment on lines +239 to +249
// Handles the case for cloudcost exporter metrics where `price_tier` is the label for spot/non-spot
// TODO: Delete after removing support for OpenCost
switch sample.Metric["price_tier"] {
case "ondemand":
cost.NonSpot = value
case "spot":
cost.Spot = value
default:
// This is when there is no spot/non-spot label
cost.Dollars = value
}
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 is really the heart of the change. The biggest difference between the queries is that the price_tier label is used to signify if the price is for an ondemand or spot instance.

@Pokom Pokom marked this pull request as draft February 5, 2025 02:49
@Pokom Pokom marked this pull request as ready for review February 5, 2025 17:57
Copy link
Contributor

@nikimanoledaki nikimanoledaki left a comment

Choose a reason for hiding this comment

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

Reviewed (LGTM!) & validated for both GKE & EKS after setting USE_CLOUD_COST_EXPORTER=true:

go run ./cmd/estimator/ \                            
  -from $PWD/pkg/costmodel/testdata/resource/Deployment.json \
  -to $PWD/pkg/costmodel/testdata/resource/Deployment-more-requests.json \
  -http.config.file ~/.config/grafana/dev2.yaml \
  -prometheus.address=$PROMETHEUS_ADDRESS \
dev-us-east-0
loading http config file: /Users/nikimanoledaki/.config/grafana/dev2.yaml
Cluster        Total Weekly Cost  Δ Weekly Cost  Total Monthly Cost  Δ Monthly Cost
<cost data>

🤞

@Pokom Pokom merged commit ea7b8f3 into main Feb 24, 2025
2 checks passed
@Pokom Pokom deleted the cloudcost-exporter-metrics-exp branch February 24, 2025 15:14
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.

3 participants