From 1a8de577855372f439b30349019548dfecb1174e Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Mon, 9 Dec 2019 14:11:42 -0700 Subject: [PATCH 1/4] Deprecate stats_summary/create --- CHANGELOG.md | 4 +- docs/source/api/stats_summary_create.rst | 99 ++++++++++++++++++++++++ traffic_ops/app/lib/API/StatsSummary.pm | 7 +- 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 docs/source/api/stats_summary_create.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ffd12452..607820e690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,7 +115,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Traffic Portal - Turn off TLSv1 ### Deprecated/Removed -- The TO API `cachegroup_fallbacks` endpoint is now deprecated +- Traffic Ops Golang Endpoints + - /api/1.1/cachegroup_fallbacks + - /api/1.1/stats_summary/create ## [3.0.0] - 2018-10-30 ### Added diff --git a/docs/source/api/stats_summary_create.rst b/docs/source/api/stats_summary_create.rst new file mode 100644 index 0000000000..b42f012b0e --- /dev/null +++ b/docs/source/api/stats_summary_create.rst @@ -0,0 +1,99 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-stats-summary-create: + +***************** +``stats_summary/create`` +***************** + +``POST`` +======== +.. deprecated:: 1.1 + Use the ``POST`` method of stats_summary instead. + + +Post a stats summary for a given stat. + +:Auth. Required: Yes +:Roles Required: None +:Response Type: Object + +Request Structure +----------------- +:cdnName: The CDN name for which the summary stat was taken for + + .. note:: If the ``cdn`` is equal to ``all`` it represents summary_stats across all delivery services within the given CDN + +:deliveryServiceName: The :term:`Delivery Service` display name for which the summary stat was taken for + + .. note:: If the ``deliveryServiceName`` is equal to ``all`` it represents summary_stats across all delivery services within the given CDN + +:statName: Stat name summary stat represents +:statValue: Summary stat value +:summaryTime: Timestamp of summary, in an ISO-like format +:statDate: Date stat was taken, in :rfc:`3339` format + + .. note:: All fields are required besides ``cdnName`` and ``deliveryServiceName`` which will default to ``all`` if not given + +.. code-block:: http + :caption: Request Example + + POST /api/1.4/stats_summary HTTP/1.1 + Host: trafficops.infra.ciab.test + User-Agent: curl/7.47.0 + Accept: */* + Cookie: mojolicious=... + Content-Length: 113 + Content-Type: application/json + + { + "cdnName": "CDN-in-a-Box", + "deliveryServiceName": "all", + "statName": "daily_maxgbps", + "statValue": 10, + "summaryTime": "2019-12-05 00:03:57+00", + "statDate": "2019-12-05" + } + +Response Structure +------------------ +.. code-block:: http + :caption: Response Example + + HTTP/1.1 200 OK + Access-Control-Allow-Credentials: true + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie + Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE + Access-Control-Allow-Origin: * + Content-Type: application/json + Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly + Whole-Content-Sha512: ezxk+iP7o7KE7zpWmGc0j8nz5k+1wAzY0HiNiA2xswTQrt+N+6CgQqUV2r9G1HAsPNr0HF2PhYs/Xr7DrYOw0A== + X-Server-Name: traffic_ops_golang/ + Date: Thu, 06 Dec 2018 02:14:45 GMT + Content-Length: 97 + + { + "alerts": [ + { + "text": "Stats Summary was successfully created", + "level": "success" + } + { + "level": "warning", + "text": "This endpoint is deprecated, please use 'POST /api/1.4/stats_summary' instead" + } + ] + } \ No newline at end of file diff --git a/traffic_ops/app/lib/API/StatsSummary.pm b/traffic_ops/app/lib/API/StatsSummary.pm index afe2c971dd..8bd074adc7 100644 --- a/traffic_ops/app/lib/API/StatsSummary.pm +++ b/traffic_ops/app/lib/API/StatsSummary.pm @@ -81,8 +81,10 @@ sub create { my $summary_time = $self->req->json->{summaryTime}; my $stat_date = $self->req->json->{statDate}; + my $alternative = "POST /api/1.4/stats_summary"; + if ( !defined($stat_name) || !defined($stat_value) || !defined($stat_date) ) { - $self->alert( { ERROR => "Please provide a stat name, value, and date" } ); + return $self->with_deprecation("Please provide a stat name, value, and date", "error", 500, $alternative); } my $insert = $self->db->resultset('StatsSummary')->create( @@ -96,8 +98,7 @@ sub create { } ); $insert->insert(); - - return $self->success("Successfully added stats summary record"); + return $self->with_deprecation("Successfully added stats summary record", "success", 200, $alternative); } 1; From 07b1524fa6a6eaaab55d1537478389b34912ecb5 Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Wed, 29 Jan 2020 10:10:38 -0700 Subject: [PATCH 2/4] Add changelog / remove docs as no need to add deprecated docs --- CHANGELOG.md | 1 + docs/source/api/stats_summary_create.rst | 99 ------------------------ 2 files changed, 1 insertion(+), 99 deletions(-) delete mode 100644 docs/source/api/stats_summary_create.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 8595bc1b48..4d9e897067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - /divisions/name/:name - /hwinfo/dtdata - /riak/stats + - /stats_summary/create ## [4.0.0] - 2019-12-16 ### Added diff --git a/docs/source/api/stats_summary_create.rst b/docs/source/api/stats_summary_create.rst deleted file mode 100644 index b42f012b0e..0000000000 --- a/docs/source/api/stats_summary_create.rst +++ /dev/null @@ -1,99 +0,0 @@ -.. -.. -.. Licensed under the Apache License, Version 2.0 (the "License"); -.. you may not use this file except in compliance with the License. -.. You may obtain a copy of the License at -.. -.. http://www.apache.org/licenses/LICENSE-2.0 -.. -.. Unless required by applicable law or agreed to in writing, software -.. distributed under the License is distributed on an "AS IS" BASIS, -.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -.. See the License for the specific language governing permissions and -.. limitations under the License. -.. - -.. _to-api-stats-summary-create: - -***************** -``stats_summary/create`` -***************** - -``POST`` -======== -.. deprecated:: 1.1 - Use the ``POST`` method of stats_summary instead. - - -Post a stats summary for a given stat. - -:Auth. Required: Yes -:Roles Required: None -:Response Type: Object - -Request Structure ------------------ -:cdnName: The CDN name for which the summary stat was taken for - - .. note:: If the ``cdn`` is equal to ``all`` it represents summary_stats across all delivery services within the given CDN - -:deliveryServiceName: The :term:`Delivery Service` display name for which the summary stat was taken for - - .. note:: If the ``deliveryServiceName`` is equal to ``all`` it represents summary_stats across all delivery services within the given CDN - -:statName: Stat name summary stat represents -:statValue: Summary stat value -:summaryTime: Timestamp of summary, in an ISO-like format -:statDate: Date stat was taken, in :rfc:`3339` format - - .. note:: All fields are required besides ``cdnName`` and ``deliveryServiceName`` which will default to ``all`` if not given - -.. code-block:: http - :caption: Request Example - - POST /api/1.4/stats_summary HTTP/1.1 - Host: trafficops.infra.ciab.test - User-Agent: curl/7.47.0 - Accept: */* - Cookie: mojolicious=... - Content-Length: 113 - Content-Type: application/json - - { - "cdnName": "CDN-in-a-Box", - "deliveryServiceName": "all", - "statName": "daily_maxgbps", - "statValue": 10, - "summaryTime": "2019-12-05 00:03:57+00", - "statDate": "2019-12-05" - } - -Response Structure ------------------- -.. code-block:: http - :caption: Response Example - - HTTP/1.1 200 OK - Access-Control-Allow-Credentials: true - Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie - Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE - Access-Control-Allow-Origin: * - Content-Type: application/json - Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly - Whole-Content-Sha512: ezxk+iP7o7KE7zpWmGc0j8nz5k+1wAzY0HiNiA2xswTQrt+N+6CgQqUV2r9G1HAsPNr0HF2PhYs/Xr7DrYOw0A== - X-Server-Name: traffic_ops_golang/ - Date: Thu, 06 Dec 2018 02:14:45 GMT - Content-Length: 97 - - { - "alerts": [ - { - "text": "Stats Summary was successfully created", - "level": "success" - } - { - "level": "warning", - "text": "This endpoint is deprecated, please use 'POST /api/1.4/stats_summary' instead" - } - ] - } \ No newline at end of file From 50053c725d689991c9582a6d00dfb9016deeb6e0 Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Wed, 29 Jan 2020 10:17:32 -0700 Subject: [PATCH 3/4] Update deprecation alt --- traffic_ops/app/lib/API/StatsSummary.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/lib/API/StatsSummary.pm b/traffic_ops/app/lib/API/StatsSummary.pm index 8bd074adc7..cef6c09ce4 100644 --- a/traffic_ops/app/lib/API/StatsSummary.pm +++ b/traffic_ops/app/lib/API/StatsSummary.pm @@ -81,7 +81,7 @@ sub create { my $summary_time = $self->req->json->{summaryTime}; my $stat_date = $self->req->json->{statDate}; - my $alternative = "POST /api/1.4/stats_summary"; + my $alternative = "POST /stats_summary"; if ( !defined($stat_name) || !defined($stat_value) || !defined($stat_date) ) { return $self->with_deprecation("Please provide a stat name, value, and date", "error", 500, $alternative); From 7163f5d940cc6b57f51c54ead411d52f4a0c59da Mon Sep 17 00:00:00 2001 From: Michael Hoppal <54542891+mhoppa@users.noreply.github.com> Date: Wed, 29 Jan 2020 10:21:41 -0700 Subject: [PATCH 4/4] Update StatsSummary.pm --- traffic_ops/app/lib/API/StatsSummary.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/lib/API/StatsSummary.pm b/traffic_ops/app/lib/API/StatsSummary.pm index cef6c09ce4..c635bef7ff 100644 --- a/traffic_ops/app/lib/API/StatsSummary.pm +++ b/traffic_ops/app/lib/API/StatsSummary.pm @@ -84,7 +84,7 @@ sub create { my $alternative = "POST /stats_summary"; if ( !defined($stat_name) || !defined($stat_value) || !defined($stat_date) ) { - return $self->with_deprecation("Please provide a stat name, value, and date", "error", 500, $alternative); + return $self->with_deprecation("Please provide a stat name, value, and date", "error", 400, $alternative); } my $insert = $self->db->resultset('StatsSummary')->create(