From 2b1d7f3cc6f3dadd34d04d83d7c2feb90f62d2a8 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Wed, 20 Dec 2017 15:17:28 -0500 Subject: [PATCH 1/3] search endpoint forwarding --- nomad/search_endpoint.go | 7 ++++++ nomad/search_endpoint_test.go | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/nomad/search_endpoint.go b/nomad/search_endpoint.go index 61931a5e8b8..512ef3e044f 100644 --- a/nomad/search_endpoint.go +++ b/nomad/search_endpoint.go @@ -2,7 +2,9 @@ package nomad import ( "strings" + "time" + metrics "github.com/armon/go-metrics" memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/state" @@ -114,6 +116,11 @@ func roundUUIDDownIfOdd(prefix string, context structs.Context) string { // PrefixSearch is used to list matches for a given prefix, and returns // matching jobs, evaluations, allocations, and/or nodes. func (s *Search) PrefixSearch(args *structs.SearchRequest, reply *structs.SearchResponse) error { + if done, err := s.srv.forward("Search.PrefixSearch", args, args, reply); done { + return err + } + defer metrics.MeasureSince([]string{"nomad", "search", "prefixsearch"}, time.Now()) + aclObj, err := s.srv.ResolveToken(args.AuthToken) if err != nil { return err diff --git a/nomad/search_endpoint_test.go b/nomad/search_endpoint_test.go index 7cd6fe6b27a..2631b695876 100644 --- a/nomad/search_endpoint_test.go +++ b/nomad/search_endpoint_test.go @@ -712,3 +712,47 @@ func TestSearch_PrefixSearch_RoundDownToEven(t *testing.T) { assert.Equal(1, len(resp.Matches[structs.Jobs])) assert.Equal(job.ID, resp.Matches[structs.Jobs][0]) } + +func TestSearch_PrefixSearch_MultiRegion(t *testing.T) { + assert := assert.New(t) + + jobName := "exampleexample" + + t.Parallel() + s1 := testServer(t, func(c *Config) { + c.NumSchedulers = 0 + c.Region = "foo" + }) + defer s1.Shutdown() + + s2 := testServer(t, func(c *Config) { + c.NumSchedulers = 0 + c.Region = "bar" + }) + defer s2.Shutdown() + + testJoin(t, s1, s2) + testutil.WaitForLeader(t, s1.RPC) + + job := registerAndVerifyJob(s1, t, jobName, 0) + + req := &structs.SearchRequest{ + Prefix: "", + Context: structs.Jobs, + QueryOptions: structs.QueryOptions{ + Region: "foo", + Namespace: job.Namespace, + }, + } + + codec := rpcClient(t, s2) + + var resp structs.SearchResponse + if err := msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp); err != nil { + t.Fatalf("err: %v", err) + } + + assert.Equal(1, len(resp.Matches[structs.Jobs])) + assert.Equal(job.ID, resp.Matches[structs.Jobs][0]) + assert.Equal(uint64(jobIndex), resp.Index) +} From 47ca3836667d4512779935ca8fcbf85d0335d7d1 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Wed, 20 Dec 2017 17:52:41 -0500 Subject: [PATCH 2/3] Fixes #3679 code review fixups; add changelog --- CHANGELOG.md | 5 +++++ nomad/search_endpoint.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a828d589e49..ca29ae61853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.8 (Unreleased) + +BUG FIXES: + * core: Fix search endpoint forwarding for multi-region clusters [GH-3679] + ## 0.7.1 (December 19, 2017) __BACKWARDS INCOMPATIBILITIES:__ diff --git a/nomad/search_endpoint.go b/nomad/search_endpoint.go index 512ef3e044f..9eb892dd31c 100644 --- a/nomad/search_endpoint.go +++ b/nomad/search_endpoint.go @@ -119,7 +119,7 @@ func (s *Search) PrefixSearch(args *structs.SearchRequest, reply *structs.Search if done, err := s.srv.forward("Search.PrefixSearch", args, args, reply); done { return err } - defer metrics.MeasureSince([]string{"nomad", "search", "prefixsearch"}, time.Now()) + defer metrics.MeasureSince([]string{"nomad", "search", "prefix_search"}, time.Now()) aclObj, err := s.srv.ResolveToken(args.AuthToken) if err != nil { From 4668c1f48f8012d651578765d12b2f11e2667576 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Wed, 20 Dec 2017 19:04:07 -0500 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca29ae61853..2453ae1a091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8 (Unreleased) BUG FIXES: - * core: Fix search endpoint forwarding for multi-region clusters [GH-3679] + * core: Fix search endpoint forwarding for multi-region clusters [GH-3680] ## 0.7.1 (December 19, 2017)