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

Support blackout tests #651

Merged
merged 46 commits into from May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
88c6a42
remove tests already present in v3
Flix6x Apr 25, 2023
f633cdb
move asset deletion test to v3
Flix6x Apr 25, 2023
3bcd8f1
move asset creation test to v3
Flix6x Apr 25, 2023
d7b0c39
remove last remaining asset test from v2
Flix6x Apr 25, 2023
c4e34c4
stop testing post_price_data and post_prognosis on v2
Flix6x Apr 25, 2023
c197cdf
move test scheduling with unknown prices from v1.3 to v3
Flix6x Apr 25, 2023
80bba2c
remove v1.3 test already present in v3
Flix6x Apr 25, 2023
66b374b
move test for wrong job id from v1.3 to v3
Flix6x Apr 25, 2023
5c21e2b
no tests worth moving in v1.2
Flix6x Apr 25, 2023
fea604a
remove test for posting weather data from v1.1
Flix6x Apr 25, 2023
0f3cee5
move test for posting data with incompatible resolution from v1.1 to v3
Flix6x Apr 25, 2023
e29d20a
move test for posting data with a user that is not properly set up as…
Flix6x Apr 25, 2023
a5236a9
move test for getting data for an empty period from v1.1 to v3
Flix6x Apr 25, 2023
a95864b
move v3 tests that just GET data to test module that uses db fixture …
Flix6x Apr 25, 2023
3f37be1
remove v1.1 test utils including old simulation script that uses one …
Flix6x Apr 25, 2023
900d9e2
salvage only 1 test from v1, which logs out a user
Flix6x Apr 25, 2023
73cfe29
add missing fixtures to let tests succeed on their own, too
Flix6x Apr 25, 2023
0a7fd46
remove v1.0 test utils
Flix6x Apr 25, 2023
316ed0b
add changelog warning
Flix6x Apr 25, 2023
62b0b34
update API documentation
Flix6x Apr 25, 2023
51e665d
Document public endpoints in v3
Flix6x Apr 25, 2023
62c5ef5
black
Flix6x Apr 25, 2023
928510b
Implement getService for API v3
Flix6x Apr 26, 2023
4c7780c
Document service listing for v3
Flix6x Apr 26, 2023
d94d780
Show quickref contents rather than summary line of docstring
Flix6x Apr 26, 2023
c966746
Fix removal of suffix and prefix, by not using rstrip and lstrip, res…
Flix6x Apr 26, 2023
250dd54
API changelog entry
Flix6x Apr 26, 2023
fe22428
Make getService more RESTful
Flix6x Apr 26, 2023
ee3d176
Add warning to API developer docs
Flix6x Apr 26, 2023
81b0600
More robust against spaces
Flix6x Apr 26, 2023
eb83957
Update main changelog entry
Flix6x Apr 26, 2023
1b8266d
Support blackout tests
Flix6x Apr 28, 2023
d6b6d05
black
Flix6x Apr 28, 2023
ade6713
Fix test
Flix6x Apr 28, 2023
25db921
More specific if statement
Flix6x Apr 28, 2023
9c56501
change default to activating the sunset
Flix6x Apr 28, 2023
733a244
Add sunset documentation for FlexMeasures hosts and make the config s…
Flix6x Apr 28, 2023
7d3ab42
shorten comment
Flix6x Apr 28, 2023
522634f
fix override from config setting
Flix6x Apr 28, 2023
9126a14
refactor
Flix6x Apr 28, 2023
5164c8f
Cross reference to snapshot version of API documentation
Flix6x Apr 28, 2023
5fee35c
We want to support blackout tests already from the version that annou…
Flix6x Apr 28, 2023
76284b4
black
Flix6x Apr 28, 2023
0d8e6cc
Add cross-reference and explanation, and add clarity
Flix6x May 1, 2023
1c2a181
Customize admonition
Flix6x May 1, 2023
79e2be2
Merge remote-tracking branch 'origin/main' into support-blackout-tests
Flix6x May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions documentation/api/introduction.rst
Expand Up @@ -107,6 +107,11 @@ which gives a response like this if the credentials are correct:
Deprecation and sunset
----------------------

Some sunsetting options are available for FlexMeasures hosts. See :ref:`api_deprecation_hosts`.

