From e191b0e1987e1507c4ad7252630be3e6e81de7b7 Mon Sep 17 00:00:00 2001 From: David Bresson Date: Wed, 10 Aug 2016 18:27:19 -0700 Subject: [PATCH 1/3] Add support for query strings in check paths --- command/agent/consul/syncer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/agent/consul/syncer.go b/command/agent/consul/syncer.go index 75d07120cb5..3accecc64d3 100644 --- a/command/agent/consul/syncer.go +++ b/command/agent/consul/syncer.go @@ -703,11 +703,11 @@ 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, } + url := base.ResolveReference(url.Parse(check.Path)) chkReg.HTTP = url.String() case structs.ServiceCheckTCP: chkReg.TCP = net.JoinHostPort(host, strconv.Itoa(port)) From 7a78bf48360ce4022dd591243f2ce0d61be7fb27 Mon Sep 17 00:00:00 2001 From: David Bresson Date: Thu, 11 Aug 2016 11:49:48 -0700 Subject: [PATCH 2/3] Add error handling to check registration --- command/agent/consul/syncer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/command/agent/consul/syncer.go b/command/agent/consul/syncer.go index 3accecc64d3..525b0aba8af 100644 --- a/command/agent/consul/syncer.go +++ b/command/agent/consul/syncer.go @@ -707,7 +707,11 @@ func (c *Syncer) createCheckReg(check *structs.ServiceCheck, serviceReg *consul. Scheme: check.Protocol, Host: net.JoinHostPort(host, strconv.Itoa(port)), } - url := base.ResolveReference(url.Parse(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)) From e41b70ca7d2c7a7dae9912cbd32293944a21673f Mon Sep 17 00:00:00 2001 From: David Bresson Date: Thu, 11 Aug 2016 12:22:46 -0700 Subject: [PATCH 3/3] Add a test for query string support --- command/agent/consul/syncer_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/command/agent/consul/syncer_test.go b/command/agent/consul/syncer_test.go index 94325b33d89..7e888c69ef1 100644 --- a/command/agent/consul/syncer_test.go +++ b/command/agent/consul/syncer_test.go @@ -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"}, @@ -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 { @@ -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) { @@ -208,6 +223,10 @@ func mockTask() *structs.Task { Label: "port2", Value: 20003, }, + structs.Port{ + Label: "port3", + Value: 20004, + }, }, }, },