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 node and region labels to exporter #62

Merged
merged 5 commits into from
Aug 31, 2022
Merged

Add node and region labels to exporter #62

merged 5 commits into from
Aug 31, 2022

Conversation

rossf7
Copy link
Contributor

@rossf7 rossf7 commented Aug 29, 2022

Towards #59

This adds --node and --region flags to the exporter command. The GRID_INTENSITY_NODE and GRID_INTENSITY_REGION env vars can also be used to set this.

go run . exporter -h
A prometheus exporter for getting the carbon intensity data for
electricity grids.

This can be used to make your software carbon aware so it runs at times when
the grid is greener or at locations where carbon intensity is lower.

	grid-intensity exporter --provider Ember --location IE --region eu-west-1 --node worker-1
	grid-intensity exporter -p Ember -l BOL

Usage:
  grid-intensity exporter [flags]

Flags:
  -h, --help              help for exporter
  -l, --location string   Location code for provider
  -n, --node string       Node where the exporter is running
  -p, --provider string   Provider of carbon intensity data (default "Ember")
  -r, --region string     Region where the exporter is running

The labels get added to the metrics like here.

curl -s http://localhost:8000/metrics | grep grid
# HELP grid_intensity_carbon_average Average carbon intensity for the electricity grid in this location.
# TYPE grid_intensity_carbon_average gauge
grid_intensity_carbon_average{location="IE",node="kind-kind",provider="Ember",region="eu-west-1",units="gCO2e per kWh"} 361.274

@mrchrisadams
Copy link
Member

hi @rossf7 - this should be unblocked now, thanks for being patient with me 😅

@rossf7 rossf7 marked this pull request as ready for review August 31, 2022 08:36
@rossf7 rossf7 changed the title WIP: Add node and region labels to exporter Add node and region labels to exporter Aug 31, 2022
@@ -34,7 +36,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install nomad
-
name: Start running nomad in agent mode, then background it
run: nomad agent --dev &
run: nomad agent --dev --node dev01 &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting the node name to make it predictable in the test.

- name: GRID_INTENSITY_NODE
valueFrom:
fieldRef:
fieldPath: spec.nodeName
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 node name is set automatically.

valueFrom:
configMapKeyRef:
name: {{ .Release.Name }}
key: gridIntensityRegion
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For k8s the region has to be set by the user. As there is no easy way to get the node label even if its set which is a pain.

@@ -37,6 +37,8 @@ job "grid-intensity-exporter" {
env {
GRID_INTENSITY_LOCATION = "GBR"
GRID_INTENSITY_PROVIDER = "Ember"
GRID_INTENSITY_NODE = "${node.unique.name}"
GRID_INTENSITY_REGION = "${node.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.

For nomad we can template both the node and region which is kinda nice :)

@rossf7 rossf7 requested a review from mrchrisadams August 31, 2022 08:43
@rossf7
Copy link
Contributor Author

rossf7 commented Aug 31, 2022

@mrchrisadams Thanks this one is ready for review as well now.

@fershad Could you add these extra params to the docs changes?

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.

Hi Ross,

thanks for adding all the explanatory comments. I'm happy for this to be merged in.

@rossf7 rossf7 merged commit 0c9424b into main Aug 31, 2022
@rossf7 rossf7 deleted the node-region-labels branch August 31, 2022 15:09
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.

2 participants