FlexMeasures clients
^^^^^^^^^^^^^^^^^^^^

Professional API users should monitor API responses for the ``"Deprecation"`` and ``"Sunset"`` response headers [see `draft-ietf-httpapi-deprecation-header-02 <https://datatracker.ietf.org/doc/draft-ietf-httpapi-deprecation-header/>`_ and `RFC 8594 <https://www.rfc-editor.org/rfc/rfc8594>`_, respectively], so system administrators can be warned when using API endpoints that are flagged for deprecation and/or are likely to become unresponsive in the future.

The deprecation header field shows an `IMF-fixdate <https://www.rfc-editor.org/rfc/rfc7231#section-7.1.1.1>`_ indicating when the API endpoint was deprecated.
Expand Down Expand Up @@ -139,3 +144,19 @@ Here is a client-side code example in Python (this merely prints out the depreca
print(f"Your request to {url} returned a sunset warning. Sunset: {content}")
elif header == "Link" and ('rel="deprecation";' in content or 'rel="sunset";' in content):
print(f"Further info is available: {content}")

.. _api_deprecation_hosts:

FlexMeasures hosts
^^^^^^^^^^^^^^^^^^

When upgrading to a FlexMeasures version that sunsets an API version, clients will receive ``HTTP status 410 (Gone)`` responses when calling corresponding endpoints.
After upgrading to one of the next FlexMeasures versions, they will receive ``HTTP status 404 (Not Found)`` responses.

Hosts should not expect every client to monitor response headers and proactively upgrade to newer API versions.
Please make sure that your users have upgraded before you upgrade to a FlexMeasures version that sunsets an API version.
You can do this by checking your server logs for warnings about users who are still calling deprecated endpoints.

In case you have users that haven't upgraded yet, and would still like to upgrade FlexMeasures, you can.
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
Just set the config setting ``FLEXMEASURES_API_SUNSET_ACTIVE = False`` and consider announcing some blackout tests to your users, during which you can set this setting to ``True`` to activate the sunset.
During such a blackout test, clients will receive ``HTTP status 410 (Gone)`` responses when calling corresponding endpoints.
nhoening marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -7,6 +7,7 @@ v0.13.0 | April XX, 2023
============================

.. warning:: Sunset notice for API versions 1.0, 1.1, 1.2, 1.3 and 2.0: after upgrading to ``flexmeasures==0.13``, users of these API versions may receive ``HTTP status 410 (Gone)`` responses.
See the `documentation for deprecation and sunset <https://flexmeasures.readthedocs.io/en/latest/api/introduction.html#deprecation-and-sunset>`_.
The relevant endpoints have been deprecated since ``flexmeasures==0.12``.

.. warning:: The API endpoint (`[POST] /sensors/(id)/schedules/trigger <api/v3_0.html#post--api-v3_0-sensors-(id)-schedules-trigger>`_) to make new schedules sunsets the deprecated (since v0.12) storage flexibility parameters (they move to the ``flex-model`` parameter group), as well as the parameters describing other sensors (they move to ``flex-context``).
Expand All @@ -29,6 +30,7 @@ Bugfixes

Infrastructure / Support
----------------------
* Support blackout tests for sunset API versions [see `PR #651 <https://www.github.com/FlexMeasures/flexmeasures/pull/651>`_]
* Sunset API versions 1.0, 1.1, 1.2, 1.3 and 2.0 [see `PR #650 <https://www.github.com/FlexMeasures/flexmeasures/pull/650>`_]
* Sunset several API fields for `/sensors/<id>/schedules/trigger` (POST) that have moved into the ``flex-model`` or ``flex-context`` fields [see `PR #580 <https://www.github.com/FlexMeasures/flexmeasures/pull/580>`_]
* Fix broken `make show-data-model` command [see `PR #638 <https://www.github.com/FlexMeasures/flexmeasures/pull/638>`_]
Expand Down
16 changes: 8 additions & 8 deletions documentation/configuration.rst
Expand Up @@ -596,24 +596,24 @@ Default: ``None``
Sunset
------

FLEXMEASURES_API_1_AND_2_SUNSET_ACTIVE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FLEXMEASURES_API_SUNSET_ACTIVE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow control over the effect of sunsetting API versions 1.0, 1.1, 1.2, 1.3 and 2.0.
Specifically, if True, the endpoints in these versions will return 410 (Gone) status codes.
Allow control over the effect of sunsetting API versions.
Specifically, if True, the endpoints in sunset versions will return ``HTTP status 410 (Gone)`` status codes.
If False, the endpoints will work like before, including Deprecation and Sunset headers in their response.

Default: ``True``

FLEXMEASURES_API_1_AND_2_SUNSET_DATE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FLEXMEASURES_API_SUNSET_DATE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow to override the default sunset date for your clients.

Default: ``None`` (defaults are set internally for each sunset API version, e.g. ``"2023-05-01"`` for version 2.0)

FLEXMEASURES_API_1_AND_2_SUNSET_LINK
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FLEXMEASURES_API_SUNSET_LINK
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow to override the default sunset link for your clients.

Expand Down
12 changes: 6 additions & 6 deletions flexmeasures/api/common/utils/deprecation_utils.py
Expand Up @@ -22,10 +22,10 @@ def let_host_switch_to_returning_410():

# Override with custom info link, if set by host
_sunset_info_link = current_app.config.get(
"FLEXMEASURES_API_1_AND_2_SUNSET_LINK", sunset_info_link
"FLEXMEASURES_API_SUNSET_LINK", sunset_info_link
)

if current_app.config["FLEXMEASURES_API_1_AND_2_SUNSET_ACTIVE"]:
if current_app.config["FLEXMEASURES_API_SUNSET_ACTIVE"]:
abort(
410,
f"API version {api_version_sunset} has been sunset. Please upgrade to API version {api_version_upgrade_to}. See {_sunset_info_link} for more information.",
Expand Down Expand Up @@ -94,12 +94,12 @@ def _after_request_handler(response: Response) -> Response:

# Override sunset date if host used corresponding config setting
_sunset = _format_sunset(
current_app.config.get("FLEXMEASURES_API_1_AND_2_SUNSET_DATE", sunset)
current_app.config.get("FLEXMEASURES_API_SUNSET_DATE", sunset)
)

# Override sunset link if host used corresponding config setting
_sunset_link = current_app.config.get(
"FLEXMEASURES_API_1_AND_2_SUNSET_LINK", sunset_link
"FLEXMEASURES_API_SUNSET_LINK", sunset_link
)

return _add_headers(
Expand Down Expand Up @@ -158,12 +158,12 @@ def _after_request_handler(response: Response) -> Response:

# Override sunset date if host used corresponding config setting
_sunset = _format_sunset(
current_app.config.get("FLEXMEASURES_API_1_AND_2_SUNSET_DATE", sunset)
current_app.config.get("FLEXMEASURES_API_SUNSET_DATE", sunset)
)

# Override sunset link if host used corresponding config setting
_sunset_link = current_app.config.get(
"FLEXMEASURES_API_1_AND_2_SUNSET_LINK", sunset_link
"FLEXMEASURES_API_SUNSET_LINK", sunset_link
)

return _add_headers(
Expand Down
6 changes: 3 additions & 3 deletions flexmeasures/utils/config_defaults.py
Expand Up @@ -131,9 +131,9 @@ class Config(object):
)

# Custom sunset switches
FLEXMEASURES_API_1_AND_2_SUNSET_ACTIVE: bool = True # if True, sunset endpoints return 410 (Gone) responses; if False, they will work as before
FLEXMEASURES_API_1_AND_2_SUNSET_DATE: str | None = None # e.g. 2023-05-01
FLEXMEASURES_API_1_AND_2_SUNSET_LINK: str | None = None # e.g. https://flexmeasures.readthedocs.io/en/latest/api/introduction.html#deprecation-and-sunset
FLEXMEASURES_API_SUNSET_ACTIVE: bool = True # if True, sunset endpoints return 410 (Gone) responses; if False, they will work as before
FLEXMEASURES_API_SUNSET_DATE: str | None = None # e.g. 2023-05-01
FLEXMEASURES_API_SUNSET_LINK: str | None = None # e.g. https://flexmeasures.readthedocs.io/en/latest/api/introduction.html#deprecation-and-sunset


# names of settings which cannot be None
Expand Down