diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-04-27 10:04:59 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-04-27 10:14:34 +0200 |
commit | b8e5228f51f47d0b63819b826da34ca7e4946d1a (patch) | |
tree | 3a886dcbdc02893bbba29de048649e70dad7240a /client/go/internal | |
parent | 2ca44073203f87b8258a632f44567710d75be4f1 (diff) |
Really align timeouts with Java client
Diffstat (limited to 'client/go/internal')
-rw-r--r-- | client/go/internal/cli/cmd/feed.go | 2 | ||||
-rw-r--r-- | client/go/internal/vespa/document/http.go | 14 | ||||
-rw-r--r-- | client/go/internal/vespa/document/http_test.go | 2 |
3 files changed, 13 insertions, 5 deletions
diff --git a/client/go/internal/cli/cmd/feed.go b/client/go/internal/cli/cmd/feed.go index 7cedc39bad8..5b168ef79a2 100644 --- a/client/go/internal/cli/cmd/feed.go +++ b/client/go/internal/cli/cmd/feed.go @@ -18,7 +18,7 @@ import ( func addFeedFlags(cmd *cobra.Command, options *feedOptions) { cmd.PersistentFlags().IntVar(&options.connections, "connections", 8, "The number of connections to use") cmd.PersistentFlags().StringVar(&options.compression, "compression", "auto", `Compression mode to use. Default is "auto" which compresses large documents. Must be "auto", "gzip" or "none"`) - cmd.PersistentFlags().IntVar(&options.timeoutSecs, "timeout", 200, "Individual feed operation timeout in seconds") + cmd.PersistentFlags().IntVar(&options.timeoutSecs, "timeout", 0, "Individual feed operation timeout in seconds. 0 to disable (default 0)") cmd.PersistentFlags().IntVar(&options.doomSecs, "deadline", 0, "Exit if this number of seconds elapse without any successful operations. 0 to disable (default 0)") cmd.PersistentFlags().BoolVar(&options.verbose, "verbose", false, "Verbose mode. Print successful operations in addition to errors") cmd.PersistentFlags().StringVar(&options.route, "route", "", `Target Vespa route for feed operations (default "default")`) diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go index 420d369e1b0..f4e4ec694c8 100644 --- a/client/go/internal/vespa/document/http.go +++ b/client/go/internal/vespa/document/http.go @@ -86,8 +86,9 @@ func NewClient(options ClientOptions, httpClients []util.HTTPClient) (*Client, e func (c *Client) queryParams() url.Values { params := url.Values{} - timeout := c.options.Timeout*11/10 + 1000 - params.Set("timeout", strconv.FormatInt(timeout.Milliseconds(), 10)+"ms") + if c.options.Timeout > 0 { + params.Set("timeout", strconv.FormatInt(c.options.Timeout.Milliseconds(), 10)+"ms") + } if c.options.Route != "" { params.Set("route", c.options.Route) } @@ -193,6 +194,13 @@ func (c *Client) createRequest(method, url string, body []byte) (*http.Request, return req, nil } +func (c *Client) clientTimeout() time.Duration { + if c.options.Timeout < 1 { + return 190 * time.Second + } + return c.options.Timeout*11/10 + 1000 // slightly higher than the server-side timeout +} + // Send given document to the endpoint configured in this client. func (c *Client) Send(document Document) Result { start := c.now() @@ -202,7 +210,7 @@ func (c *Client) Send(document Document) Result { if err != nil { return resultWithErr(result, err) } - resp, err := c.leastBusyClient().Do(req, 190*time.Second) + resp, err := c.leastBusyClient().Do(req, c.clientTimeout()) if err != nil { return resultWithErr(result, err) } diff --git a/client/go/internal/vespa/document/http_test.go b/client/go/internal/vespa/document/http_test.go index 3694c7599be..61ead1ba9c3 100644 --- a/client/go/internal/vespa/document/http_test.go +++ b/client/go/internal/vespa/document/http_test.go @@ -109,7 +109,7 @@ func TestClientSend(t *testing.T) { if r.Method != http.MethodPut { t.Errorf("got r.Method = %q, want %q", r.Method, http.MethodPut) } - wantURL := fmt.Sprintf("https://example.com:1337/document/v1/ns/type/docid/%s?create=true&timeout=5500ms", doc.Id.UserSpecific) + wantURL := fmt.Sprintf("https://example.com:1337/document/v1/ns/type/docid/%s?create=true&timeout=5000ms", doc.Id.UserSpecific) if r.URL.String() != wantURL { t.Errorf("got r.URL = %q, want %q", r.URL, wantURL) } |