Skip to content

Commit

Permalink
Merge pull request #1562 from dbresson/support-query-strings-in-checks
Browse files Browse the repository at this point in the history
support query strings in checks
  • Loading branch information
diptanu committed Aug 12, 2016
2 parents 4f79c01 + e41b70c commit 0d35216
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions command/agent/consul/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,15 @@ func (c *Syncer) createCheckReg(check *structs.ServiceCheck, serviceReg *consul.
if check.Protocol == "" {
check.Protocol = "http"
}
url := url.URL{
base := url.URL{
Scheme: check.Protocol,
Host: net.JoinHostPort(host, strconv.Itoa(port)),
Path: check.Path,
}
relative, err := url.Parse(check.Path)
if err != nil {
return nil, err
}
url := base.ResolveReference(relative)
chkReg.HTTP = url.String()
case structs.ServiceCheckTCP:
chkReg.TCP = net.JoinHostPort(host, strconv.Itoa(port))
Expand Down
21 changes: 20 additions & 1 deletion command/agent/consul/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ var (
Interval: 3 * time.Second,
Timeout: 1 * time.Second,
}
check3 = structs.ServiceCheck{
Name: "check3",
Type: "http",
PortLabel: "port3",
Path: "/health?p1=1&p2=2",
Interval: 3 * time.Second,
Timeout: 1 * time.Second,
}
service1 = structs.Service{
Name: "foo-1",
Tags: []string{"tag1", "tag2"},
Expand Down Expand Up @@ -61,6 +69,7 @@ func TestCheckRegistration(t *testing.T) {
srvReg, _ := cs.createService(&service1, "domain", "key")
check1Reg, _ := cs.createCheckReg(&check1, srvReg)
check2Reg, _ := cs.createCheckReg(&check2, srvReg)
check3Reg, _ := cs.createCheckReg(&check3, srvReg)

expected := "10.10.11.5:20002"
if check1Reg.TCP != expected {
Expand All @@ -69,8 +78,14 @@ func TestCheckRegistration(t *testing.T) {

expected = "10.10.11.5:20003"
if check2Reg.TCP != expected {
t.Fatalf("expected: %v, actual: %v", expected, check1Reg.TCP)
t.Fatalf("expected: %v, actual: %v", expected, check2Reg.TCP)
}

expected = "http://10.10.11.5:20004/health?p1=1&p2=2"
if check3Reg.HTTP != expected {
t.Fatalf("expected: %v, actual: %v", expected, check3Reg.HTTP)
}

}

func TestConsulServiceRegisterServices(t *testing.T) {
Expand Down Expand Up @@ -208,6 +223,10 @@ func mockTask() *structs.Task {
Label: "port2",
Value: 20003,
},
structs.Port{
Label: "port3",
Value: 20004,
},
},
},
},
Expand Down

0 comments on commit 0d35216

Please sign in to comment.