Skip to content

Commit

Permalink
Fixes #37 | Configure consul timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
janisz committed Jan 28, 2016
1 parent 25f4d3d commit 8e143dc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ consul-ssl-cert | | Path to an SSL client certifica
consul-ssl-verify | `true` | Verify certificates when connecting via SSL
consul-token | | The Consul ACL token
consul-tag | `marathon` | Common tag name added to every service registered in Consul, should be unique for every Marathon-cluster connected to Consul
consul-timeout | `1 s` | Max request duration
listen | `:4000` | Accept connections at this address
log-level | `info` | Log level: panic, fatal, error, warn, info, or debug
log-format | `text` | Log format: JSON, text
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (config *Config) parseFlags() {
flag.StringVar(&config.Consul.SslCaCert, "consul-ssl-ca-cert", "", "Path to a CA certificate file, containing one or more CA certificates to use to validate the certificate sent by the Consul server to us")
flag.StringVar(&config.Consul.Token, "consul-token", "", "The Consul ACL token")
flag.StringVar(&config.Consul.Tag, "consul-tag", "marathon", "Common tag name added to every service registered in Consul, should be unique for every Marathon-cluster connected to Consul")
flag.DurationVar(&config.Consul.Timeout, "consul-timeout", time.Second, "Max request duration")

// Web
flag.StringVar(&config.Web.Listen, "listen", ":4000", "accept connections at this address")
Expand Down
4 changes: 3 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func TestConfig_ShouldBeMergedWithFileDefaultsAndFlags(t *testing.T) {
SslCert: "",
SslCaCert: "",
Token: "",
Tag: "marathon"},
Tag: "marathon",
Timeout: 1 * time.Second,
},
Web: struct{ Listen string }{Listen: ":4000"},
Sync: sync.Config{
Interval: 15 * time.Minute,
Expand Down
5 changes: 5 additions & 0 deletions consul/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (a *ConcurrentAgents) createAgent(host string) (*consulapi.Client, error) {
config.Scheme = "https"
}

if a.config.Timeout != 0 {
log.Debugf("Seting timeout to %s", a.config.Timeout.String())
config.HttpClient.Timeout = a.config.Timeout
}

if !a.config.SslVerify {
log.Debugf("Disabled SSL verification")
config.HttpClient.Transport = &http.Transport{
Expand Down
3 changes: 3 additions & 0 deletions consul/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package consul

import "time"

type ConsulConfig struct {
Auth Auth
Port string
Expand All @@ -9,6 +11,7 @@ type ConsulConfig struct {
SslCaCert string
Token string
Tag string
Timeout time.Duration
}

type Auth struct {
Expand Down
3 changes: 2 additions & 1 deletion consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/allegro/marathon-consul/utils"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestGetAgent_WithEmptyHost(t *testing.T) {
Expand All @@ -23,7 +24,7 @@ func TestGetAgent_FullConfig(t *testing.T) {

// given
agents := NewAgents(&ConsulConfig{Token: "token", SslEnabled: true,
Auth: Auth{Enabled: true, Username: "", Password: ""}})
Auth: Auth{Enabled: true, Username: "", Password: ""}, Timeout: time.Second})

// when
agent, err := agents.GetAgent("host")
Expand Down
3 changes: 2 additions & 1 deletion debian/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"SslCert": "",
"SslCaCert": "",
"Token": "",
"Tag": "marathon"
"Tag": "marathon",
"Timeout": 1000000000
},
"Web": {
"Listen": ":4000"
Expand Down

0 comments on commit 8e143dc

Please sign in to comment.