Skip to content

Commit

Permalink
Add haproxy prefix where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Dubicki committed Jun 3, 2020
1 parent 2c7e3dd commit 5c55e55
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (h *HAProxy) start(sd *lib.Shutdown) error {
}
h.haConfig = hc

if h.opts.LogAddress == "" {
if h.opts.HAProxyLogAddress == "" {
err := h.startLogger()
if err != nil {
return err
}
} else {
log.Infof("not starting built-in syslog - using %s as syslog address", h.opts.LogAddress)
log.Infof("not starting built-in syslog - using %s as syslog address", h.opts.HAProxyLogAddress)
}

if h.opts.EnableIntentions {
Expand All @@ -79,7 +79,7 @@ func (h *HAProxy) start(sd *lib.Shutdown) error {
dpc, err := haproxy_cmd.Start(sd, haproxy_cmd.Config{
HAProxyPath: h.opts.HAProxyBin,
HAProxyConfigPath: hc.HAProxy,
HAProxyLogWithThisApp: h.opts.LogAddress == "",
HAProxyLogWithThisApp: h.opts.HAProxyLogAddress == "",
DataplanePath: h.opts.DataplaneBin,
DataplaneTransactionDir: hc.DataplaneTransactionDir,
DataplaneSock: hc.DataplaneSock,
Expand Down
4 changes: 2 additions & 2 deletions haproxy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ type Options struct {
EnableIntentions bool
StatsListenAddr string
StatsRegisterService bool
LogRequests bool
LogAddress string
HAProxyLogRequests bool
HAProxyLogAddress string
}
6 changes: 3 additions & 3 deletions haproxy/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ func (h *HAProxy) watch(sd *lib.Shutdown) error {
newConsulCfg := nextState.Load().(consul.Config)

logAddress := h.haConfig.LogsSock
if h.opts.LogAddress != "" {
logAddress = h.opts.LogAddress
if h.opts.HAProxyLogAddress != "" {
logAddress = h.opts.HAProxyLogAddress
}

newState, err := state.Generate(state.Options{
EnableIntentions: h.opts.EnableIntentions,
LogRequests: h.opts.LogRequests,
LogRequests: h.opts.HAProxyLogRequests,
LogAddress: logAddress,
SPOEConfigPath: h.haConfig.SPOE,
SPOESocket: h.haConfig.SPOESock,
Expand Down
18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func validateRequirements(dataplaneBin, haproxyBin string) error {
}

// HAproxy doesn't exit immediately when you pass incorrect log address, so we try to do it on our own to fail fast
func validateLogAddress(logAddress string) error {
// possible values taken from https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-log
func validateHaproxyLogAddress(logAddress string) error {
// allowed values taken from https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-log
fi, err := os.Stat(logAddress)
if err != nil {
match, err := regexp.Match(`(fd@<[0-9]+>|stdout|stderr)`, []byte(logAddress))
Expand All @@ -84,15 +84,15 @@ func validateLogAddress(logAddress string) error {

func main() {
versionFlag := flag.Bool("version", false, "Show version and exit")
logLevel := flag.String("log-level", "INFO", "Log level")
logRequests := flag.Bool("log-requests", false, "Enable logging requests by Haproxy")
logAddress := flag.String("log-address", "", "Syslog address for Haproxy logs (default: log to stderr with this app)")
consulAddr := flag.String("http-addr", "127.0.0.1:8500", "Consul agent address")
service := flag.String("sidecar-for", "", "The consul service id to proxy")
serviceTag := flag.String("sidecar-for-tag", "", "The consul service id to proxy")
haproxyBin := flag.String("haproxy", haproxy_cmd.DefaultHAProxyBin, "Haproxy binary path")
dataplaneBin := flag.String("dataplane", haproxy_cmd.DefaultDataplaneBin, "Dataplane binary path")
haproxyCfgBasePath := flag.String("haproxy-cfg-base-path", "/tmp", "Haproxy binary path")
haproxyLogRequests := flag.Bool("haproxy-log-requests", false, "Enable logging requests by Haproxy")
haproxyLogAddress := flag.String("haproxy-log-address", "", "Syslog address for Haproxy logs (default: log to stderr with this app)")
logLevel := flag.String("log-level", "INFO", "Log level")
statsListenAddr := flag.String("stats-addr", "", "Listen addr for stats server")
statsServiceRegister := flag.Bool("stats-service-register", false, "Register a consul service for connect stats")
enableIntentions := flag.Bool("enable-intentions", false, "Enable Connect intentions")
Expand All @@ -114,8 +114,8 @@ func main() {
}
log.SetLevel(ll)

if *logAddress != "" {
if err := validateLogAddress(*logAddress); err != nil {
if *haproxyLogAddress != "" {
if err := validateHaproxyLogAddress(*haproxyLogAddress); err != nil {
log.Fatal(err)
}
}
Expand Down Expand Up @@ -175,8 +175,8 @@ func main() {
EnableIntentions: *enableIntentions,
StatsListenAddr: *statsListenAddr,
StatsRegisterService: *statsServiceRegister,
LogRequests: *logRequests,
LogAddress: *logAddress,
HAProxyLogRequests: *haproxyLogRequests,
HAProxyLogAddress: *haproxyLogAddress,
})
sd.Add(1)
go func() {
Expand Down

0 comments on commit 5c55e55

Please sign in to comment.