Skip to content

Commit

Permalink
Adding TCP proxy server
Browse files Browse the repository at this point in the history
The daemon now serves as a proxy to the X-Ray SDK for API calls that are
related to sampling rules. The proxy runs on TCP port 2000 and relays
calls to get sampling rules and report sampling statistics to X-Ray.
  • Loading branch information
Yogiraj Awati committed Aug 28, 2018
1 parent 5457699 commit 0b1d6a1
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 35 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

## 3.0.0 (2018-08-28)
- The daemon now serves as a proxy to the X-Ray SDK for API calls that are related to sampling rules. The proxy runs on TCP port 2000 and relays calls to get sampling rules and report sampling statistics to X-Ray. The TCP proxy server address can be configured from command line using `t` flag or by using `cfg.yaml` version `2` file.
- `cfg.yaml` file version is changed to `2` and has an extra attribute. The daemon supports version `1` of cfg.yaml:

## 2.1.3 (2018-06-13)
- Updated AWS SDK dependency version to `1.14.1`
- Refactored `MockTimerClient`
- Moving version number variable to `cfg` package
```
Socket:
# Change the address and port on which the daemon listens for HTTP requests to proxy to AWS X-Ray.
TCPAddress: "127.0.0.1:2000"
```
- Adds timestamp header `X-Amzn-Xray-Timestamp` to PutTraceSegments API calls made by the daemon
- Adding support for configuring `ProxyAddress` through command line: PR [#10](https://github.com/aws/aws-xray-daemon/pull/10)

## 2.1.2 (2018-05-14)
- SystemD service file updates for Debian and Linux binaries: PR [#3](https://github.com/aws/aws-xray-daemon/pull/3)
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ Usage: X-Ray [options]
1. -a --resource-arn Amazon Resource Name (ARN) of the AWS resource running the daemon.
2. -o --local-mode Don't check for EC2 instance metadata.
3. -m --buffer-memory Change the amount of memory in MB that buffers can use (minimum 3).
4. -n --region Send segments to the X-Ray service in a specific region.
5. -b --bind Overrides default UDP address (127.0.0.1:2000).
6. -r --role-arn Assume the specified IAM role to upload segments to a different account.
7. -c --config Load a configuration file from the specified path.
8. -f --log-file Output logs to the specified file path.
9. -l --log-level Log level, from most verbose to least: dev, debug, info, warn, error, prod (default).
10. -p --proxy-address Proxy address through which to upload segments.
11. -v --version Show AWS X-Ray daemon version.
12. -h --help Show this screen
4. -n --region Send segments to X-Ray service in a specific region.
5. -b --bind Overrides default UDP address (127.0.0.1:2000).
6. -t --bind-tcp Overrides default TCP address (127.0.0.1:2000).
7. -r --role-arn Assume the specified IAM role to upload segments to a different account.
8. -c --config Load a configuration file from the specified path.
9. -f --log-file Output logs to the specified file path.
10. -l --log-level Log level, from most verbose to least: dev, debug, info, warn, error, prod (default).
11. -p --proxy-address Proxy address through which to upload segments.
12. -v --version Show AWS X-Ray daemon version.
13. -h --help Show this screen

## Build

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
3.0.0
4 changes: 3 additions & 1 deletion daemon/cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Endpoint: ""
Socket:
# Change the address and port on which the daemon listens for UDP packets containing segment documents.
UDPAddress: "127.0.0.1:2000"
# Change the address and port on which the daemon listens for HTTP requests to proxy to AWS X-Ray.
TCPAddress: "127.0.0.1:2000"
Logging:
LogRotation: true
# Change the log level, from most verbose to least: dev, debug, info, warn, error, prod (default).
Expand All @@ -26,4 +28,4 @@ NoVerifySSL: false
# Upload segments to AWS X-Ray through a proxy.
ProxyAddress: ""
# Daemon configuration file format version.
Version: 1
Version: 2
38 changes: 36 additions & 2 deletions daemon/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import (
"reflect"

"github.com/aws/aws-xray-daemon/daemon/util"

"gopkg.in/yaml.v2"

log "github.com/cihub/seelog"
)

// Version number of the X-Ray daemon.
const Version = "2.1.3"
const Version = "3.0.0"

var cfgFileVersions = [...]int{1, 2} // Supported versions of cfg.yaml file.

var configLocations = []string{
"/etc/amazon/xray/cfg.yaml",
Expand Down Expand Up @@ -54,8 +57,15 @@ type Config struct {
Socket struct {
// Address and port on which the daemon listens for UDP packets containing segment documents.
UDPAddress string `yaml:"UDPAddress"`
TCPAddress string `yaml:"TCPAddress"`
} `yaml:"Socket"`

ProxyServer struct {
IdleConnTimeout int
MaxIdleConnsPerHost int
MaxIdleConns int
}

// Structure for logging.
Logging struct {
// LogRotation, if true, will rotate log after 50 MB size of current log file.
Expand Down Expand Up @@ -94,8 +104,20 @@ func DefaultConfig() *Config {
Region: "",
Socket: struct {
UDPAddress string `yaml:"UDPAddress"`
TCPAddress string `yaml:"TCPAddress"`
}{
UDPAddress: "127.0.0.1:2000",
TCPAddress: "127.0.0.1:2000",
},
ProxyServer: struct {
IdleConnTimeout int
MaxIdleConnsPerHost int
MaxIdleConns int
}{

IdleConnTimeout: 30,
MaxIdleConnsPerHost: 2,
MaxIdleConns: 0,
},
Logging: struct {
LogRotation *bool `yaml:"LogRotation"`
Expand Down Expand Up @@ -321,11 +343,23 @@ func contains(s []string, e string) bool {

func merge(configFile string) *Config {
userConfig := loadConfigFromFile(configFile)
if userConfig.Version != 1 {
versionMatch := false
for i := 0; i < len(cfgFileVersions); i++ {
if cfgFileVersions[i] == userConfig.Version {
versionMatch = true
break
}
}

if !versionMatch {
errorAndExit("Config Version Setting is not correct. Use X-Ray Daemon Config Migration Script to update the config file. Please refer to AWS X-Ray Documentation for more information.", nil)
}

userConfig.Socket.UDPAddress = getStringValue(userConfig.Socket.UDPAddress, DefaultConfig().Socket.UDPAddress)
userConfig.Socket.TCPAddress = getStringValue(userConfig.Socket.TCPAddress, DefaultConfig().Socket.TCPAddress)
userConfig.ProxyServer.IdleConnTimeout = DefaultConfig().ProxyServer.IdleConnTimeout
userConfig.ProxyServer.MaxIdleConnsPerHost = DefaultConfig().ProxyServer.MaxIdleConnsPerHost
userConfig.ProxyServer.MaxIdleConns = DefaultConfig().ProxyServer.MaxIdleConns
userConfig.TotalBufferSizeMB = getIntValue(userConfig.TotalBufferSizeMB, DefaultConfig().TotalBufferSizeMB)
userConfig.ResourceARN = getStringValue(userConfig.ResourceARN, DefaultConfig().ResourceARN)
userConfig.RoleARN = getStringValue(userConfig.RoleARN, DefaultConfig().RoleARN)
Expand Down
Loading

0 comments on commit 0b1d6a1

Please sign in to comment.