-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix for #81: For the Prometheus exporter, the values based on ElecticityMaps provider are estimations and not the real values #83
Conversation
thegreenwebfoundation#81 - Now sending always the timestamp in the Prometheus metrics. - For ElectricityMaps, we now use the historic endpoint instead of the carbon-intensity one, so we can get both the latest estimated and real values. - Tested that it works with Ember and CarbonIntensityOrgUK, Watttime not yet (I need to register) - The label is_estimated has been added in the Prometheus metrics. For ElectricityMaps it can provide values for both, or for one of the two, depending on the location. - For the other providers it always returns the value as is_estimated=false (the default) because I didn't make any changes. I'm. not 100% sure this is correct for all of them, or if some of the providers also return estimations (to investigate). - The error handling when parsing generates a lot of clutter, not sure if there's a better way to do it in go...
for relative carbon intensity Otherwise we see this error, for example: panic: inconsistent label cardinality: expected 5 label values but got 6 in []string{"CAISO_NORTH", "", "WattTime", "", "percent", "false"}
Thanks for this @locomundo, this looks great! I'm currently travelling but if @rossf7 doesn't get to it before Wednesday I'll aim to review it by the end of the week. |
@locomundo Yes this looks good. I think / hope we can get it merged this week and then cut a release with it and #82
For the other providers I think we'll need to check their methodologies. Unless you know @mrchrisadams ?
I should be able to review first half of this week. Chris, I'll let you know if I get delayed |
Hey @rossf7 - I think pretty much all of these are forecasts / estimates rather than historical, recorded figures. Ember - the free annual figures we use are an estimate, based on either the latest data for the last full year, or data from the last full month. In each case, if we used the Ember data to get an idea of the carbon intensity for "now", I think we'd be looking at historical data as the basis to project forward to now. More in the methodology documentation here CarbonIntensityOrgUK - the figures here are forecasts, based on an ML model. I don't think it's historical data per se. They briefly describe the M methodology on their front page Watttime - I'm less clear on Watttime. Because marginal emissions rely on a comparison to a counterfactual that doesn't exist (we don't have two versions of the same grid to compare side by side), I think you'd refer to all of these as estimates, until there was some explicit validation for each reading. I think this is somewhat comparable to Electricity Maps saying a reading is estimated until it is replaced with 'real' data. You can read some more about the Watttime methodologies here Until we hear otherwise, I think it's safer to assume all the other readings are estimates. |
In that case we can invert it and make the default as isEstimated=true. If you all agree on this I can make that change in the PR @rossf7 @mrchrisadams |
@locomundo Yes, good idea lets invert it. @mrchrisadams thanks for clarifying and I agree for WattTime since they return marginal emissions we should treat them as estimated. |
Thus, we are setting IsEstimated to true. See for more info thegreenwebfoundation#83 (comment)
Ok, so now all the other providers are returning is_estimated=true. No default, though, I thought I could change the default value, but that was not possible. However, this might be better so it's explicit and clear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@locomundo This is really cool to be able to show both values!
Just some minor nits from me and then I think this is good to go.
pkg/provider/electricity_maps.go
Outdated
@@ -64,34 +64,139 @@ func (e *ElectricityMapsClient) GetCarbonIntensity(ctx context.Context, location | |||
return nil, errBadStatus(resp) | |||
} | |||
|
|||
data := &electricityMapsData{} | |||
err = json.NewDecoder(resp.Body).Decode(data) | |||
type EMHistoryResponse struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type EMHistoryResponse struct { | |
type electricityMapsHistoryResponse struct { |
Rather than have this struct inline could you rename it and add it to the end of the file?
For now we have all the providers in a single package but we use the provider name as a prefix for the types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
pkg/provider/electricity_maps.go
Outdated
|
||
// Helper struct to remove clutter in the calling function | ||
// while finding the latest (and greatest) data points | ||
type mostRecentDatapoints struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type mostRecentDatapoints struct { | |
type electricityMapsDatapoints struct { |
Same here to add the prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: Ross Fairbanks <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
in Prometheus. Related to PR thegreenwebfoundation#83 "For the Prometheus exporter, the values based on ElecticityMaps provider are estimations and not the real values"
* Fix/improvement for issue #81 #81 - Now sending always the timestamp in the Prometheus metrics. - For ElectricityMaps, we now use the historic endpoint instead of the carbon-intensity one, so we can get both the latest estimated and real values. - Tested that it works with Ember and CarbonIntensityOrgUK, Watttime not yet (I need to register) - The label is_estimated has been added in the Prometheus metrics. For ElectricityMaps it can provide values for both, or for one of the two, depending on the location. - For the other providers it always returns the value as is_estimated=false (the default) because I didn't make any changes. I'm. not 100% sure this is correct for all of them, or if some of the providers also return estimations (to investigate). - The error handling when parsing generates a lot of clutter, not sure if there's a better way to do it in go... * Fix for Watttime - was missing the is_estimated label... for relative carbon intensity Otherwise we see this error, for example: panic: inconsistent label cardinality: expected 5 label values but got 6 in []string{"CAISO_NORTH", "", "WattTime", "", "percent", "false"} * Cleaned up some commented code * It turns out that all the other providers return estimated values Thus, we are setting IsEstimated to true. See for more info #83 (comment) * Some renaming as suggested by Chris * Update pkg/provider/electricity_maps.go Co-authored-by: Ross Fairbanks <[email protected]> * Document how to fix "old" samples not being ingested in Prometheus. Related to PR #83 "For the Prometheus exporter, the values based on ElecticityMaps provider are estimations and not the real values" * Corrections suggested by Ross Co-authored-by: Ross Fairbanks <[email protected]> --------- Co-authored-by: Flavia Paganelli <[email protected]> Co-authored-by: Ross Fairbanks <[email protected]>
This is the fix discussed in issue #81.
We noticed that when using the grid-intensity exporter with
ElectricityMaps
as provider we always obtained an estimation, never the real value.By using the
history
endpoint as opposed to thelatest
one, we can get both the latest estimated value, as well as the latest real measured value.This change includes:
ElectricityMaps
, we now use thehistory
endpoint instead of thelatest
one, to return both the latest estimated and latest real values.ElectricityMaps
,Ember
andCarbonIntensityOrgUK
, andWatttime
providers (so all of them), but didn't run the tests.is_estimated
has been added in the Prometheus metrics. ForElectricityMaps
it can provide values for estimated or real, or for one of the two, depending on the location. For example, for NL we get:is_estimated=false
(the default). Is this correct or are you aware of some of the other providers returning estimated data? @rossf7 @mrchrisadams