Skip to content

Commit da70a64

Browse files
OmerTiroshraboof
andauthored
Update libraries (raboof#9)
* Move code to http package * Update libraries Add to all libraries /v7/ after beats Move output/transport to common/transport Move function were in outputs/transport/tls.go to common/transport/tlscommon * Update config * Update config.go * Update travis config * Update .travis.yml * Update .travis.yml * add a go.mod To make it possible to fetch the beats dependency, as that's only published as a module now. Eventually we'd want to migrate all dependency information from glide.lock to go.mod Unfortunately 'go get' doesn't take into account transitive replacements, so we need to include the replacements required by beats to make the build succeed on Travis. Co-authored-by: Arnout Engelen <arnout@bzzt.net>
1 parent 7b9307f commit da70a64

File tree

8 files changed

+111
-79
lines changed

8 files changed

+111
-79
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
language: go
22

3+
env:
4+
- GO111MODULE="on"
5+
36
go:
4-
- 1.12.6
7+
- 1.14.7

config.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

go.mod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module github.com/raboof/beats-output-http
2+
3+
go 1.14
4+
5+
require (
6+
github.com/elastic/beats/v7 v7.10.1
7+
)
8+
9+
// needed because elastic wants these replacements, and https://github.com/golang/go/issues/30354#issuecomment-466479708
10+
replace (
11+
github.com/Azure/go-autorest => github.com/Azure/go-autorest v12.2.0+incompatible
12+
github.com/Microsoft/go-winio => github.com/bi-zone/go-winio v0.4.15
13+
github.com/Shopify/sarama => github.com/elastic/sarama v1.19.1-0.20200629123429-0e7b69039eec
14+
github.com/cucumber/godog => github.com/cucumber/godog v0.8.1
15+
github.com/docker/docker => github.com/docker/engine v0.0.0-20191113042239-ea84732a7725
16+
github.com/docker/go-plugins-helpers => github.com/elastic/go-plugins-helpers v0.0.0-20200207104224-bdf17607b79f
17+
github.com/dop251/goja => github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20
18+
github.com/dop251/goja_nodejs => github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6
19+
github.com/fsnotify/fsevents => github.com/elastic/fsevents v0.0.0-20181029231046-e1d381a4d270
20+
github.com/fsnotify/fsnotify => github.com/adriansr/fsnotify v0.0.0-20180417234312-c9bbe1f46f1d
21+
github.com/google/gopacket => github.com/adriansr/gopacket v1.1.18-0.20200327165309-dd62abfa8a41
22+
github.com/insomniacslk/dhcp => github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 // indirect
23+
github.com/kardianos/service => github.com/blakerouse/service v1.1.1-0.20200924160513-057808572ffa
24+
github.com/tonistiigi/fifo => github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c
25+
golang.org/x/tools => golang.org/x/tools v0.0.0-20200602230032-c00d67ef29d0 // release 1.14
26+
)

client.go renamed to http/client.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ package http
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/elastic/beats/libbeat/beat"
7-
"github.com/elastic/beats/libbeat/common"
8-
"github.com/elastic/beats/libbeat/outputs"
9-
"github.com/elastic/beats/libbeat/outputs/outil"
10-
"github.com/elastic/beats/libbeat/outputs/transport"
11-
"github.com/elastic/beats/libbeat/publisher"
6+
"github.com/elastic/beats/v7/libbeat/beat"
7+
"github.com/elastic/beats/v7/libbeat/common"
8+
"github.com/elastic/beats/v7/libbeat/outputs"
9+
"github.com/elastic/beats/v7/libbeat/outputs/outil"
10+
"github.com/elastic/beats/v7/libbeat/common/transport"
11+
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
12+
"github.com/elastic/beats/v7/libbeat/publisher"
1213
"io"
1314
"io/ioutil"
1415
"net/http"
1516
"net/url"
1617
"time"
18+
"context"
1719
)
1820

