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:
[email protected]