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

TO Fixes Region V5 apis to respond with RFC3339 date/time Format #7698

Merged
merged 12 commits into from
Aug 9, 2023

Conversation

gbkannan89
Copy link
Contributor

Related: #5911


Which Traffic Control components are affected by this PR?

  • Documentation
  • Traffic Ops

What is the best way to verify this PR?

Curl all Region v5 REST calls (GET, CREATE, UPDATE, DELETE) and ensure you are getting RFC3339 date-time ( eg: lastUpdated : "2023-05-25T15:59:33.7096-06:00" )

If this is a bugfix, which Traffic Control versions contained the bug?

  • 7.0.x

PR submission checklist

@gbkannan89 gbkannan89 marked this pull request as ready for review August 4, 2023 07:12
@ericholguin ericholguin added Traffic Ops related to Traffic Ops low impact affects only a small portion of a CDN, and cannot itself break one tech debt rework due to choosing easy/limited solution labels Aug 4, 2023
@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

Merging #7698 (f93b368) into master (849d166) will decrease coverage by 0.08%.
The diff coverage is 3.47%.

@@             Coverage Diff              @@
##             master    #7698      +/-   ##
============================================
- Coverage     29.78%   29.70%   -0.08%     
  Complexity       98       98              
============================================
  Files           802      802              
  Lines         85789    86011     +222     
  Branches        952      952              
============================================
+ Hits          25550    25552       +2     
- Misses        58099    58320     +221     
+ Partials       2140     2139       -1     
Flag Coverage Δ
golib_unit 48.05% <ø> (+<0.01%) ⬆️
grove_unit 4.60% <ø> (ø)
t3c_unit 4.95% <ø> (ø)
traffic_monitor_unit 21.30% <ø> (ø)
traffic_ops_integration 69.39% <100.00%> (ø)
traffic_ops_unit 22.16% <1.76%> (-0.13%) ⬇️
traffic_portal_v2 73.71% <ø> (+0.01%) ⬆️
traffic_stats_unit 10.14% <ø> (ø)
unit_tests 26.86% <1.76%> (-0.08%) ⬇️
v3 57.79% <ø> (ø)
v4 79.18% <ø> (ø)
v5 78.52% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
traffic_ops/traffic_ops_golang/region/regions.go 7.48% <0.00%> (-14.84%) ⬇️
traffic_ops/traffic_ops_golang/routing/routes.go 95.53% <100.00%> (ø)
traffic_ops/v5-client/region.go 82.35% <100.00%> (ø)

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

}

query := selectQuery() + where + orderBy + pagination
rows, err := tx.NamedQuery(query, queryValues)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources

This query depends on a [user-provided value](1).
Copy link
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

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

The API v5 tests fail:

    regions_test.go:324: Received unexpected error: error requesting Traffic Ops: path 'https://localhost:6443/api/5.0/regions' gave HTTP error 400 Bad Request - error-level alerts: error decoding POST request body into RegionV5 struct parsing time "\"0001-01-01 00:00:00+00\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse " 00:00:00+00\"" as "T" Messages: Could not create Region 'region1': error requesting Traffic Ops: path 'https://localhost:6443/api/5.0/regions' gave HTTP error 400 Bad Request - error-level alerts: error decoding POST request body into RegionV5 struct parsing time "\"0001-01-01 00:00:00+00\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse " 00:00:00+00\"" as "T" - alerts: [{Text:error decoding POST request body into RegionV5 struct parsing time "\"0001-01-01 00:00:00+00\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse " 00:00:00+00\"" as "T" Level:error}]

Both need to use the API v5 version instead.

"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
validation "github.com/go-ozzo/ozzo-validation"
Copy link
Member

Choose a reason for hiding this comment

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

There should be a line break between Traffic Control imports and third-party imports.

@gbkannan89 gbkannan89 requested a review from zrhoffman August 7, 2023 06:54
@@ -298,7 +294,7 @@ func validateRegionsDescSort() utils.CkReqFunc {

func validateRegionsPagination(paginationParam string) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
paginationResp := resp.([]tc.Region)
paginationResp := resp.([]tc.RegionV5)
Copy link
Member

@zrhoffman zrhoffman Aug 7, 2023

Choose a reason for hiding this comment

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

This line panics for me. You're typecasting to []tc.RegionV5, which is not the type of the Response field:

type RegionsResponseV50 struct {
Response []Region `json:"response"`

Copy link
Contributor

@kdamichie kdamichie left a comment

Choose a reason for hiding this comment

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

Few changes needed.

@@ -41,8 +41,7 @@ Request Structure
+-----------+----------+---------------------------------------------------------------------------------------------------------------+
| name | no | Filter :term:`Regions` by name |
+-----------+----------+---------------------------------------------------------------------------------------------------------------+
| orderby | no | Choose the ordering of the results - must be the name of one of the fields of the objects in the ``response`` |
| | | array |
| orderby | no | Choose the ordering of the results - either one of them "division", "id", "name" |
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ending pipe

@@ -111,7 +110,6 @@ Creates a new region
Request Structure
-----------------
:division: The integral, unique identifier of the division which shall contain the new region\ [1]_
Copy link
Contributor

Choose a reason for hiding this comment

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

Target "1" was removed, so his does not refer to anything anymore. Needs removed

@@ -39,7 +39,6 @@ Request Structure
+------+---------------------------------------------------------+

:division: The new integral, unique identifier of the division which shall contain the region\ [1]_
Copy link
Contributor

Choose a reason for hiding this comment

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

Target "1" was removed, so his does not refer to anything anymore. Needs removed

SELECT max(r.last_updated) as t FROM region r
JOIN division d ON r.division = d.id ` + where +
` UNION ALL
select max(last_updated) as t from last_deleted l where l.table_name='region') as res`
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to keep this commented out statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no it is not commented

Copy link
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

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

Just 1 small comment.

Comment on lines 3 to 4
import "time"

Copy link
Member

Choose a reason for hiding this comment

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

Imports should be after the Apache license, not before.

@gbkannan89 gbkannan89 requested a review from zrhoffman August 9, 2023 15:02
Copy link
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

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

Looks good! But I'll wait for @kdamichie to approve before I merge.

Copy link
Contributor

@kdamichie kdamichie left a comment

Choose a reason for hiding this comment

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

Approved

docs/source/api/v5/regions.rst Outdated Show resolved Hide resolved
@zrhoffman
Copy link
Member

Approved

I'll wait for the checks to pass, then merge

@zrhoffman zrhoffman merged commit 6cab395 into apache:master Aug 9, 2023
cybertunnel pushed a commit to cybertunnel/trafficcontrol that referenced this pull request Aug 16, 2023
…che#7698)

* region v5 api

* change log and doc

* region comments addresed

* response error fix

* comments addressed

* comment addressed

* removed  stray pipe

---------

Co-authored-by: Zach Hoffman <zrhoffman@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low impact affects only a small portion of a CDN, and cannot itself break one tech debt rework due to choosing easy/limited solution Traffic Ops related to Traffic Ops
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants