From 961c04cae992eadb42d286d2f85f8a675bdc68c8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 29 Jan 2018 14:17:40 -0800 Subject: Upgrading server dependancies (#8154) --- vendor/gopkg.in/olivere/elastic.v5/client.go | 123 ++++++++++++--------------- 1 file changed, 56 insertions(+), 67 deletions(-) (limited to 'vendor/gopkg.in/olivere/elastic.v5/client.go') diff --git a/vendor/gopkg.in/olivere/elastic.v5/client.go b/vendor/gopkg.in/olivere/elastic.v5/client.go index 9a48d9ac7..1eb0ec54f 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/client.go +++ b/vendor/gopkg.in/olivere/elastic.v5/client.go @@ -21,12 +21,12 @@ import ( "github.com/pkg/errors" - "gopkg.in/olivere/elastic.v5/config" + "github.com/olivere/elastic/config" ) const ( // Version is the current version of Elastic. - Version = "5.0.53" + Version = "6.1.4" // 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. @@ -76,9 +76,6 @@ const ( // a GET request with a body. DefaultSendGetBodyAs = "GET" - // DefaultGzipEnabled specifies if gzip compression is enabled by default. - DefaultGzipEnabled = false - // off is used to disable timeouts. off = -1 * time.Second ) @@ -135,7 +132,6 @@ type Client struct { basicAuthPassword string // password for HTTP Basic Auth sendGetBodyAs string // override for when sending a GET with a body requiredPlugins []string // list of required plugins - gzipEnabled bool // gzip compression enabled or disabled (default) retrier Retrier // strategy for retries } @@ -158,7 +154,7 @@ type Client struct { // // If the sniffer is enabled (the default), the new client then sniffes // the cluster via the Nodes Info API -// (see https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html#cluster-nodes-info). +// (see https://www.elastic.co/guide/en/elasticsearch/reference/6.0/cluster-nodes-info.html#cluster-nodes-info). // It uses the URLs specified by the caller. The caller is responsible // to only pass a list of URLs of nodes that belong to the same cluster. // This sniffing process is run on startup and periodically. @@ -209,7 +205,6 @@ func NewClient(options ...ClientOptionFunc) (*Client, error) { snifferCallback: nopSnifferCallback, snifferStop: make(chan bool), sendGetBodyAs: DefaultSendGetBodyAs, - gzipEnabled: DefaultGzipEnabled, retrier: noRetries, // no retries by default } @@ -367,7 +362,6 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) { snifferCallback: nopSnifferCallback, snifferStop: make(chan bool), sendGetBodyAs: DefaultSendGetBodyAs, - gzipEnabled: DefaultGzipEnabled, retrier: noRetries, // no retries by default } @@ -596,14 +590,6 @@ func SetMaxRetries(maxRetries int) ClientOptionFunc { } } -// SetGzip enables or disables gzip compression (disabled by default). -func SetGzip(enabled bool) ClientOptionFunc { - return func(c *Client) error { - c.gzipEnabled = enabled - return nil - } -} - // SetDecoder sets the Decoder to use when decoding data from Elasticsearch. // DefaultDecoder is used by default. func SetDecoder(decoder Decoder) ClientOptionFunc { @@ -1086,6 +1072,7 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { c.mu.Unlock() // If we don't get a connection after "timeout", we bail. + var lastErr error start := time.Now() for { // Make a copy of the HTTP client provided via options to respect @@ -1104,6 +1091,8 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { res, err := cl.Do(req) if err == nil && res != nil && res.StatusCode >= 200 && res.StatusCode < 300 { return nil + } else if err != nil { + lastErr = err } } time.Sleep(1 * time.Second) @@ -1111,6 +1100,9 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { break } } + if lastErr != nil { + return errors.Wrapf(ErrNoClient, "health check timeout: %v", lastErr) + } return errors.Wrap(ErrNoClient, "health check timeout") } @@ -1167,19 +1159,26 @@ func (c *Client) mustActiveConn() error { return errors.Wrap(ErrNoClient, "no active connection found") } -// PerformRequest does a HTTP request to Elasticsearch. -// See PerformRequestWithContentType for details. -func (c *Client) PerformRequest(ctx context.Context, method, path string, params url.Values, body interface{}, ignoreErrors ...int) (*Response, error) { - return c.PerformRequestWithContentType(ctx, method, path, params, body, "application/json", ignoreErrors...) +// -- PerformRequest -- + +// PerformRequestOptions must be passed into PerformRequest. +type PerformRequestOptions struct { + Method string + Path string + Params url.Values + Body interface{} + ContentType string + IgnoreErrors []int + Retrier Retrier } -// PerformRequestWithContentType executes a HTTP request with a specific content type. +// PerformRequest does a HTTP request to Elasticsearch. // It returns a response (which might be nil) and an error on failure. // // Optionally, a list of HTTP error codes to ignore can be passed. // This is necessary for services that expect e.g. HTTP status 404 as a // valid outcome (Exists, IndicesExists, IndicesTypeExists). -func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path string, params url.Values, body interface{}, contentType string, ignoreErrors ...int) (*Response, error) { +func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions) (*Response, error) { start := time.Now().UTC() c.mu.RLock() @@ -1188,7 +1187,10 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path basicAuthUsername := c.basicAuthUsername basicAuthPassword := c.basicAuthPassword sendGetBodyAs := c.sendGetBodyAs - gzipEnabled := c.gzipEnabled + retrier := c.retrier + if opt.Retrier != nil { + retrier = opt.Retrier + } c.mu.RUnlock() var err error @@ -1199,14 +1201,14 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path var n int // Change method if sendGetBodyAs is specified. - if method == "GET" && body != nil && sendGetBodyAs != "GET" { - method = sendGetBodyAs + if opt.Method == "GET" && opt.Body != nil && sendGetBodyAs != "GET" { + opt.Method = sendGetBodyAs } for { - pathWithParams := path - if len(params) > 0 { - pathWithParams += "?" + params.Encode() + pathWithParams := opt.Path + if len(opt.Params) > 0 { + pathWithParams += "?" + opt.Params.Encode() } // Get a connection @@ -1217,7 +1219,7 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path // Force a healtcheck as all connections seem to be dead. c.healthcheck(timeout, false) } - wait, ok, rerr := c.retrier.Retry(ctx, n, nil, nil, err) + wait, ok, rerr := retrier.Retry(ctx, n, nil, nil, err) if rerr != nil { return nil, rerr } @@ -1233,24 +1235,24 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path return nil, err } - req, err = NewRequest(method, conn.URL()+pathWithParams) + req, err = NewRequest(opt.Method, conn.URL()+pathWithParams) if err != nil { - c.errorf("elastic: cannot create request for %s %s: %v", strings.ToUpper(method), conn.URL()+pathWithParams, err) + c.errorf("elastic: cannot create request for %s %s: %v", strings.ToUpper(opt.Method), conn.URL()+pathWithParams, err) return nil, err } if basicAuth { req.SetBasicAuth(basicAuthUsername, basicAuthPassword) } - if contentType != "" { - req.Header.Set("Content-Type", contentType) + if opt.ContentType != "" { + req.Header.Set("Content-Type", opt.ContentType) } // Set body - if body != nil { - err = req.SetBody(body, gzipEnabled) + if opt.Body != nil { + err = req.SetBody(opt.Body) if err != nil { - c.errorf("elastic: couldn't set body %+v for request: %v", body, err) + c.errorf("elastic: couldn't set body %+v for request: %v", opt.Body, err) return nil, err } } @@ -1273,7 +1275,7 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path } if err != nil { n++ - wait, ok, rerr := c.retrier.Retry(ctx, n, (*http.Request)(req), res, err) + wait, ok, rerr := retrier.Retry(ctx, n, (*http.Request)(req), res, err) if rerr != nil { c.errorf("elastic: %s is dead", conn.URL()) conn.MarkAsDead() @@ -1295,8 +1297,13 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path // Tracing c.dumpResponse(res) + // Log deprecation warnings as errors + if s := res.Header.Get("Warning"); s != "" { + c.errorf(s) + } + // Check for errors - if err := checkResponse((*http.Request)(req), res, ignoreErrors...); err != nil { + if err := checkResponse((*http.Request)(req), res, opt.IgnoreErrors...); err != nil { // No retry if request succeeded // We still try to return a response. resp, _ = c.newResponse(res) @@ -1316,7 +1323,7 @@ func (c *Client) PerformRequestWithContentType(ctx context.Context, method, path duration := time.Now().UTC().Sub(start) c.infof("%s %s [status:%d, request:%.3fs]", - strings.ToUpper(method), + strings.ToUpper(opt.Method), req.URL, resp.StatusCode, float64(int64(duration/time.Millisecond))/1000) @@ -1378,7 +1385,7 @@ func (c *Client) BulkProcessor() *BulkProcessorService { // Reindex copies data from a source index into a destination index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-reindex.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-reindex.html // for details on the Reindex API. func (c *Client) Reindex() *ReindexService { return NewReindexService(c) @@ -1405,11 +1412,6 @@ func (c *Client) Search(indices ...string) *SearchService { return NewSearchService(c).Index(indices...) } -// Suggest returns a service to return suggestions. -func (c *Client) Suggest(indices ...string) *SuggestService { - return NewSuggestService(c).Index(indices...) -} - // MultiSearch is the entry point for multi searches. func (c *Client) MultiSearch() *MultiSearchService { return NewMultiSearchService(c) @@ -1430,9 +1432,9 @@ func (c *Client) Explain(index, typ, id string) *ExplainService { // TODO Search Exists API // TODO Validate API -// FieldStats returns statistical information about fields in indices. -func (c *Client) FieldStats(indices ...string) *FieldStatsService { - return NewFieldStatsService(c).Index(indices...) +// FieldCaps returns statistical information about fields in indices. +func (c *Client) FieldCaps(indices ...string) *FieldCapsService { + return NewFieldCapsService(c).Index(indices...) } // Exists checks if a document exists. @@ -1516,6 +1518,11 @@ func (c *Client) IndexPutSettings(indices ...string) *IndicesPutSettingsService return NewIndicesPutSettingsService(c).Index(indices...) } +// IndexSegments retrieves low level segment information for all, one or more indices. +func (c *Client) IndexSegments(indices ...string) *IndicesSegmentsService { + return NewIndicesSegmentsService(c).Index(indices...) +} + // IndexAnalyze performs the analysis process on a text and returns the // token breakdown of the text. func (c *Client) IndexAnalyze() *IndicesAnalyzeService { @@ -1549,24 +1556,6 @@ func (c *Client) Aliases() *AliasesService { return NewAliasesService(c) } -// GetTemplate gets a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) GetTemplate() *GetTemplateService { - return NewGetTemplateService(c) -} - -// PutTemplate creates or updates a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) PutTemplate() *PutTemplateService { - return NewPutTemplateService(c) -} - -// DeleteTemplate deletes a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) DeleteTemplate() *DeleteTemplateService { - return NewDeleteTemplateService(c) -} - // IndexGetTemplate gets an index template. // Use XXXTemplate funcs to manage search templates. func (c *Client) IndexGetTemplate(names ...string) *IndicesGetTemplateService { -- cgit v1.2.3-1-g7c22