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 2020/04/30 16:03:23 UTC

[GitHub] [trafficcontrol] mattjackson220 opened a new pull request #4674: updated servers/details for multiple interfaces

mattjackson220 opened a new pull request #4674:
URL: https://github.com/apache/trafficcontrol/pull/4674


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ 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.
   -->
   
   - [x] This PR fixes #4613  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. -->
   
   - Documentation
   - Traffic Ops
   
   ## 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. -->
   
   Verify that the unit test run successfully
   Verify that the API tests run successfully for v1, v2, and v3
   Verify that /api/3.0/servers/details has the correct updated formatting for interfaces
   Verify that /api/2.0/servers/details and /api/1.5/servers/details still have the old formatting
   
   ## 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!
   
   -->
   
   - [x] This PR includes tests 
   - [x] This PR includes documentation 
   - [x] This PR includes an update to CHANGELOG.md 
   - [x] This PR includes any and all required license headers
   - [x] This PR does not include a database migration
   - [x] 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 #4674: updated servers/details for multiple interfaces

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



##########
File path: docs/source/api/v3/servers_details.rst
##########
@@ -159,7 +158,37 @@ Response Structure
 				"tcpPort": 80,
 				"type": "EDGE",
 				"xmppId": "edge",
-				"xmppPasswd": ""
+				"xmppPasswd": "",
+				"interfaces": [{
+					"ipAddresses": [
+						{
+							"address": "172.16.239.101",
+							"gateway": "",
+							"service_address": false
+						}
+					],
+						"max_bandwidth": 0,

Review comment:
       ... nvm.




----------------------------------------------------------------
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 merged pull request #4674: updated servers/details for multiple interfaces

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


   


----------------------------------------------------------------
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 #4674: updated servers/details for multiple interfaces

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



##########
File path: docs/source/api/v3/servers_details.rst
##########
@@ -159,7 +158,37 @@ Response Structure
 				"tcpPort": 80,
 				"type": "EDGE",
 				"xmppId": "edge",
-				"xmppPasswd": ""
+				"xmppPasswd": "",
+				"interfaces": [{
+					"ipAddresses": [
+						{
+							"address": "172.16.239.101",
+							"gateway": "",
+							"service_address": false
+						}
+					],
+						"max_bandwidth": 0,

Review comment:
       `go fmt`




----------------------------------------------------------------
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 #4674: updated servers/details for multiple interfaces

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



##########
File path: docs/source/api/v3/servers_details.rst
##########
@@ -73,13 +73,22 @@ Response Structure
 	:iloIpNetmask:		The IPv4 subnet mask of the server's :abbr:`ILO (Integrated Lights-Out)` service\ [1]_
 	:iloPassword:		The password of the of the server's :abbr:`ILO (Integrated Lights-Out)` service user\ [1]_ - displays as simply ``******`` if the currently logged-in user does not have the 'admin' or 'operations' :term:`Role(s) <Role>`
 	:iloUsername:		The user name for the server's :abbr:`ILO (Integrated Lights-Out)` service\ [1]_
-	:interfaceMtu:		The :abbr:`MTU (Maximum Transmission Unit)` to configured on ``interfaceName``
-	:interfaceName:		The name of the primary network interface used by the server
-	:ip6Address:		The IPv6 address and subnet mask of ``interfaceName``
-	:ip6Gateway:		The IPv6 address of the gateway used by ``interfaceName``
-	:ipAddress:		The IPv4 address of ``interfaceName``
-	:ipGateway:		The IPv4 address of the gateway used by ``interfaceName``
-	:ipNetmask:		The IPv4 subnet mask used by ``interfaceName``
+	:interfaces:     An array of interface and IP address information
+
+		:max_bandwidth:  The maximum allowed bandwidth for this interface to be considered "healthy" by Traffic Monitor. This has no effect if `monitor` is not true. Values are in kb/s. The value `0` means "no limit".
+		:monitor:        A boolean indicating if Traffic Monitor should monitor this interface
+		:mtu:            The :abbr:`MTU (Maximum Transmission Unit)` to configure for ``interfaceName``
+
+			.. seealso:: `The Wikipedia article on Maximum Transmission Unit <https://en.wikipedia.org/wiki/Maximum_transmission_unit>`_
+
+		:name:           The network interface name used by the server. A value of 'mgmt' indicates a management port.
+
+		:ipAddresses:    An array of the IP address information for the interface
+
+			:ip6Address:       The IPv4 or IPv6 address and subnet mask of the server - applicable for the interface ``name``
+			:ip6Gateway:       The IPv4 or IPv6 gateway address of the server - applicable for the interface ``name``

Review comment:
       Field names incorrect




----------------------------------------------------------------
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 #4674: updated servers/details for multiple interfaces

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



##########
File path: lib/go-tc/servers.go
##########
@@ -43,12 +47,113 @@ type ServersV1Response struct {
 	Alerts
 }
 
+type ServerDetailV11 struct {
+	ServerDetail
+	LegacyInterfaceDetails
+}
+
+// ServerDetailV30 is the details for a server for API v3
+type ServerDetailV30 struct {
+	ServerDetail
+	ServerInterfaces *[]ServerInterfaceInfo `json:"interfaces"`
+}
+
 // ServersV1DetailResponse is the JSON object returned for a single server for v1.
 type ServersV1DetailResponse struct {
-	Response ServerV1 `json:"response"`
+	Response []ServerDetailV11 `json:"response"`
+	Alerts
+}
+
+// ServersV3DetailResponse is the JSON object returned for a single server for v3.
+type ServersV3DetailResponse struct {
+	Response []ServerDetailV30 `json:"response"`
 	Alerts
 }
 
+// ServerIpAddress is the data associated with a server's interface's IP address.
+type ServerIpAddress struct {
+	Address        string  `json:"address" db:"address"`
+	Gateway        *string `json:"gateway" db:"gateway"`
+	Interface      string  `json:"interface,omitempty" db:"interface"`
+	Server         uint64  `json:"server,omitempty" db:"server"`

Review comment:
       Is it necessary to include these two fields? My `/servers` implementation never used them (and my `ServerIpAddress` struct doesn't have them).

##########
File path: traffic_ops/traffic_ops_golang/server/detail.go
##########
@@ -145,43 +182,56 @@ func getDetailServers(tx *sql.Tx, user *auth.CurrentUser, hostName string, physL
 	}
 	const JumboFrameBPS = 9000
 	q := `
-SELECT
-cg.name as cachegroup,
-cdn.name as cdn_name,
-ARRAY(select deliveryservice from deliveryservice_server where server = s.id),
-s.domain_name,
-s.guid,
-s.host_name,
-s.https_port,
-s.id,
-s.ilo_ip_address,
-s.ilo_ip_gateway,
-s.ilo_ip_netmask,
-s.ilo_password,
-s.ilo_username,
-COALESCE(s.interface_mtu, ` + strconv.Itoa(JumboFrameBPS) + `) as interface_mtu,
-s.interface_name,
-s.ip6_address,
-s.ip6_gateway,
-s.ip_address,
-s.ip_gateway,
-s.ip_netmask,
-s.mgmt_ip_address,
-s.mgmt_ip_gateway,
-s.mgmt_ip_netmask,
-s.offline_reason,
-pl.name as phys_location,
-p.name as profile,
-p.description as profile_desc,
-s.rack,
-s.router_host_name,
-s.router_port_name,
-st.name as status,
-s.tcp_port,
-t.name as server_type,
-s.xmpp_id,
-s.xmpp_passwd
-FROM server as s
+SELECT 
+	cg.name AS cachegroup,
+	cdn.name AS cdn_name,
+	ARRAY(select deliveryservice from deliveryservice_server where server = s.id),
+	s.domain_name,
+	s.guid,
+	s.host_name,
+	s.https_port,
+	s.id,
+	s.ilo_ip_address,
+	s.ilo_ip_gateway,
+	s.ilo_ip_netmask,
+	s.ilo_password,
+	s.ilo_username,
+	ARRAY (
+SELECT ( json_build_object (
+'ipAddresses', ARRAY (
+SELECT ( json_build_object (
+'address', ip_address.address,
+'gateway', ip_address.gateway,
+'service_address', ip_address.service_address
+))
+FROM ip_address
+WHERE ip_address.interface = interface.name
+AND ip_address.server = s.id
+),
+'max_bandwidth', interface.max_bandwidth,
+'monitor', interface.monitor,
+'mtu', COALESCE (interface.mtu, 9000),
+'name', interface.name
+))
+FROM interface
+WHERE interface.server = s.id
+) AS interfaces,

Review comment:
       Is there anything you can do about this formatting? It's pretty hard to read.

##########
File path: traffic_ops/v2-client/server.go
##########
@@ -186,6 +187,24 @@ func (to *Session) GetServerByHostName(hostName string) ([]tc.Server, ReqInf, er
 	return data.Response, reqInf, nil
 }
 
+// GetServerDetailsByHostName GETs Servers by the Server hostname.
+func (to *Session) GetServerDetailsByHostName(hostName string) ([]tc.ServerDetailV11, ReqInf, error) {
+	url := fmt.Sprintf("%s?hostName=%s", API_SERVERS_DETAILS, hostName)

Review comment:
       same as above RE: url-encoding

##########
File path: lib/go-tc/servers.go
##########
@@ -43,12 +47,113 @@ type ServersV1Response struct {
 	Alerts
 }
 
+type ServerDetailV11 struct {
+	ServerDetail
+	LegacyInterfaceDetails
+}
+
+// ServerDetailV30 is the details for a server for API v3
+type ServerDetailV30 struct {
+	ServerDetail
+	ServerInterfaces *[]ServerInterfaceInfo `json:"interfaces"`
+}
+
 // ServersV1DetailResponse is the JSON object returned for a single server for v1.
 type ServersV1DetailResponse struct {
-	Response ServerV1 `json:"response"`
+	Response []ServerDetailV11 `json:"response"`
+	Alerts
+}
+
+// ServersV3DetailResponse is the JSON object returned for a single server for v3.
+type ServersV3DetailResponse struct {
+	Response []ServerDetailV30 `json:"response"`
 	Alerts
 }
 
+// ServerIpAddress is the data associated with a server's interface's IP address.
+type ServerIpAddress struct {
+	Address        string  `json:"address" db:"address"`
+	Gateway        *string `json:"gateway" db:"gateway"`
+	Interface      string  `json:"interface,omitempty" db:"interface"`
+	Server         uint64  `json:"server,omitempty" db:"server"`
+	ServiceAddress bool    `json:"serviceAddress" db:"service_address"`
+}
+
+// ServerInterfaceInfo is the data associated with a server's interface.
+type ServerInterfaceInfo struct {
+	IpAddresses  []ServerIpAddress `json:"ipAddresses" db:"ipAddresses"`
+	MaxBandwidth *int64            `json:"maxBandwidth" db:"max_bandwidth"`
+	Monitor      bool              `json:"monitor" db:"monitor"`
+	MTU          *uint64           `json:"mtu" db:"mtu"`
+	Name         string            `json:"name" db:"name"`
+}
+
+// Value implements the database/sql/driver.Valuer interface.
+// marshals struct to json to pass back as a json.RawMessage
+func (sii *ServerInterfaceInfo) Value() (driver.Value, error) {
+	b, err := json.Marshal(sii)
+	return b, err
+}
+
+// Scan implements the sql.Scanner interface
+// expects json.RawMessage and unmarshals to a deliveryservice struct
+func (sii *ServerInterfaceInfo) Scan(src interface{}) error {
+	b, ok := src.([]byte)
+	if !ok {
+		return fmt.Errorf("expected deliveryservice in byte array form; got %T", src)
+	}
+
+	return json.Unmarshal([]byte(b), sii)
+}
+
+// LegacyInterfaceDetails is the details for interfaces on servers for API v1 and v2.
+type LegacyInterfaceDetails struct {
+	InterfaceMtu  *int    `json:"interfaceMtu" db:"interface_mtu"`
+	InterfaceName *string `json:"interfaceName" db:"interface_name"`
+	IP6Address    *string `json:"ip6Address" db:"ip6_address"`
+	IP6Gateway    *string `json:"ip6Gateway" db:"ip6_gateway"`
+	IPAddress     *string `json:"ipAddress" db:"ip_address"`
+	IPGateway     *string `json:"ipGateway" db:"ip_gateway"`
+	IPNetmask     *string `json:"ipNetmask" db:"ip_netmask"`
+}
+
+// InterfaceInfoToLegacyInterfaces converts a ServerInterfaceInfo to an
+// equivalent LegacyInterfaceDetails structure. It does this by creating the
+// IP address fields using the "service" interface's IP addresses. All others
+// are discarded, as the legacy format is incapable of representing them.
+func InterfaceInfoToLegacyInterfaces(serverInterfaces []ServerInterfaceInfo) (LegacyInterfaceDetails, error) {
+	var legacyDetails LegacyInterfaceDetails
+
+	for _, intFace := range serverInterfaces {
+		if intFace.MTU != nil {
+			legacyDetails.InterfaceMtu = util.IntPtr(int(*intFace.MTU))
+		}
+
+		legacyDetails.InterfaceName = &intFace.Name
+
+		for _, addr := range intFace.IpAddresses {
+			address := addr.Address

Review comment:
       The returned IP addresses should only be the server's service addresses, otherwise if operators migrate their management interfaces into the new system they will run the risk of occasionally returning management interface details as if they were the actual service IPs of the server.
   
   My implementation uses a check right here and skips the IP if it is not a service IP.

##########
File path: traffic_ops/client/server.go
##########
@@ -186,6 +187,24 @@ func (to *Session) GetServerByHostName(hostName string) ([]tc.Server, ReqInf, er
 	return data.Response, reqInf, nil
 }
 
+// GetServerDetailsByHostName GETs Servers by the Server hostname.
+func (to *Session) GetServerDetailsByHostName(hostName string) ([]tc.ServerDetailV30, ReqInf, error) {
+	url := fmt.Sprintf("%s?hostName=%s", API_SERVERS_DETAILS, hostName)

Review comment:
       same as above RE: url-encoding

##########
File path: traffic_ops/v1-client/server.go
##########
@@ -187,6 +188,24 @@ func (to *Session) GetServerByHostName(hostName string) ([]tc.ServerV1, ReqInf,
 	return data.Response, reqInf, nil
 }
 
+// GetServerDetailsByHostName GETs Servers by the Server hostname.
+func (to *Session) GetServerDetailsByHostName(hostName string) ([]tc.ServerDetailV11, ReqInf, error) {
+	url := fmt.Sprintf("%s?hostName=%s", API_SERVERS_DETAILS, hostName)

Review comment:
       hostName needs to be URL-encoded.




----------------------------------------------------------------
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] shamrickus commented on a change in pull request #4674: updated servers/details for multiple interfaces

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



##########
File path: traffic_ops/traffic_ops_golang/server/detail.go
##########
@@ -92,16 +114,36 @@ func GetDetailParamHandler(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 	}
-	servers, err := getDetailServers(inf.Tx.Tx, inf.User, hostName, physLocationID, util.CamelToSnakeCase(orderBy), limit)
+	servers, err := getDetailServers(inf.Tx.Tx, inf.User, hostName, physLocationID, util.CamelToSnakeCase(orderBy), limit, *inf.Version)
 	respVals := map[string]interface{}{
 		"orderby": orderBy,
 		"limit":   limit,
 		"size":    len(servers),
 	}
+
+	if inf.Version.Major < 3 {
+		v11ServerList := []tc.ServerDetailV11{}
+		for _, server := range servers {

Review comment:
       Can extract this for loop to a function for reuse  (such as on line 57).  Alternatively, the version on line 57 can be optimized to break after the first iteration (or something to that affect) as the consequent iterations do not appear to have any affect.

##########
File path: docs/source/api/v3/servers_details.rst
##########
@@ -159,7 +158,37 @@ Response Structure
 				"tcpPort": 80,
 				"type": "EDGE",
 				"xmppId": "edge",
-				"xmppPasswd": ""
+				"xmppPasswd": "",
+				"interfaces": [{
+					"ipAddresses": [
+						{
+							"address": "172.16.239.101",
+							"gateway": "",
+							"service_address": false
+						}
+					],
+						"max_bandwidth": 0,

Review comment:
       Inconsistent spacing with line 186

##########
File path: lib/go-tc/servers.go
##########
@@ -286,3 +315,88 @@ type ServerQueueUpdate struct {
 	ServerID util.JSONIntStr `json:"serverId"`
 	Action   string          `json:"action"`
 }
+
+// ServerInterface is the data associated with an interface
+type ServerInterface struct {

Review comment:
       This struct doesn't appear to have any usages (across the entire repo)




----------------------------------------------------------------
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 pull request #4674: updated servers/details for multiple interfaces

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on pull request #4674:
URL: https://github.com/apache/trafficcontrol/pull/4674#issuecomment-625471860


   This has to wait for the migration to be in first, then probably gonna need to rebase.


----------------------------------------------------------------
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