Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 5cc9fd9

Browse files
authored
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.
1 parent 46f2f93 commit 5cc9fd9

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

tc-health-client/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
% tc-health-client(1) tc-health-client 6.1.0 | ATC tc-health-client Manual
2-
%
3-
% 2021-09-20
4-
% tc-health-client(1) tc-health-client 6.1.0
5-
%
6-
% 2021-09-17
71
<!--
82
Licensed to the Apache Software Foundation (ASF) under one
93
or more contributor license agreements. See the NOTICE file
@@ -109,6 +103,7 @@ Sample configuarion file:
109103
"to-url": "https://tp.cdn.com:443",
110104
"to-request-timeout-seconds": "5s",
111105
"tm-poll-interval-seconds": "60s",
106+
"tm-proxy-url", "http://sample-http-proxy.cdn.net:80",
112107
"tm-update-cycles": 5,
113108
"trafficserver-config-dir": "/opt/trafficserver/etc/trafficserver",
114109
"trafficserver-bin-dir": "/opt/trafficserver/bin",
@@ -154,6 +149,13 @@ Sample configuarion file:
154149
The polling interval in seconds used to update **Traffic Server** parent
155150
status.
156151

152+
### tm-proxy-url
153+
154+
If not nil, all Traffic Monitor requests will be proxied through this
155+
proxy endpoint. This is useful when there are large numbers of caches
156+
polling a Traffic Monitor and you wish to funnel queries through a caching
157+
proxy server to limit direct direct connections to Traffic Monitor.
158+
157159
### tm-update-cycles
158160

159161
Each time a polling cycle completes a count is incremented. When the count
@@ -181,4 +183,4 @@ Sample configuarion file:
181183
* Traffic Server **strategies.yaml**
182184
* Traffic Server **traffic_ctl** command
183185

184-
186+

tc-health-client/config/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ type Cfg struct {
6060
TOPass string `json:"to-pass"`
6161
TOUrl string `json:"to-url"`
6262
TOUser string `json:"to-user"`
63+
TmProxyURL string `json:"tm-proxy-url"`
6364
TmPollIntervalSeconds string `json:"tm-poll-interval-seconds"`
6465
TmUpdateCycles int `json:"tm-update-cycles"`
6566
TrafficServerConfigDir string `json:"trafficserver-config-dir"`
6667
TrafficServerBinDir string `json:"trafficserver-bin-dir"`
6768
TrafficMonitors map[string]bool `json:"trafficmonitors,omitempty"`
6869
HealthClientConfigFile util.ConfigFile
6970
CredentialFile util.ConfigFile
71+
ParsedProxyURL *url.URL
7072
}
7173

7274
type LogCfg struct {
@@ -328,6 +330,22 @@ func LoadConfig(cfg *Cfg) (bool, error) {
328330
if cfg.TOCredentialFile != "" {
329331
cfg.CredentialFile.Filename = cfg.TOCredentialFile
330332
}
333+
334+
// if tm-proxy-url is set in the config, verify the proxy
335+
// url
336+
if cfg.TmProxyURL != "" {
337+
if cfg.ParsedProxyURL, err = url.Parse(cfg.TmProxyURL); err != nil {
338+
cfg.ParsedProxyURL = nil
339+
return false, errors.New("parsing TmProxyUrl: " + err.Error())
340+
}
341+
if cfg.ParsedProxyURL.Port() == "" {
342+
cfg.ParsedProxyURL = nil
343+
return false, errors.New("TmProxyUrl invalid port specified")
344+
}
345+
log.Infof("TM queries will use the proxy: %s", cfg.TmProxyURL)
346+
} else {
347+
cfg.ParsedProxyURL = nil
348+
}
331349
updated = true
332350
}
333351
return updated, nil

tc-health-client/tc-health-client.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"to-credential-file": "/etc/credentials",
66
"to-url": "https://tp.cdn.com:443",
77
"to-request-timeout-seconds": "5s",
8+
"tm-proxy-url":, "proxy.net:80",
89
"tm-poll-interval-seconds": "15s",
910
"tm-update-cycles": 5,
1011
"trafficserver-config-dir": "/opt/trafficserver/etc/trafficserver",

tc-health-client/tmagent/tmagent.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"io/ioutil"
2828
"math/rand"
2929
"net"
30+
"net/http"
3031
"os"
3132
"os/exec"
3233
"path/filepath"
@@ -245,6 +246,11 @@ func (c *ParentInfo) GetCacheStatuses() (map[tc.CacheName]datareq.CacheStatus, e
245246
}
246247
tmc := tmclient.New("http://"+tmHostName, config.GetRequestTimeout())
247248

249+
// Use a proxy to query TM if the ProxyURL is set
250+
if c.Cfg.ParsedProxyURL != nil {
251+
tmc.Transport = &http.Transport{Proxy: http.ProxyURL(c.Cfg.ParsedProxyURL)}
252+
}
253+
248254
return tmc.CacheStatuses()
249255
}
250256

traffic_monitor/tmclient/tmclient.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ import (
3838
)
3939

4040
type TMClient struct {
41-
url string
42-
timeout time.Duration
41+
url string
42+
timeout time.Duration
43+
Transport *http.Transport // optional http Transport
4344
}
4445

4546
func New(url string, timeout time.Duration) *TMClient {
@@ -198,6 +199,9 @@ func (c *TMClient) ConfigDoc() (handler.OpsConfig, error) {
198199
func (c *TMClient) getBytes(path string) ([]byte, error) {
199200
url := c.url + path
200201
httpClient := http.Client{Timeout: c.timeout}
202+
if c.Transport != nil {
203+
httpClient.Transport = c.Transport
204+
}
201205
resp, err := httpClient.Get(url)
202206
if err != nil {
203207
return nil, errors.New("getting from '" + url + "': " + err.Error())

0 commit comments

Comments
 (0)