Skip to content

Commit

Permalink
Merge pull request #3680 from hashicorp/b-multi-region-search
Browse files Browse the repository at this point in the history
Search endpoint forwarding
  • Loading branch information
chelseakomlo committed Dec 21, 2017
2 parents b612f7a + 4668c1f commit da9a1d7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8 (Unreleased)

BUG FIXES:
* core: Fix search endpoint forwarding for multi-region clusters [GH-3680]

## 0.7.1 (December 19, 2017)

__BACKWARDS INCOMPATIBILITIES:__
Expand Down
7 changes: 7 additions & 0 deletions nomad/search_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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", "prefix_search"}, time.Now())

aclObj, err := s.srv.ResolveToken(args.AuthToken)
if err != nil {
return err
Expand Down
44 changes: 44 additions & 0 deletions nomad/search_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit da9a1d7

Please sign in to comment.