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/11/01 23:11:48 UTC

[GitHub] [trafficcontrol] jrushford opened a new pull request #6320: Adds support for querying Traffic Monitors via a caching Proxy server.

jrushford opened a new pull request #6320:
URL: https://github.com/apache/trafficcontrol/pull/6320


   Adds support for querying Traffic Monitors via a caching Proxy server.
   
   - adds a tm-proxy-url config property
   - updates the traffic_monitor/tmclient to use an optional http.Transport
     object needed to support an Http Proxy.
   
   ## Which Traffic Control components are affected by this PR?
   
   - Traffic Control Health Client (tc-health-client)
   
   ## What is the best way to verify this PR?
   
   On an edge cache, configure the tc-health-client to run with the tm-proxy-url set in the /etc/trafficcontrol/tc-health-client.json config file.  With the proxy server configured to proxy traffic monitor requests from the health-client, verify traffic monitor requests are successful, see /var/log/trafficcontrol/tc-health-client.log
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   
   ## PR submission checklist
   - [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [x] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Ah, I see, because `ProxyURL` is a global variable, if `LoadConfig` is called twice it'll be different.
   This is why I don't like Global Variables. But yes, you're right, disregard my comment.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Nitpick: the `ProxyURL` is already nil, and nothing outside this `if` changes it, so the `else { ProxyURL = nil` isn't necessary




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Nitpick: the httpClient `Transport` is nil by default here, so the `if` check isn't necessary




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c it's needed so as not to eliminate the Default Transport.  It overrides the Default Transport with the one created for using a proxy.  If I use this without the nil check, the default Transport is eliminated and the TM integrations tests fail:
   
   httpClient := http.Client{Timeout: c.timeout, Transport: c.Transport}




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Nitpick: the httpClient `Transport` is nil by default here, so the `if` check isn't necessary

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Nitpick: the `ProxyURL` is already nil, and nothing outside this `if` changes it, so the `else { ProxyURL = nil` isn't necessary

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Ah, I see, because `ProxyURL` is a global variable, if `LoadConfig` is called twice it'll be different.
   This is why I don't like Global Variables. But yes, you're right, disregard my comment.

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Right, I was just saying, it technically doesn't need the "if", `httpClient := http.Client{Timeout: c.timeout, Transport: c.Transport}` does exactly the same thing.
   
   But it was just a nitpick, not a big deal to leave it. It's an extremely minor readability and performance improvement




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one when using a Proxy.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       @rob05c When the config is reloaded and the tm-proxy-url parameter has been removed, the ProxyURL is set to nil and no proxy will be used the next time a TM is queried.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c merged pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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


   


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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c merged pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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


   


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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one to the TMClient which is what's done when using a Proxy.

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one when using a Proxy.

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       @rob05c When the config is reloaded and the tm-proxy-url parameter has been removed, the ProxyURL is set to nil and no proxy will be used the next time a TM is queried.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Ah, because `TMClient.Transport` a `*http.Transport` and `http.Client` is a `http.RoundTripper`, there's an implicit cast happening, and it's creating a non-nil interface pointing to a nil pointer. Which is where the weirdness and test failure is coming from.
   
   If `TMClient.Transport` was a `RoundTripper` it'd avoid the cast, and work as-expected. But interfaces are really pointers, and pointers-to-pointers where the outer interface pointer is non-nil with an object that's a nil pointer get weird.
   
   That's fine, I'd just leave it. Sorry, I wouldn't have suggested it if I'd noticed the types were different. Non-nil interfaces with potentially nil objects are one of Go's pain points, not worth dealing with.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Right, I was just saying, it technically doesn't need the "if", `httpClient := http.Client{Timeout: c.timeout, Transport: c.Transport}` does exactly the same thing.
   
   But it was just a nitpick, not a big deal to leave it. It's an extremely minor readability and performance improvement




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one to the TMClient which is what's done when using a Proxy.




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Nitpick: the httpClient `Transport` is nil by default here, so the `if` check isn't necessary

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Nitpick: the `ProxyURL` is already nil, and nothing outside this `if` changes it, so the `else { ProxyURL = nil` isn't necessary

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       Ah, I see, because `ProxyURL` is a global variable, if `LoadConfig` is called twice it'll be different.
   This is why I don't like Global Variables. But yes, you're right, disregard my comment.

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       Right, I was just saying, it technically doesn't need the "if", `httpClient := http.Client{Timeout: c.timeout, Transport: c.Transport}` does exactly the same thing.
   
   But it was just a nitpick, not a big deal to leave it. It's an extremely minor readability and performance improvement




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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



[GitHub] [trafficcontrol] jrushford commented on a change in pull request #6320: Adds support to the tc-health-client for querying Traffic Monitors via a caching Proxy server.

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



##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one to the TMClient which is what's done when using a Proxy.

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c I added this so that I can inject an http.Transport into the httpClient.  I only want to inject an http.Transport when I've created and added one when using a Proxy.

##########
File path: tc-health-client/config/config.go
##########
@@ -328,6 +331,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
 		if cfg.TOCredentialFile != "" {
 			cfg.CredentialFile.Filename = cfg.TOCredentialFile
 		}
+
+		// if tm-proxy-url is set in the config, verify the proxy
+		// url
+		if cfg.TmProxyURL != "" {
+			if ProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
+				ProxyURL = nil
+				return false, errors.New("parsing TmProxyUrl: " + err.Error())
+			}
+			if ProxyURL.Port() == "" {
+				ProxyURL = nil
+				return false, errors.New("TmProxyUrl invalid port specified")
+			}
+			log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
+		} else {

Review comment:
       @rob05c When the config is reloaded and the tm-proxy-url parameter has been removed, the ProxyURL is set to nil and no proxy will be used the next time a TM is queried.

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c it's needed so as not to eliminate the Default Transport.  It overrides the Default Transport with the one created for using a proxy.  If I use this without the nil check, the default Transport is eliminated and the TM integrations tests fail:
   
   httpClient := http.Client{Timeout: c.timeout, Transport: c.Transport}

##########
File path: traffic_monitor/tmclient/tmclient.go
##########
@@ -198,6 +199,10 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
 func (c *TMClient) getBytes(path string) ([]byte, error) {
 	url := c.url + path
 	httpClient := http.Client{Timeout: c.timeout}
+	// add the http.Transport object if specified.
+	if c.Transport != nil {

Review comment:
       @rob05c it's needed so as not to clobber the Default Transport.  It overrides the Default Transport with the one created for using a proxy when needed.  If I use this without the nil check, the default Transport is clobbered  and the TM integrations tests panic and fail:
   




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

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

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