diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index a3baa4deb..53c1c34b9 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -3,6 +3,7 @@ package agent import ( "fmt" "github.com/hashicorp/consul/consul/structs" + "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf" "net/http" "strconv" @@ -11,12 +12,23 @@ import ( type AgentSelf struct { Config *Config + Coord *coordinate.Coordinate Member serf.Member } func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + var coord *coordinate.Coordinate + if !s.agent.config.DisableCoordinates { + var err error + coord, err = s.agent.server.GetLANCoordinate() + if err != nil { + return nil, err + } + } + return AgentSelf{ Config: s.agent.config, + Coord: coord, Member: s.agent.LocalMember(), }, nil } diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index c89977049..9376f5394 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "os" + "reflect" "testing" "time" @@ -81,7 +82,7 @@ func TestHTTPAgentSelf(t *testing.T) { obj, err := srv.AgentSelf(nil, req) if err != nil { - t.Fatalf("Err: %v", err) + t.Fatalf("err: %v", err) } val := obj.(AgentSelf) @@ -92,6 +93,24 @@ func TestHTTPAgentSelf(t *testing.T) { if int(val.Config.Ports.SerfLan) != srv.agent.config.Ports.SerfLan { t.Fatalf("incorrect port: %v", obj) } + + c, err := srv.agent.server.GetLANCoordinate() + if err != nil { + t.Fatalf("err: %v", err) + } + if !reflect.DeepEqual(c, val.Coord) { + t.Fatalf("coordinates are not equal: %v != %v", c, val.Coord) + } + + srv.agent.config.DisableCoordinates = true + obj, err = srv.AgentSelf(nil, req) + if err != nil { + t.Fatalf("err: %v", err) + } + val = obj.(AgentSelf) + if val.Coord != nil { + t.Fatalf("should have been nil: %v", val.Coord) + } } func TestHTTPAgentMembers(t *testing.T) { diff --git a/website/source/docs/agent/http/agent.html.markdown b/website/source/docs/agent/http/agent.html.markdown index 32ffa19f1..d12e5a7aa 100644 --- a/website/source/docs/agent/http/agent.html.markdown +++ b/website/source/docs/agent/http/agent.html.markdown @@ -163,6 +163,11 @@ It returns a JSON body like this: "EnableSyslog": false, "RejoinAfterLeave": false }, + "Coord": { + "Adjustment": 0, + "Error": 1.5, + "Vec": [0,0,0,0,0,0,0,0] + }, "Member": { "Name": "foobar", "Addr": "10.1.10.12",