Skip to content

Commit

Permalink
feat(outputs/http): Allow keepalive configuration (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jul 13, 2023
1 parent 6c01149 commit ab333a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/output/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/output/http/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ab333a0

Please sign in to comment.