From 09e3742a827a36dead71569be9e971b82a75e243 Mon Sep 17 00:00:00 2001 From: Gowtam Lal Date: Thu, 9 Mar 2023 03:47:46 -0500 Subject: [PATCH] app/vmctl: Allow vmnative exports to skip HTTP keepalive. (#3909) app/vmctl: support HTTP keepalive disabling for vm-native mode --- app/vmctl/flags.go | 7 +++++++ app/vmctl/main.go | 20 +++++++++++--------- app/vmctl/native/client.go | 14 ++++++++------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/vmctl/flags.go b/app/vmctl/flags.go index afebd79a8..1fcc3033e 100644 --- a/app/vmctl/flags.go +++ b/app/vmctl/flags.go @@ -325,6 +325,8 @@ const ( vmNativeFilterTimeEnd = "vm-native-filter-time-end" vmNativeStepInterval = "vm-native-step-interval" + vmNativeDisableHTTPKeepAlive = "vm-native-disable-http-keep-alive" + vmNativeSrcAddr = "vm-native-src-addr" vmNativeSrcUser = "vm-native-src-user" vmNativeSrcPassword = "vm-native-src-password" @@ -358,6 +360,11 @@ var ( Name: vmNativeStepInterval, Usage: fmt.Sprintf("Split export data into chunks. Requires setting --%s. Valid values are '%s','%s','%s','%s'.", vmNativeFilterTimeStart, stepper.StepMonth, stepper.StepDay, stepper.StepHour, stepper.StepMinute), }, + &cli.BoolFlag{ + Name: vmNativeDisableHTTPKeepAlive, + Usage: "Disable HTTP persistent connections for requests made to VictoriaMetrics components during export", + Value: false, + }, &cli.StringFlag{ Name: vmNativeSrcAddr, Usage: "VictoriaMetrics address to perform export from. \n" + diff --git a/app/vmctl/main.go b/app/vmctl/main.go index aa5bad045..98db814b1 100644 --- a/app/vmctl/main.go +++ b/app/vmctl/main.go @@ -209,17 +209,19 @@ func main() { Chunk: c.String(vmNativeStepInterval), }, src: &native.Client{ - Addr: strings.Trim(c.String(vmNativeSrcAddr), "/"), - User: c.String(vmNativeSrcUser), - Password: c.String(vmNativeSrcPassword), - Headers: c.String(vmNativeSrcHeaders), + Addr: strings.Trim(c.String(vmNativeSrcAddr), "/"), + User: c.String(vmNativeSrcUser), + Password: c.String(vmNativeSrcPassword), + Headers: c.String(vmNativeSrcHeaders), + DisableHTTPKeepAlive: c.Bool(vmNativeDisableHTTPKeepAlive), }, dst: &native.Client{ - Addr: strings.Trim(c.String(vmNativeDstAddr), "/"), - User: c.String(vmNativeDstUser), - Password: c.String(vmNativeDstPassword), - ExtraLabels: c.StringSlice(vmExtraLabel), - Headers: c.String(vmNativeDstHeaders), + Addr: strings.Trim(c.String(vmNativeDstAddr), "/"), + User: c.String(vmNativeDstUser), + Password: c.String(vmNativeDstPassword), + ExtraLabels: c.StringSlice(vmExtraLabel), + Headers: c.String(vmNativeDstHeaders), + DisableHTTPKeepAlive: c.Bool(vmNativeDisableHTTPKeepAlive), }, backoff: backoff.New(), cc: c.Int(vmConcurrency), diff --git a/app/vmctl/native/client.go b/app/vmctl/native/client.go index ad73224c5..474dbe81f 100644 --- a/app/vmctl/native/client.go +++ b/app/vmctl/native/client.go @@ -18,11 +18,12 @@ const ( // Client is an HTTP client for exporting and importing // time series via native protocol. type Client struct { - Addr string - User string - Password string - ExtraLabels []string - Headers string + Addr string + User string + Password string + ExtraLabels []string + Headers string + DisableHTTPKeepAlive bool } // LabelValues represents series from api/v1/series response @@ -196,7 +197,8 @@ func (c *Client) do(req *http.Request, expSC int) (*http.Response, error) { if c.User != "" { req.SetBasicAuth(c.User, c.Password) } - resp, err := http.DefaultClient.Do(req) + var httpClient = &http.Client{Transport: &http.Transport{DisableKeepAlives: c.DisableHTTPKeepAlive}} + resp, err := httpClient.Do(req) if err != nil { return nil, fmt.Errorf("unexpected error when performing request: %w", err) }