This is an automated email from the ASF dual-hosted git repository.

rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 5cc9fd9  Adds support for querying Traffic Monitors via a caching 
Proxy server. (#6320)
5cc9fd9 is described below

commit 5cc9fd90f7425ee5ed2705d09d82f099a1d7eead
Author: John J. Rushford <[email protected]>
AuthorDate: Tue Nov 2 16:56:40 2021 -0600

    Adds support for querying Traffic Monitors via a caching Proxy server. 
(#6320)
    
    - 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.
---
 tc-health-client/README.md             | 16 +++++++++-------
 tc-health-client/config/config.go      | 18 ++++++++++++++++++
 tc-health-client/tc-health-client.json |  1 +
 tc-health-client/tmagent/tmagent.go    |  6 ++++++
 traffic_monitor/tmclient/tmclient.go   |  8 ++++++--
 5 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/tc-health-client/README.md b/tc-health-client/README.md
index 326d68c..90702e9 100644
--- a/tc-health-client/README.md
+++ b/tc-health-client/README.md
@@ -1,9 +1,3 @@
-% tc-health-client(1) tc-health-client 6.1.0 | ATC tc-health-client Manual
-%
-% 2021-09-20
-% tc-health-client(1) tc-health-client 6.1.0 
-%
-% 2021-09-17
 <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -109,6 +103,7 @@ Sample configuarion file:
     "to-url": "https://tp.cdn.com:443";, 
     "to-request-timeout-seconds": "5s",
     "tm-poll-interval-seconds": "60s",
+    "tm-proxy-url", "http://sample-http-proxy.cdn.net:80";,
     "tm-update-cycles": 5,
     "trafficserver-config-dir": "/opt/trafficserver/etc/trafficserver",
     "trafficserver-bin-dir": "/opt/trafficserver/bin",
@@ -154,6 +149,13 @@ Sample configuarion file:
   The polling interval in seconds used to update **Traffic Server** parent
   status.
 
+### tm-proxy-url
+
+  If not nil, all Traffic Monitor requests will be proxied through this 
+  proxy endpoint.  This is useful when there are large numbers of caches
+  polling a Traffic Monitor and you wish to funnel queries through a caching
+  proxy server to limit direct direct connections to Traffic Monitor.
+
 ### tm-update-cycles
 
   Each time a polling cycle completes a count is incremented. When the count
@@ -181,4 +183,4 @@ Sample configuarion file:
 * Traffic Server **strategies.yaml**
 * Traffic Server **traffic_ctl** command
   
-   
\ No newline at end of file
+   
diff --git a/tc-health-client/config/config.go 
b/tc-health-client/config/config.go
index dd14e8b..e35f3d7 100644
--- a/tc-health-client/config/config.go
+++ b/tc-health-client/config/config.go
@@ -60,6 +60,7 @@ type Cfg struct {
        TOPass                  string          `json:"to-pass"`
        TOUrl                   string          `json:"to-url"`
        TOUser                  string          `json:"to-user"`
+       TmProxyURL              string          `json:"tm-proxy-url"`
        TmPollIntervalSeconds   string          
`json:"tm-poll-interval-seconds"`
        TmUpdateCycles          int             `json:"tm-update-cycles"`
        TrafficServerConfigDir  string          
`json:"trafficserver-config-dir"`
@@ -67,6 +68,7 @@ type Cfg struct {
        TrafficMonitors         map[string]bool 
`json:"trafficmonitors,omitempty"`
        HealthClientConfigFile  util.ConfigFile
        CredentialFile          util.ConfigFile
+       ParsedProxyURL          *url.URL
 }
 
 type LogCfg struct {
@@ -328,6 +330,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 cfg.ParsedProxyURL, err = url.Parse(cfg.TmProxyURL); 
err != nil {
+                               cfg.ParsedProxyURL = nil
+                               return false, errors.New("parsing TmProxyUrl: " 
+ err.Error())
+                       }
+                       if cfg.ParsedProxyURL.Port() == "" {
+                               cfg.ParsedProxyURL = nil
+                               return false, errors.New("TmProxyUrl invalid 
port specified")
+                       }
+                       log.Infof("TM queries will use the proxy: %s", 
cfg.TmProxyURL)
+               } else {
+                       cfg.ParsedProxyURL = nil
+               }
                updated = true
        }
        return updated, nil
diff --git a/tc-health-client/tc-health-client.json 
b/tc-health-client/tc-health-client.json
index 8df62f6..501f6b7 100644
--- a/tc-health-client/tc-health-client.json
+++ b/tc-health-client/tc-health-client.json
@@ -5,6 +5,7 @@
   "to-credential-file": "/etc/credentials",
   "to-url": "https://tp.cdn.com:443";, 
   "to-request-timeout-seconds": "5s",
+  "tm-proxy-url":, "proxy.net:80",
   "tm-poll-interval-seconds": "15s",
   "tm-update-cycles": 5,
   "trafficserver-config-dir": "/opt/trafficserver/etc/trafficserver",
diff --git a/tc-health-client/tmagent/tmagent.go 
b/tc-health-client/tmagent/tmagent.go
index cc9710c..a922bf7 100644
--- a/tc-health-client/tmagent/tmagent.go
+++ b/tc-health-client/tmagent/tmagent.go
@@ -27,6 +27,7 @@ import (
        "io/ioutil"
        "math/rand"
        "net"
+       "net/http"
        "os"
        "os/exec"
        "path/filepath"
@@ -245,6 +246,11 @@ func (c *ParentInfo) GetCacheStatuses() 
(map[tc.CacheName]datareq.CacheStatus, e
        }
        tmc := tmclient.New("http://"+tmHostName, config.GetRequestTimeout())
 
+       // Use a proxy to query TM if the ProxyURL is set
+       if c.Cfg.ParsedProxyURL != nil {
+               tmc.Transport = &http.Transport{Proxy: 
http.ProxyURL(c.Cfg.ParsedProxyURL)}
+       }
+
        return tmc.CacheStatuses()
 }
 
diff --git a/traffic_monitor/tmclient/tmclient.go 
b/traffic_monitor/tmclient/tmclient.go
index 732a52e..3837cd8 100644
--- a/traffic_monitor/tmclient/tmclient.go
+++ b/traffic_monitor/tmclient/tmclient.go
@@ -38,8 +38,9 @@ import (
 )
 
 type TMClient struct {
-       url     string
-       timeout time.Duration
+       url       string
+       timeout   time.Duration
+       Transport *http.Transport // optional http Transport
 }
 
 func New(url string, timeout time.Duration) *TMClient {
@@ -198,6 +199,9 @@ 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}
+       if c.Transport != nil {
+               httpClient.Transport = c.Transport
+       }
        resp, err := httpClient.Get(url)
        if err != nil {
                return nil, errors.New("getting from '" + url + "': " + 
err.Error())

Reply via email to