From 96eab1202717e073782ec399a4e0820cae15b1bb Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 17 Aug 2017 17:19:06 -0700 Subject: Updating server dependancies. (#7246) --- vendor/gopkg.in/olivere/elastic.v5/client.go | 9 +- vendor/gopkg.in/olivere/elastic.v5/client_test.go | 16 ++- vendor/gopkg.in/olivere/elastic.v5/retry_test.go | 6 +- vendor/gopkg.in/olivere/elastic.v5/run-es-5.5.1.sh | 1 + .../olivere/elastic.v5/search_aggs_bucket_terms.go | 110 ++++++++++++--------- .../elastic.v5/search_aggs_bucket_terms_test.go | 51 ++++++++++ 6 files changed, 141 insertions(+), 52 deletions(-) create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.5.1.sh (limited to 'vendor/gopkg.in/olivere') diff --git a/vendor/gopkg.in/olivere/elastic.v5/client.go b/vendor/gopkg.in/olivere/elastic.v5/client.go index 13be369bd..e517a7fa8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/client.go +++ b/vendor/gopkg.in/olivere/elastic.v5/client.go @@ -26,7 +26,7 @@ import ( const ( // Version is the current version of Elastic. - Version = "5.0.43" + Version = "5.0.45" // DefaultURL is the default endpoint of Elasticsearch on the local machine. // It is used e.g. when initializing a new Client without a specific URL. @@ -1257,6 +1257,13 @@ func (c *Client) PerformRequest(ctx context.Context, method, path string, params // Proceed, but don't mark the node as dead return nil, err } + if ue, ok := err.(*url.Error); ok { + // This happens e.g. on redirect errors, see https://golang.org/src/net/http/client_test.go#L329 + if ue.Err == context.Canceled || ue.Err == context.DeadlineExceeded { + // Proceed, but don't mark the node as dead + return nil, err + } + } if err != nil { n++ wait, ok, rerr := c.retrier.Retry(ctx, n, (*http.Request)(req), res, err) diff --git a/vendor/gopkg.in/olivere/elastic.v5/client_test.go b/vendor/gopkg.in/olivere/elastic.v5/client_test.go index 1441f1791..6caf7b797 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/client_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/client_test.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "strings" + "sync" "testing" "time" @@ -294,6 +295,7 @@ func TestClientHealthcheckTimeoutLeak(t *testing.T) { // leaks via leaktest. mux := http.NewServeMux() + var reqDoneMu sync.Mutex var reqDone bool mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { cn, ok := w.(http.CloseNotifier) @@ -301,7 +303,9 @@ func TestClientHealthcheckTimeoutLeak(t *testing.T) { t.Fatalf("Writer is not CloseNotifier, but %v", reflect.TypeOf(w).Name()) } <-cn.CloseNotify() + reqDoneMu.Lock() reqDone = true + reqDoneMu.Unlock() }) lis, err := net.Listen("tcp", "127.0.0.1:0") @@ -346,9 +350,12 @@ func TestClientHealthcheckTimeoutLeak(t *testing.T) { } <-time.After(time.Second) + reqDoneMu.Lock() if !reqDone { + reqDoneMu.Unlock() t.Fatal("Request wasn't canceled or stopped") } + reqDoneMu.Unlock() } // -- NewSimpleClient -- @@ -552,6 +559,7 @@ func TestClientSniffTimeoutLeak(t *testing.T) { // leaks via leaktest. mux := http.NewServeMux() + var reqDoneMu sync.Mutex var reqDone bool mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { cn, ok := w.(http.CloseNotifier) @@ -559,7 +567,9 @@ func TestClientSniffTimeoutLeak(t *testing.T) { t.Fatalf("Writer is not CloseNotifier, but %v", reflect.TypeOf(w).Name()) } <-cn.CloseNotify() + reqDoneMu.Lock() reqDone = true + reqDoneMu.Unlock() }) lis, err := net.Listen("tcp", "127.0.0.1:0") @@ -605,9 +615,12 @@ func TestClientSniffTimeoutLeak(t *testing.T) { } <-time.After(time.Second) + reqDoneMu.Lock() if !reqDone { + reqDoneMu.Unlock() t.Fatal("Request wasn't canceled or stopped") } + reqDoneMu.Unlock() } func TestClientExtractHostname(t *testing.T) { @@ -1195,7 +1208,8 @@ func TestPerformRequestWithTimeout(t *testing.T) { res *Response err error } - ctx, _ := context.WithTimeout(context.Background(), 1*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() resc := make(chan result, 1) go func() { diff --git a/vendor/gopkg.in/olivere/elastic.v5/retry_test.go b/vendor/gopkg.in/olivere/elastic.v5/retry_test.go index 14ebbb835..804313095 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/retry_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/retry_test.go @@ -21,14 +21,14 @@ func TestRetry(t *testing.T) { // This function is successfull on "successOn" calls. f := func() error { i++ - t.Logf("function is called %d. time\n", i) + // t.Logf("function is called %d. time\n", i) if i == successOn { - t.Log("OK") + // t.Log("OK") return nil } - t.Log("error") + // t.Log("error") return errors.New("error") } diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.5.1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.5.1.sh new file mode 100755 index 000000000..343a605ba --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.5.1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/etc:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.5.1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go index 5497aa6e9..6bcc322d0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go @@ -20,15 +20,10 @@ type TermsAggregation struct { minDocCount *int shardMinDocCount *int valueType string - includePattern string - includeFlags *int - excludePattern string - excludeFlags *int + includeExclude *TermsAggregationIncludeExclude executionHint string collectionMode string showTermDocCountError *bool - includeTerms []string - excludeTerms []string order []TermsOrder } @@ -91,24 +86,50 @@ func (a *TermsAggregation) ShardMinDocCount(shardMinDocCount int) *TermsAggregat } func (a *TermsAggregation) Include(regexp string) *TermsAggregation { - a.includePattern = regexp + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Include = regexp return a } -func (a *TermsAggregation) IncludeWithFlags(regexp string, flags int) *TermsAggregation { - a.includePattern = regexp - a.includeFlags = &flags +func (a *TermsAggregation) IncludeValues(values ...interface{}) *TermsAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.IncludeValues = append(a.includeExclude.IncludeValues, values...) return a } func (a *TermsAggregation) Exclude(regexp string) *TermsAggregation { - a.excludePattern = regexp + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Exclude = regexp + return a +} + +func (a *TermsAggregation) ExcludeValues(values ...interface{}) *TermsAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.ExcludeValues = append(a.includeExclude.ExcludeValues, values...) + return a +} + +func (a *TermsAggregation) Partition(p int) *TermsAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Partition = p return a } -func (a *TermsAggregation) ExcludeWithFlags(regexp string, flags int) *TermsAggregation { - a.excludePattern = regexp - a.excludeFlags = &flags +func (a *TermsAggregation) NumPartitions(n int) *TermsAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.NumPartitions = n return a } @@ -207,16 +228,6 @@ func (a *TermsAggregation) ShowTermDocCountError(showTermDocCountError bool) *Te return a } -func (a *TermsAggregation) IncludeTerms(terms ...string) *TermsAggregation { - a.includeTerms = append(a.includeTerms, terms...) - return a -} - -func (a *TermsAggregation) ExcludeTerms(terms ...string) *TermsAggregation { - a.excludeTerms = append(a.excludeTerms, terms...) - return a -} - func (a *TermsAggregation) Source() (interface{}, error) { // Example: // { @@ -283,32 +294,27 @@ func (a *TermsAggregation) Source() (interface{}, error) { } opts["order"] = orderSlice } - if len(a.includeTerms) > 0 { - opts["include"] = a.includeTerms - } - if a.includePattern != "" { - if a.includeFlags == nil || *a.includeFlags == 0 { - opts["include"] = a.includePattern - } else { - p := make(map[string]interface{}) - p["pattern"] = a.includePattern - p["flags"] = *a.includeFlags - opts["include"] = p + // Include/Exclude + if ie := a.includeExclude; ie != nil { + // Include + if ie.Include != "" { + opts["include"] = ie.Include + } else if len(ie.IncludeValues) > 0 { + opts["include"] = ie.IncludeValues + } else if ie.NumPartitions > 0 { + inc := make(map[string]interface{}) + inc["partition"] = ie.Partition + inc["num_partitions"] = ie.NumPartitions + opts["include"] = inc } - } - if len(a.excludeTerms) > 0 { - opts["exclude"] = a.excludeTerms - } - if a.excludePattern != "" { - if a.excludeFlags == nil || *a.excludeFlags == 0 { - opts["exclude"] = a.excludePattern - } else { - p := make(map[string]interface{}) - p["pattern"] = a.excludePattern - p["flags"] = *a.excludeFlags - opts["exclude"] = p + // Exclude + if ie.Exclude != "" { + opts["exclude"] = ie.Exclude + } else if len(ie.ExcludeValues) > 0 { + opts["exclude"] = ie.ExcludeValues } } + if a.executionHint != "" { opts["execution_hint"] = a.executionHint } @@ -334,6 +340,16 @@ func (a *TermsAggregation) Source() (interface{}, error) { return source, nil } +// TermsAggregationIncludeExclude allows for include/exclude in a TermsAggregation. +type TermsAggregationIncludeExclude struct { + Include string + Exclude string + IncludeValues []interface{} + ExcludeValues []interface{} + Partition int + NumPartitions int +} + // TermsOrder specifies a single order field for a terms aggregation. type TermsOrder struct { Field string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms_test.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms_test.go index 6b5c1bb8a..351cbf63b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms_test.go @@ -102,3 +102,54 @@ func TestTermsAggregationWithMissing(t *testing.T) { t.Errorf("expected\n%s\n,got:\n%s", expected, got) } } + +func TestTermsAggregationWithIncludeExclude(t *testing.T) { + agg := NewTermsAggregation().Field("tags").Include(".*sport.*").Exclude("water_.*") + src, err := agg.Source() + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(src) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"terms":{"exclude":"water_.*","field":"tags","include":".*sport.*"}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestTermsAggregationWithIncludeExcludeValues(t *testing.T) { + agg := NewTermsAggregation().Field("make").IncludeValues("mazda", "honda").ExcludeValues("rover", "jensen") + src, err := agg.Source() + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(src) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"terms":{"exclude":["rover","jensen"],"field":"make","include":["mazda","honda"]}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestTermsAggregationWithPartitions(t *testing.T) { + agg := NewTermsAggregation().Field("account_id").Partition(0).NumPartitions(20) + src, err := agg.Source() + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(src) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"terms":{"field":"account_id","include":{"num_partitions":20,"partition":0}}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} -- cgit v1.2.3-1-g7c22