You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/01/27 23:57:40 UTC

[GitHub] [trafficcontrol] ocket8888 opened a new pull request #5475: Remove tm_url from CDN Snapshots

ocket8888 opened a new pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475


   ## What does this PR (Pull Request) do?
   - [x] This PR fixes #1876 
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [ ] This PR fixes #REPLACE_ME OR is not related to any Issue <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - CDN in a Box
   - Documentation
   - Grove
   - Traffic Control Client <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Monitor
   - Traffic Ops
   - Traffic Ops ORT
   - Traffic Portal
   - Traffic Router
   - Traffic Stats
   - Traffic Vault
   - CI tests
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '1df853c8'), in v4.0.0,
   and in the current 4.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (1df853c8)
   - 4.0.0
   - 4.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [ ] This PR includes tests OR I have explained why tests are unnecessary
   - [ ] This PR includes documentation OR I have explained why documentation is unnecessary
   - [ ] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [ ] This PR includes any and all required license headers
   - [ ] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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.
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569803734



##########
File path: traffic_ops/traffic_ops_golang/crconfig/crconfig.go
##########
@@ -30,7 +30,7 @@ import (
 )
 
 // Make creates and returns the CRConfig from the database.
-func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {
+func Make(tx *sql.Tx, cdn, user, toHost, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {

Review comment:
       Either way we'd need `CRConfig.Stats.TMPath`; `CRConfigEmulateOldPath` only determined whether or not to insert a legacy path into that field. It would still be populated otherwise, just with a different path. Except in API 4 the property is only populated if you specifically request emulating legacy behavior.
   
   I believe the "major version" that's talking about is the major ATC version, since historically snapshots have been un-versioned. 
   
   When I made the change it looked like the next ATC version was going to be 5.1, but currently it seems like this won't make it into that and would go into ATC 6 instead, so I _think_ we can get rid of that, but just in case this gets cherry-picked back for whatever reason I think I'd prefer to do that separately. If that's acceptable I'll open an issue about it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569832487



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
 	defer inf.Close()

Review comment:
       Ahh ok. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569803734



##########
File path: traffic_ops/traffic_ops_golang/crconfig/crconfig.go
##########
@@ -30,7 +30,7 @@ import (
 )
 
 // Make creates and returns the CRConfig from the database.
-func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {
+func Make(tx *sql.Tx, cdn, user, toHost, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {

Review comment:
       Either way we'd need `CRConfig.Stats.TMPath`; `CRConfigEmulateOldPath` only determined whether or not to insert a legacy path into that field. It would still be populated otherwise, just with a different path.
   
   I believe the "major version" that's talking about is the major ATC version, since historically snapshots have been un-versioned. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569814791



##########
File path: docs/source/api/v1/cdns_name_snapshot.rst
##########
@@ -321,6 +321,11 @@ Response Structure
 	:date:       The UNIX epoch timestamp date in the Traffic Ops server's own timezone
 	:tm_host:    The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server
 	:tm_path:    A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN
+
+		.. deprecated:: ATCv5.1
+
+			This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4
+

Review comment:
       yeah, that should've been done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman merged pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
zrhoffman merged pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569792018



##########
File path: traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql
##########
@@ -0,0 +1,23 @@
+/*
+
+    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.
+*/
+
+-- +goose Up

Review comment:
       I think that would be beneficial. I can see the updated information in the SQL table. It's removes the `tm_path` value from the `stats` object on _goose up_. If you need to revert with _goose down_, it subsequently adds a `tm_path` value back into the `stats` object with the value "/api/4.0/cdns/\<cdn name\>/snapshot"




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569806100



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {
+		decoded.Stats.TMPath = new(string)
+		*decoded.Stats.TMPath = fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"])
+	}
+	api.WriteResp(w, r, decoded)

Review comment:
       This used to not use it either, the only reason it does now is because it sometimes needs to modify the structure, which it cannot safely do to a byte array. Deserializing and reserializing can be expensive - although there's no reason to believe that would have a meaningful impact on performance without measuring. What they're doing right now is safe, accurate, works, and isn't particularly confusing so I don't feel a need to change it, personally.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569831823



##########
File path: traffic_ops/traffic_ops_golang/crconfig/crconfig.go
##########
@@ -30,7 +30,7 @@ import (
 )
 
 // Make creates and returns the CRConfig from the database.
-func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {
+func Make(tx *sql.Tx, cdn, user, toHost, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {

Review comment:
       Oh yeah, it can be separate from this PR. I just figured if we're gutting a field and it's dependent upon another deprecated field that _can_ be removed then we can just keep cleaning. Anyways, another GH issue is just fine for me here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569833103



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {

Review comment:
       @ocket8888 Since I think we can remove the flag in a separate GH issue, we might need the check here then. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569724216



##########
File path: traffic_ops/traffic_ops_golang/crconfig/crconfig.go
##########
@@ -30,7 +30,7 @@ import (
 )
 
 // Make creates and returns the CRConfig from the database.
-func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {
+func Make(tx *sql.Tx, cdn, user, toHost, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) {

Review comment:
       The **emulateOldPath** appears to bubble up to the `config/config.go` _ConfigTrafficOpsGolang_ struct where we see:
   ```go
   	// CRConfigUseRequestHost is whether to use the client request host header in the CRConfig. If false, uses the tm.url parameter.
   	// This defaults to false. Traffic Ops used to always use the host header, setting this true will resume that legacy behavior.
   	// See https://github.com/apache/trafficcontrol/issues/2224
   	// Deprecated: will be removed in the next major version.
   	CRConfigUseRequestHost bool `json:"crconfig_snapshot_use_client_request_host"`
   	// CRConfigEmulateOldPath is whether to emulate the legacy CRConfig request path when generating a new CRConfig. This primarily exists in the event a tool relies on the legacy path '/tools/write_crconfig'.
   	// Deprecated: will be removed in the next major version.
   	CRConfigEmulateOldPath bool `json:"crconfig_emulate_old_path"`
   ```
   
   When is the "next major version" mentioned here? Is that the next major API version? Since we're going to API 4.0, is that the "next major version" mentioned and thusly we can remove this and all the logic dependent on it as well? If that's the case, do we even need to emulate the old path and have this `crc.Stats.TMPath` value if we no longer emulate the old path?

##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
 	defer inf.Close()
 
 	start := time.Now()
-	crConfig, err := Make(inf.Tx.Tx, inf.Params["cdn"], inf.User.UserName, r.Host, r.URL.Path, inf.Config.Version, inf.Config.CRConfigUseRequestHost, inf.Config.CRConfigEmulateOldPath)
+	emulate := inf.Config.CRConfigEmulateOldPath || inf.Version.Major < 4

Review comment:
       I like this as a separate variable. Very clear.
   
   As I mentioned in other comments, it is unclear to me when we officially quit using `inf.Config.CRConfigEmulateOldPath`. If we do remove the `inf.Config.CRConfigEmulateOldPath` can we also then remove the `inf.Version.Major < 4` check as well?

##########
File path: lib/go-tc/crconfig.go
##########
@@ -199,11 +199,13 @@ type CRConfigMonitor struct {
 	ServerStatus *CRConfigServerStatus `json:"status,omitempty"`
 }
 
+// CRConfigStats is the type of the 'stats' property of a CDN Snapshot.
 type CRConfigStats struct {
 	CDNName         *string `json:"CDN_name,omitempty"`
 	DateUnixSeconds *int64  `json:"date,omitempty"`
 	TMHost          *string `json:"tm_host,omitempty"`
-	TMPath          *string `json:"tm_path,omitempty"`
-	TMUser          *string `json:"tm_user,omitempty"`
-	TMVersion       *string `json:"tm_version,omitempty"`
+	// Deprecated: Don't ever use this for anything. It's been removed from APIv4 responses.

Review comment:
       The `// Deprecated: [...]` warning is excellent, but can/should we put a final removal notice as well? For example, I might come across this in 2 years and still not know if/when we can actually remove this (See a subsequent comment in this review)
   
   ```
   // Deprecated: ... Can/Will be removed in API v 6+
   ```

##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {
+		decoded.Stats.TMPath = new(string)
+		*decoded.Stats.TMPath = fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"])
+	}
+	api.WriteResp(w, r, decoded)

Review comment:
       There are other instances in this file of not using the `api.WriteResp` wrapper func. Should those be changed now or only as touched?

##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {

Review comment:
       Do we need to check `inf.Config.CRConfigEmulateOldPath` here as well?

##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
 	defer inf.Close()

Review comment:
       I'm not understanding the purpose of this Handler, especially with the comment warning and the route definition:
   `cdns/{cdn}/snapshot/new/?$`
   
   How does this create a _new_ crconfig? Should this route definition continue to be a part of the clients going forward as well? I see that clients have both available APIs to call from (`getCRConfig` and `GetCRConfigNew`). Outside of tests, I don't see the `GetCRConfigNew` being utilized (granted we have no way of know what a client is actually utilizing.

##########
File path: docs/source/api/v1/cdns_name_snapshot.rst
##########
@@ -321,6 +321,11 @@ Response Structure
 	:date:       The UNIX epoch timestamp date in the Traffic Ops server's own timezone
 	:tm_host:    The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server
 	:tm_path:    A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN
+
+		.. deprecated:: ATCv5.1
+
+			This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4
+

Review comment:
       is there also a `cdns_name_snapshot_new.rst` for v1 that needs updating like the other versions as well?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman merged pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
zrhoffman merged pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569832137



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {
+		decoded.Stats.TMPath = new(string)
+		*decoded.Stats.TMPath = fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"])
+	}
+	api.WriteResp(w, r, decoded)

Review comment:
       Sounds good.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r567072826



##########
File path: traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql
##########
@@ -0,0 +1,23 @@
+/*
+
+    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.
+*/
+
+-- +goose Up

Review comment:
       fancy. this could probably use a comment to explain what's going on




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569813915



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
 	defer inf.Close()

Review comment:
       This constructs - but does not store - the CDN Snapshot, and returns it to the client. Other components "MUST NOT" use it because it represents what the new CDN Snapshot *would be* **if** one were taken. Components MUST use the stored Snapshot, as that is the configuration that is intended to be active.
   
   `GetCRConfigNew` itself may not be used outside of tests, but the Go client is not the only supported client of the TO API; TP uses it to display the changes to the CRConfig (ideally it would show the entire Snapshot, but that's another matter entirely) that would be made if a new Snapshot were taken, which is absolutely vital to operators.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569810639



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil)
 		return
 	}
-	w.Header().Set(rfc.ContentType, rfc.ApplicationJSON)
-	w.Write([]byte(`{"response":` + snapshot + `}`))
+
+	var decoded tc.CRConfig
+	if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err))
+	}
+
+	if inf.Version.Major < 4 {

Review comment:
       Yes, I think so. Unless we're removing that in this PR. So I'll wait to do anything until that's decided.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569813915



##########
File path: traffic_ops/traffic_ops_golang/crconfig/handler.go
##########
@@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
 	defer inf.Close()

Review comment:
       This constructs - but does not store - the CDN Snapshot, and returns it to the client. Other components "MUST NOT" use it because it represents what the new CDN Snapshot *would be* **if** one were taken. Components MUST use the stored Snapshot, as that is the configuration that is intended to be active.
   
   `GetCRConfigNew` may not be used directly, but the Go client is not the only supported client of the TO API; TP uses it to display the changes to the CRConfig (ideally it would show the entire Snapshot, but that's another matter entirely) that would be made if a new Snapshot were taken, which is absolutely vital to operators.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5475: Remove tm_path from CDN Snapshots

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5475:
URL: https://github.com/apache/trafficcontrol/pull/5475#discussion_r569878848



##########
File path: lib/go-tc/crconfig.go
##########
@@ -199,11 +199,13 @@ type CRConfigMonitor struct {
 	ServerStatus *CRConfigServerStatus `json:"status,omitempty"`
 }
 
+// CRConfigStats is the type of the 'stats' property of a CDN Snapshot.
 type CRConfigStats struct {
 	CDNName         *string `json:"CDN_name,omitempty"`
 	DateUnixSeconds *int64  `json:"date,omitempty"`
 	TMHost          *string `json:"tm_host,omitempty"`
-	TMPath          *string `json:"tm_path,omitempty"`
-	TMUser          *string `json:"tm_user,omitempty"`
-	TMVersion       *string `json:"tm_version,omitempty"`
+	// Deprecated: Don't ever use this for anything. It's been removed from APIv4 responses.

Review comment:
       Well in a sense that's been done. It's been removed from API v4, so when that's the lowest supported version it'll be gone.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org