Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Change default provider to Ember #8

Merged
merged 5 commits into from
Jun 23, 2022
Merged

Change default provider to Ember #8

merged 5 commits into from
Jun 23, 2022

Conversation

rossf7
Copy link
Contributor

@rossf7 rossf7 commented Jun 22, 2022

Towards #7

Adds support for the Ember provider and makes it the default.

go run .

curl -s http://localhost:8000/metrics | grep grid | head
# HELP grid_intensity_carbon_actual Actual carbon intensity for the electricity grid in this region.
# TYPE grid_intensity_carbon_actual gauge
grid_intensity_carbon_actual{provider="ember-climate.org",region="ARG"} 365.292
grid_intensity_carbon_actual{provider="ember-climate.org",region="ARM"} 206.522
grid_intensity_carbon_actual{provider="ember-climate.org",region="AUS"} 526.876
grid_intensity_carbon_actual{provider="ember-climate.org",region="AUT"} 145.083
grid_intensity_carbon_actual{provider="ember-climate.org",region="AZE"} 536.585
grid_intensity_carbon_actual{provider="ember-climate.org",region="BDI"} 275.862
grid_intensity_carbon_actual{provider="ember-climate.org",region="BEL"} 156.063
grid_intensity_carbon_actual{provider="ember-climate.org",region="BGD"} 559.606

Or for a single country

GRID_INTENSITY_REGION=ESP go run .

curl -s http://localhost:8000/metrics | grep grid | head
# HELP grid_intensity_carbon_actual Actual carbon intensity for the electricity grid in this region.
# TYPE grid_intensity_carbon_actual gauge
grid_intensity_carbon_actual{provider="ember-climate.org",region="ESP"} 193.737

Or using the carbonintensity.org.uk provider

GRID_INTENSITY_PROVIDER=carbonintensity.org.uk go run .

curl -s http://localhost:8000/metrics | grep grid | head
# HELP grid_intensity_carbon_actual Actual carbon intensity for the electricity grid in this region.
# TYPE grid_intensity_carbon_actual gauge
grid_intensity_carbon_actual{provider="carbonintensity.org.uk",region="UK"} 197

@rossf7 rossf7 marked this pull request as ready for review June 22, 2022 13:52
@@ -25,7 +25,7 @@ jobs:
tags: thegreenwebfoundation/grid-intensity-exporter:integration-test
-
name: Create kubernetes Kind Cluster
uses: helm/kind-action@v1.1.0
uses: helm/kind-action@v1.3.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The integration test was failing.

This upgrades the Kubernetes version we test with from 1.19 to 1.24 and means the test will pass 🤷‍♂️

go.mod Outdated

require (
github.com/cenkalti/backoff/v4 v4.1.0
github.com/prometheus/client_golang v1.8.0
github.com/thegreenwebfoundation/grid-intensity-go v0.0.0-20201120145608-ed4c07f2660c
github.com/thegreenwebfoundation/grid-intensity-go v0.1.1-0.20220622112548-6b75d66a9da8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs thegreenwebfoundation/grid-intensity-go#24 to be merged and released

gridIntensityRegion: {{ .Values.gridIntensity.region | quote }}
{{ end }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Region is now optional so we need this extra templating.

main.go Outdated
if err != nil {
log.Printf("failed to get carbon intensity %#v", err)
}
if e.region == "" {
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 the new logic to return all countries if a region is not provided.

@rossf7 rossf7 requested a review from mrchrisadams June 22, 2022 14:04
@mrchrisadams
Copy link
Member

Hey Ross, given that:

  • electricity map doesn't support iterating through multiple countries any more
  • the carbonintensityku provider is focussed on the uk

Do you think it's better to just have the exporter list a single country?

The data from ember is very unlikely to change, and I can't think of a use case where you would be listing all the countries for prometheus to consume, because previously the library is been a bit like allowing a computer to say:

this is my carbon intensity based on where I am in the world, and what time it is

I'm happy to defer to you on this though, as I'm not a heavy user or grafana / prometheus.

Copy link
Member

@mrchrisadams mrchrisadams left a comment

Choose a reason for hiding this comment

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

I have one query about whether regions should be optional, but I'm prepared to follow the use cases you have in mind here Ross, and otherwise I'm happy for this to be merged in. Danke!

@rossf7
Copy link
Contributor Author

rossf7 commented Jun 23, 2022

Do you think it's better to just have the exporter list a single country?

The data from ember is very unlikely to change, and I can't think of a use case where you would be listing all the countries for prometheus to consume, because previously the library is been a bit like allowing a computer to say:

Good point, I'll remove the changes listing all countries. I also don't have a good use case for it right now.

My thinking was about the dev experience. So the user wouldn't need to provide any configuration and could later select the country they are interested in.

But I think it's better and simpler 😅 to provide example install commands with a country and the user can change to their value.

@rossf7 rossf7 merged commit 0f421a0 into main Jun 23, 2022
@rossf7 rossf7 deleted the ember branch June 23, 2022 11:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants