Green-Software-Foundation / carbon-aware-sdk

Carbon-Aware SDK
https://carbon-aware-sdk.greensoftware.foundation/
MIT License
487 stars 99 forks source link

[Feature Contribution]: Better to throw exception when future datetime is specified to endpoints for current/historical data #396

Open YaSuenag opened 1 year ago

YaSuenag commented 1 year ago

What happened?

We would receive HTTP 204 (No content) when we pass future datetime to endpoints of current/historical data (e.g. /emissions/bylocation) in WebAPI. However these endpoints would not handle forecast data, so future datetime as parameters are not expected.

We've discussed about this whether it would be better to throw exception (e.g. ArgumentOutOfRangeException) in this case in #389 and #384. If throwing exception is appropriate, we need to fix all of datasources (WattTime, ElectricityMaps, ElectricityMapsFree, JSON).

Code of Conduct

Feature Commitment

Willmish commented 1 year ago

I have mixed opinions on this, so will share both reasons why I think we might want it and why not. Why we SHOULD throw an exception:

Why we SHOULDN'T throw an exception:

Additionally, when implementing this we need to think in which timezone and at what times the cutoff time for most recent emission is - e.g. if EMFree has a few hour delay, then requesting current time emissions might be invalid, as the most recent emission is from few hours ago.

YaSuenag commented 1 year ago

maybe we need to keep in mind future datasources which might accept time ranges for future dates on historical endpoints. This can be disregarded however, if we never want to allow forecast data to be returned from a historical endpoint (which does make sense).

I think we can disallow historical endpoint never accept request for forecasting because it is for "historical".

Additionally, when implementing this we need to think in which timezone and at what times the cutoff time for most recent emission is - e.g. if EMFree has a few hour delay, then requesting current time emissions might be invalid, as the most recent emission is from few hours ago.

I've raised this issue about passing future datetime to historical endpoint, so I think we don't need to think about this case.
But I think we can following cases:

  1. do not specify time range:
    • SDK can return current emission data because time range does not specified.
  2. start time is specified, and emission data in range is available
    • SDK can return emission data.
  3. start time is specified, but emission data is out of range
    • SDK cannot return emission data.
  4. start time points the future
    • SDK should not return (should throw exception) on historical endpoint.

I think your concern fits case 2 and 3, it means the SDK user specifies start datetime, so I think it can be allowed that the SDK would not return any data when emission data is out of specified time range.

vaughanknight commented 1 year ago

Can we please create an ADR for this as per the meeting last week on the 2023-10-10 #402 . Thanks!

github-actions[bot] commented 9 months ago

This issue has not had any activity in 120 days. Please review this issue and ensure it is still relevant. If no more activity is detected on this issue for the next 20 days, it will be closed automatically.

YaSuenag commented 9 months ago

Wait, do not close this issue.

I will start to work when I can (maybe after clarifying vNext)

danuw commented 8 months ago

What is next on this one please?

github-actions[bot] commented 4 months ago

This issue has not had any activity in 120 days. Please review this issue and ensure it is still relevant. If no more activity is detected on this issue for the next 20 days, it will be closed automatically.

YaSuenag commented 4 months ago

Please remove stale label from this issue.

Priority of this issue is not high, but it is worth to discuss I think. I'll back when other issues/PRs are closed.

github-actions[bot] commented 3 weeks ago

This issue has not had any activity in 120 days. Please review this issue and ensure it is still relevant. If no more activity is detected on this issue for the next 20 days, it will be closed automatically.

YaSuenag commented 3 weeks ago

Please remove stale label from this issue.