From ab333a0e750fe7aa0bab41558fec1f16996b8901 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Thu, 13 Jul 2023 11:32:02 +1000 Subject: [PATCH] feat(outputs/http): Allow keepalive configuration (#138) --- pkg/output/http/config.go | 1 + pkg/output/http/exporter.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/output/http/config.go b/pkg/output/http/config.go index 649499e6..335442c4 100644 --- a/pkg/output/http/config.go +++ b/pkg/output/http/config.go @@ -13,6 +13,7 @@ type Config struct { ExportTimeout time.Duration `yaml:"exportTimeout" default:"30s"` MaxExportBatchSize int `yaml:"maxExportBatchSize" default:"512"` Compression CompressionStrategy `yaml:"compression" default:"none"` + KeepAlive bool `yaml:"keepAlive" default:"true"` } func (c *Config) Validate() error { diff --git a/pkg/output/http/exporter.go b/pkg/output/http/exporter.go index 8eb84373..bfd6587f 100644 --- a/pkg/output/http/exporter.go +++ b/pkg/output/http/exporter.go @@ -21,12 +21,18 @@ type ItemExporter struct { } func NewItemExporter(name string, config *Config, log logrus.FieldLogger) (ItemExporter, error) { + t := http.DefaultTransport.(*http.Transport).Clone() + if !config.KeepAlive { + t.DisableKeepAlives = true + } + return ItemExporter{ config: config, log: log.WithField("output_name", name).WithField("output_type", SinkType), client: &http.Client{ - Timeout: config.ExportTimeout, + Transport: t, + Timeout: config.ExportTimeout, }, }, nil }