1921
// Client struct
2022
type Client struct {
2123
Connection
22-
tlsConfig *transport.TLSConfig
24+
tlsConfig *tlscommon.TLSConfig
2325
params map[string]string
2426
// additional configs
2527
compressionLevel int
@@ -33,7 +35,7 @@ type Client struct {
3335
type ClientSettings struct {
3436
URL string
3537
Proxy *url.URL
36-
TLS *transport.TLSConfig
38+
TLS *tlscommon.TLSConfig
3739
Username, Password string
3840
Parameters map[string]string
3941
Index outil.Selector
@@ -162,7 +164,7 @@ func (client *Client) String() string {
162164
}
163165

164166
// Publish sends events to the clients sink.
165-
func (client *Client) Publish(batch publisher.Batch) error {
167+
func (client *Client) Publish(_ context.Context, batch publisher.Batch) error {
166168
events := batch.Events()
167169
rest, err := client.publishEvents(events)
168170
if len(rest) == 0 {

http/config.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package http
2+
3+
import (
4+
"time"
5+
6+
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
7+
)
8+
9+
type httpConfig struct {
10+
Protocol string `config:"protocol"`
11+
Path string `config:"path"`
12+
Params map[string]string `config:"parameters"`
13+
Username string `config:"username"`
14+
Password string `config:"password"`
15+
ProxyURL string `config:"proxy_url"`
16+
LoadBalance bool `config:"loadbalance"`
17+
BatchPublish bool `config:"batch_publish"`
18+
BatchSize int `config:"batch_size"`
19+
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
20+
TLS *tlscommon.Config `config:"tls"`
21+
MaxRetries int `config:"max_retries"`
22+
Timeout time.Duration `config:"timeout"`
23+
Headers map[string]string `config:"headers"`
24+
ContentType string `config:"content_type"`
25+
Backoff backoff `config:"backoff"`
26+
}
27+
28+
type backoff struct {
29+
Init time.Duration
30+
Max time.Duration
31+
}
32+
33+
var (
34+
defaultConfig = httpConfig{
35+
Protocol: "",
36+
Path: "",
37+
Params: nil,
38+
ProxyURL: "",
39+
Username: "",
40+
Password: "",
41+
BatchPublish: false,
42+
BatchSize: 2048,
43+
Timeout: 90 * time.Second,
44+
CompressionLevel: 0,
45+
TLS: nil,
46+
MaxRetries: 3,
47+
LoadBalance: false,
48+
Backoff: backoff{
49+
Init: 1 * time.Second,
50+
Max: 60 * time.Second,
51+
},
52+
}
53+
)
54+
55+
func (c *httpConfig) Validate() error {
56+
if c.ProxyURL != "" {
57+
if _, err := parseProxyURL(c.ProxyURL); err != nil {
58+
return err
59+
}
60+
}
61+
62+
return nil
63+
}
File renamed without changes.

http.go renamed to http/http.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package http
22

33
import (
44
"errors"
5-
"github.com/elastic/beats/libbeat/beat"
6-
"github.com/elastic/beats/libbeat/common"
7-
"github.com/elastic/beats/libbeat/logp"
8-
"github.com/elastic/beats/libbeat/outputs"
5+
"github.com/elastic/beats/v7/libbeat/beat"
6+
"github.com/elastic/beats/v7/libbeat/common"
7+
"github.com/elastic/beats/v7/libbeat/logp"
8+
"github.com/elastic/beats/v7/libbeat/outputs"
9+
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
910
)
1011

1112
func init() {
@@ -30,7 +31,7 @@ func MakeHTTP(
3031
if err := cfg.Unpack(&config); err != nil {
3132
return outputs.Fail(err)
3233
}
33-
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
34+
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
3435
if err != nil {
3536
return outputs.Fail(err)
3637
}

url.go renamed to http/url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package http
22

33
import (
4-
"github.com/elastic/beats/libbeat/common"
4+
"github.com/elastic/beats/v7/libbeat/common"
55
"net/url"
66
"strings"
77
)

0 commit comments

Comments
 (0)