go.d pkg web renames (#18545)
Ilya Mashchenko committed
Sep 13, 2024 at 15:27 UTC
bf4f03e722671caf9cc6c28e3ea6eb79a9a988ae
241 files changed
+1068
-1013
src/go/plugin/go.d/agent/discovery/sd/discoverer/dockerd/docker.go
+4
-4
@@ -13,8 +13,8 @@ import (
13
14
"github.com/netdata/netdata/go/plugins/logger"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/discovery/sd/model"
16
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
17
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/dockerhost"
17
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
18
19
"github.com/docker/docker/api/types"
20
typesContainer "github.com/docker/docker/api/types/container"
@@ -64,9 +64,9 @@ func NewDiscoverer(cfg Config) (*Discoverer, error) {
64
type Config struct {
65
Source string
66
67
- Tags string `yaml:"tags"`
68
- Address string `yaml:"address"`
69
- Timeout web.Duration `yaml:"timeout"`
67
+ Tags string `yaml:"tags"`
68
+ Address string `yaml:"address"`
69
+ Timeout confopt.Duration `yaml:"timeout"`
70
}
71
72
type (
src/go/plugin/go.d/modules/activemq/activemq.go
+14
-13
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *ActiveMQ {
28
return &ActiveMQ{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8161",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
Webadmin: "admin",
@@ -45,13 +46,13 @@ func New() *ActiveMQ {
46
}
47
48
type Config struct {
48
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
50
- Webadmin string `yaml:"webadmin,omitempty" json:"webadmin"`
51
- MaxQueues int `yaml:"max_queues" json:"max_queues"`
52
- MaxTopics int `yaml:"max_topics" json:"max_topics"`
53
- QueuesFilter string `yaml:"queues_filter,omitempty" json:"queues_filter"`
54
- TopicsFilter string `yaml:"topics_filter,omitempty" json:"topics_filter"`
49
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
+ Webadmin string `yaml:"webadmin,omitempty" json:"webadmin"`
52
+ MaxQueues int `yaml:"max_queues" json:"max_queues"`
53
+ MaxTopics int `yaml:"max_topics" json:"max_topics"`
54
+ QueuesFilter string `yaml:"queues_filter,omitempty" json:"queues_filter"`
55
+ TopicsFilter string `yaml:"topics_filter,omitempty" json:"topics_filter"`
56
}
57
58
type ActiveMQ struct {
@@ -92,13 +93,13 @@ func (a *ActiveMQ) Init() error {
93
}
94
a.topicsFilter = tf
95
95
- client, err := web.NewHTTPClient(a.Client)
96
+ client, err := web.NewHTTPClient(a.ClientConfig)
97
if err != nil {
98
a.Error(err)
99
return err
100
}
101
101
- a.apiClient = newAPIClient(client, a.Request, a.Webadmin)
102
+ a.apiClient = newAPIClient(client, a.RequestConfig, a.Webadmin)
103
104
return nil
105
}
src/go/plugin/go.d/modules/activemq/activemq_test.go
+4
-4
@@ -178,7 +178,7 @@ func TestActiveMQ_Check(t *testing.T) {
178
defer ts.Close()
179
180
job := New()
181
- job.HTTP.Request = web.Request{URL: ts.URL}
181
+ job.HTTPConfig.RequestConfig = web.RequestConfig{URL: ts.URL}
182
job.Webadmin = "webadmin"
183
184
require.NoError(t, job.Init())
@@ -211,7 +211,7 @@ func TestActiveMQ_Collect(t *testing.T) {
211
defer ts.Close()
212
213
job := New()
214
- job.HTTP.Request = web.Request{URL: ts.URL}
214
+ job.HTTPConfig.RequestConfig = web.RequestConfig{URL: ts.URL}
215
job.Webadmin = "webadmin"
216
217
require.NoError(t, job.Init())
@@ -319,7 +319,7 @@ func TestActiveMQ_404(t *testing.T) {
319
320
job := New()
321
job.Webadmin = "webadmin"
322
- job.HTTP.Request = web.Request{URL: ts.URL}
322
+ job.HTTPConfig.RequestConfig = web.RequestConfig{URL: ts.URL}
323
324
require.NoError(t, job.Init())
325
assert.Error(t, job.Check())
@@ -333,7 +333,7 @@ func TestActiveMQ_InvalidData(t *testing.T) {
333
334
mod := New()
335
mod.Webadmin = "webadmin"
336
- mod.HTTP.Request = web.Request{URL: ts.URL}
336
+ mod.HTTPConfig.RequestConfig = web.RequestConfig{URL: ts.URL}
337
338
require.NoError(t, mod.Init())
339
assert.Error(t, mod.Check())
src/go/plugin/go.d/modules/activemq/apiclient.go
+2
-2
@@ -44,7 +44,7 @@ type stats struct {
44
45
const pathStats = "/%s/xml/%s.jsp"
46
47
-func newAPIClient(client *http.Client, request web.Request, webadmin string) *apiClient {
47
+func newAPIClient(client *http.Client, request web.RequestConfig, webadmin string) *apiClient {
48
return &apiClient{
49
httpClient: client,
50
request: request,
@@ -54,7 +54,7 @@ func newAPIClient(client *http.Client, request web.Request, webadmin string) *ap
54
55
type apiClient struct {
56
httpClient *http.Client
57
- request web.Request
57
+ request web.RequestConfig
58
webadmin string
59
}
60
src/go/plugin/go.d/modules/adaptecraid/adaptec.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *AdaptecRaid {
29
return &AdaptecRaid{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
lds: make(map[string]bool),
@@ -37,8 +37,8 @@ func New() *AdaptecRaid {
37
}
38
39
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
}
43
44
type (
src/go/plugin/go.d/modules/ap/ap.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -29,7 +29,7 @@ func New() *AP {
29
return &AP{
30
Config: Config{
31
BinaryPath: "/usr/sbin/iw",
32
- Timeout: web.Duration(time.Second * 2),
32
+ Timeout: confopt.Duration(time.Second * 2),
33
},
34
charts: &module.Charts{},
35
seenIfaces: make(map[string]*iwInterface),
@@ -37,9 +37,9 @@ func New() *AP {
37
}
38
39
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
- BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
40
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
43
}
44
45
type (
src/go/plugin/go.d/modules/apache/apache.go
+7
-6
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -27,12 +28,12 @@ func init() {
28
func New() *Apache {
29
return &Apache{
30
Config: Config{
30
- HTTP: web.HTTP{
31
- Request: web.Request{
31
+ HTTPConfig: web.HTTPConfig{
32
+ RequestConfig: web.RequestConfig{
33
URL: "http://127.0.0.1/server-status?auto",
34
},
34
- Client: web.Client{
35
- Timeout: web.Duration(time.Second),
35
+ ClientConfig: web.ClientConfig{
36
+ Timeout: confopt.Duration(time.Second),
37
},
38
},
39
},
@@ -42,8 +43,8 @@ func New() *Apache {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type Apache struct {
src/go/plugin/go.d/modules/apache/apache_test.go
+4
-4
@@ -55,16 +55,16 @@ func TestApache_Init(t *testing.T) {
55
"fail when URL not set": {
56
wantFail: true,
57
config: Config{
58
- HTTP: web.HTTP{
59
- Request: web.Request{URL: ""},
58
+ HTTPConfig: web.HTTPConfig{
59
+ RequestConfig: web.RequestConfig{URL: ""},
60
},
61
},
62
},
63
"fail when URL has no wantMetrics suffix": {
64
wantFail: true,
65
config: Config{
66
- HTTP: web.HTTP{
67
- Request: web.Request{URL: "http://127.0.0.1:38001"},
66
+ HTTPConfig: web.HTTPConfig{
67
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
68
},
69
},
70
},
src/go/plugin/go.d/modules/apache/collect.go
+1
-1
@@ -31,7 +31,7 @@ func (a *Apache) collect() (map[string]int64, error) {
31
}
32
33
func (a *Apache) scrapeStatus() (*serverStatus, error) {
34
- req, err := web.NewHTTPRequest(a.Request)
34
+ req, err := web.NewHTTPRequest(a.RequestConfig)
35
if err != nil {
36
return nil, err
37
}
src/go/plugin/go.d/modules/apache/init.go
+1
-1
@@ -21,5 +21,5 @@ func (a *Apache) validateConfig() error {
21
}
22
23
func (a *Apache) initHTTPClient() (*http.Client, error) {
24
- return web.NewHTTPClient(a.Client)
24
+ return web.NewHTTPClient(a.ClientConfig)
25
}
src/go/plugin/go.d/modules/apcupsd/apcupsd.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Apcupsd {
26
return &Apcupsd{
27
Config: Config{
28
Address: "127.0.0.1:3551",
29
- Timeout: web.Duration(time.Second * 3),
29
+ Timeout: confopt.Duration(time.Second * 3),
30
},
31
newConn: newUpsdConn,
32
charts: charts.Copy(),
@@ -34,9 +34,9 @@ func New() *Apcupsd {
34
}
35
36
type Config struct {
37
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
- Address string `yaml:"address" json:"address"`
39
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
37
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
+ Address string `yaml:"address" json:"address"`
39
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
}
41
42
type Apcupsd struct {
src/go/plugin/go.d/modules/beanstalk/beanstalk.go
+6
-6
@@ -10,8 +10,8 @@ import (
10
11
"github.com/netdata/netdata/go/plugins/logger"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
17
//go:embed "config_schema.json"
@@ -29,7 +29,7 @@ func New() *Beanstalk {
29
return &Beanstalk{
30
Config: Config{
31
Address: "127.0.0.1:11300",
32
- Timeout: web.Duration(time.Second * 1),
32
+ Timeout: confopt.Duration(time.Second * 1),
33
TubeSelector: "*",
34
},
35
@@ -42,10 +42,10 @@ func New() *Beanstalk {
42
}
43
44
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- Address string `yaml:"address" json:"address"`
47
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
48
- TubeSelector string `yaml:"tube_selector,omitempty" json:"tube_selector"`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ Address string `yaml:"address" json:"address"`
47
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
48
+ TubeSelector string `yaml:"tube_selector,omitempty" json:"tube_selector"`
49
}
50
51
type Beanstalk struct {
src/go/plugin/go.d/modules/bind/bind.go
+10
-10
@@ -8,10 +8,10 @@ import (
8
"net/http"
9
"time"
10
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
-
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
15
)
16
17
//go:embed "config_schema.json"
@@ -28,12 +28,12 @@ func init() {
28
func New() *Bind {
29
return &Bind{
30
Config: Config{
31
- HTTP: web.HTTP{
32
- Request: web.Request{
31
+ HTTPConfig: web.HTTPConfig{
32
+ RequestConfig: web.RequestConfig{
33
URL: "http://127.0.0.1:8653/json/v1",
34
},
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second),
35
+ ClientConfig: web.ClientConfig{
36
+ Timeout: confopt.Duration(time.Second),
37
},
38
},
39
},
@@ -42,9 +42,9 @@ func New() *Bind {
42
}
43
44
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
47
- PermitView string `yaml:"permit_view,omitempty" json:"permit_view"`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ web.HTTPConfig `yaml:",inline" json:""`
47
+ PermitView string `yaml:"permit_view,omitempty" json:"permit_view"`
48
}
49
50
type (
@@ -84,7 +84,7 @@ func (b *Bind) Init() error {
84
b.permitView = pvm
85
}
86
87
- httpClient, err := web.NewHTTPClient(b.Client)
87
+ httpClient, err := web.NewHTTPClient(b.ClientConfig)
88
if err != nil {
89
b.Errorf("creating http client : %v", err)
90
return err
src/go/plugin/go.d/modules/bind/init.go
+2
-2
@@ -28,9 +28,9 @@ func (b *Bind) initPermitViewMatcher() (matcher.Matcher, error) {
28
func (b *Bind) initBindApiClient(httpClient *http.Client) (bindAPIClient, error) {
29
switch {
30
case strings.HasSuffix(b.URL, "/xml/v3"): // BIND 9.9+
31
- return newXML3Client(httpClient, b.Request), nil
31
+ return newXML3Client(httpClient, b.RequestConfig), nil
32
case strings.HasSuffix(b.URL, "/json/v1"): // BIND 9.10+
33
- return newJSONClient(httpClient, b.Request), nil
33
+ return newJSONClient(httpClient, b.RequestConfig), nil
34
default:
35
return nil, fmt.Errorf("URL %s is wrong, supported endpoints: `/xml/v3`, `/json/v1`", b.URL)
36
}
src/go/plugin/go.d/modules/bind/json_client.go
+2
-2
@@ -32,13 +32,13 @@ type jsonViewResolver struct {
32
CacheStats map[string]int64
33
}
34
35
-func newJSONClient(client *http.Client, request web.Request) *jsonClient {
35
+func newJSONClient(client *http.Client, request web.RequestConfig) *jsonClient {
36
return &jsonClient{httpClient: client, request: request}
37
}
38
39
type jsonClient struct {
40
httpClient *http.Client
41
- request web.Request
41
+ request web.RequestConfig
42
}
43
44
func (c jsonClient) serverStats() (*serverStats, error) {
src/go/plugin/go.d/modules/bind/xml3_client.go
+2
-2
@@ -34,13 +34,13 @@ type xml3View struct {
34
CounterGroups []xml3CounterGroup `xml:"counters"`
35
}
36
37
-func newXML3Client(client *http.Client, request web.Request) *xml3Client {
37
+func newXML3Client(client *http.Client, request web.RequestConfig) *xml3Client {
38
return &xml3Client{httpClient: client, request: request}
39
}
40
41
type xml3Client struct {
42
httpClient *http.Client
43
- request web.Request
43
+ request web.RequestConfig
44
}
45
46
func (c xml3Client) serverStats() (*serverStats, error) {
src/go/plugin/go.d/modules/boinc/boinc.go
+6
-6
@@ -9,7 +9,7 @@ import (
9
10
"github.com/netdata/netdata/go/plugins/logger"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
)
14
15
//go:embed "config_schema.json"
@@ -27,7 +27,7 @@ func New() *Boinc {
27
return &Boinc{
28
Config: Config{
29
Address: "127.0.0.1:31416",
30
- Timeout: web.Duration(time.Second * 1),
30
+ Timeout: confopt.Duration(time.Second * 1),
31
},
32
newConn: newBoincConn,
33
charts: charts.Copy(),
@@ -35,10 +35,10 @@ func New() *Boinc {
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Address string `yaml:"address" json:"address"`
40
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
41
- Password string `yaml:"password" json:"password"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Address string `yaml:"address" json:"address"`
40
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
41
+ Password string `yaml:"password" json:"password"`
42
}
43
44
type Boinc struct {
src/go/plugin/go.d/modules/cassandra/cassandra.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -29,12 +30,12 @@ func init() {
30
func New() *Cassandra {
31
return &Cassandra{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Request: web.Request{
33
+ HTTPConfig: web.HTTPConfig{
34
+ RequestConfig: web.RequestConfig{
35
URL: "http://127.0.0.1:7072/metrics",
36
},
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second * 5),
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second * 5),
39
},
40
},
41
},
@@ -45,8 +46,8 @@ func New() *Cassandra {
46
}
47
48
type Config struct {
48
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
49
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
}
52
53
type Cassandra struct {
src/go/plugin/go.d/modules/cassandra/cassandra_test.go
+2
-2
@@ -47,7 +47,7 @@ func TestCassandra_Init(t *testing.T) {
47
}{
48
"success if 'url' is set": {
49
config: Config{
50
- HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:7072"}}},
50
+ HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:7072"}}},
51
},
52
"success on default config": {
53
wantFail: false,
@@ -55,7 +55,7 @@ func TestCassandra_Init(t *testing.T) {
55
},
56
"fails if 'url' is unset": {
57
wantFail: true,
58
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: ""}}},
58
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: ""}}},
59
},
60
}
61
src/go/plugin/go.d/modules/cassandra/init.go
+2
-2
@@ -17,9 +17,9 @@ func (c *Cassandra) validateConfig() error {
17
}
18
19
func (c *Cassandra) initPrometheusClient() (prometheus.Prometheus, error) {
20
- client, err := web.NewHTTPClient(c.Client)
20
+ client, err := web.NewHTTPClient(c.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
- return prometheus.New(client, c.Request), nil
24
+ return prometheus.New(client, c.RequestConfig), nil
25
}
src/go/plugin/go.d/modules/chrony/chrony.go
+5
-5
@@ -9,7 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
14
"github.com/facebook/time/ntp/chrony"
15
)
@@ -29,7 +29,7 @@ func New() *Chrony {
29
return &Chrony{
30
Config: Config{
31
Address: "127.0.0.1:323",
32
- Timeout: web.Duration(time.Second),
32
+ Timeout: confopt.Duration(time.Second),
33
},
34
charts: charts.Copy(),
35
addStatsChartsOnce: &sync.Once{},
@@ -38,9 +38,9 @@ func New() *Chrony {
38
}
39
40
type Config struct {
41
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
- Address string `yaml:"address" json:"address"`
43
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ Address string `yaml:"address" json:"address"`
43
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
}
45
46
type (
src/go/plugin/go.d/modules/clickhouse/clickhouse.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *ClickHouse {
28
return &ClickHouse{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8123",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -42,8 +43,8 @@ func New() *ClickHouse {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type (
src/go/plugin/go.d/modules/clickhouse/clickhouse_test.go
+2
-2
@@ -58,8 +58,8 @@ func TestClickHouse_Init(t *testing.T) {
58
"fail when URL not set": {
59
wantFail: true,
60
config: Config{
61
- HTTP: web.HTTP{
62
- Request: web.Request{URL: ""},
61
+ HTTPConfig: web.HTTPConfig{
62
+ RequestConfig: web.RequestConfig{URL: ""},
63
},
64
},
65
},
src/go/plugin/go.d/modules/clickhouse/collect_system_async_metrics.go
+1
-1
@@ -22,7 +22,7 @@ where
22
`
23
24
func (c *ClickHouse) collectSystemAsyncMetrics(mx map[string]int64) error {
25
- req, _ := web.NewHTTPRequest(c.Request)
25
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
26
req.URL.RawQuery = makeURLQuery(querySystemAsyncMetrics)
27
28
want := map[string]float64{
src/go/plugin/go.d/modules/clickhouse/collect_system_disks.go
+1
-1
@@ -26,7 +26,7 @@ type diskStats struct {
26
}
27
28
func (c *ClickHouse) collectSystemDisks(mx map[string]int64) error {
29
- req, _ := web.NewHTTPRequest(c.Request)
29
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
30
req.URL.RawQuery = makeURLQuery(querySystemDisks)
31
32
seen := make(map[string]*diskStats)
src/go/plugin/go.d/modules/clickhouse/collect_system_events.go
+1
-1
@@ -18,7 +18,7 @@ FROM
18
`
19
20
func (c *ClickHouse) collectSystemEvents(mx map[string]int64) error {
21
- req, _ := web.NewHTTPRequest(c.Request)
21
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
22
req.URL.RawQuery = makeURLQuery(querySystemEvents)
23
24
px := "events_"
src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go
+1
-1
@@ -18,7 +18,7 @@ FROM
18
`
19
20
func (c *ClickHouse) collectSystemMetrics(mx map[string]int64) error {
21
- req, _ := web.NewHTTPRequest(c.Request)
21
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
22
req.URL.RawQuery = makeURLQuery(querySystemMetrics)
23
24
px := "metrics_"
src/go/plugin/go.d/modules/clickhouse/collect_system_parts.go
+1
-1
@@ -34,7 +34,7 @@ type tableStats struct {
34
}
35
36
func (c *ClickHouse) collectSystemParts(mx map[string]int64) error {
37
- req, _ := web.NewHTTPRequest(c.Request)
37
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
38
req.URL.RawQuery = makeURLQuery(querySystemParts)
39
40
seen := make(map[string]*tableStats)
src/go/plugin/go.d/modules/clickhouse/collect_system_processes.go
+1
-1
@@ -16,7 +16,7 @@ FROM
16
`
17
18
func (c *ClickHouse) collectLongestRunningQueryTime(mx map[string]int64) error {
19
- req, _ := web.NewHTTPRequest(c.Request)
19
+ req, _ := web.NewHTTPRequest(c.RequestConfig)
20
req.URL.RawQuery = makeURLQuery(queryLongestQueryTime)
21
22
return c.doOKDecodeCSV(req, func(column, value string, lineEnd bool) {
src/go/plugin/go.d/modules/clickhouse/init.go
+1
-1
@@ -17,5 +17,5 @@ func (c *ClickHouse) validateConfig() error {
17
}
18
19
func (c *ClickHouse) initHTTPClient() (*http.Client, error) {
20
- return web.NewHTTPClient(c.Client)
20
+ return web.NewHTTPClient(c.ClientConfig)
21
}
src/go/plugin/go.d/modules/cockroachdb/cockroachdb.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -33,12 +34,12 @@ func init() {
34
func New() *CockroachDB {
35
return &CockroachDB{
36
Config: Config{
36
- HTTP: web.HTTP{
37
- Request: web.Request{
37
+ HTTPConfig: web.HTTPConfig{
38
+ RequestConfig: web.RequestConfig{
39
URL: "http://127.0.0.1:8080/_status/vars",
40
},
40
- Client: web.Client{
41
- Timeout: web.Duration(time.Second),
41
+ ClientConfig: web.ClientConfig{
42
+ Timeout: confopt.Duration(time.Second),
43
},
44
},
45
},
@@ -47,8 +48,8 @@ func New() *CockroachDB {
48
}
49
50
type Config struct {
50
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
51
- web.HTTP `yaml:",inline" json:""`
51
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
52
+ web.HTTPConfig `yaml:",inline" json:""`
53
}
54
55
type CockroachDB struct {
src/go/plugin/go.d/modules/cockroachdb/cockroachdb_test.go
+1
-1
@@ -56,7 +56,7 @@ func TestCockroachDB_Init_ReturnsFalseIfConfigURLIsNotSet(t *testing.T) {
56
57
func TestCockroachDB_Init_ReturnsFalseIfClientWrongTLSCA(t *testing.T) {
58
cdb := prepareCockroachDB()
59
- cdb.Client.TLSConfig.TLSCA = "testdata/tls"
59
+ cdb.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
60
61
assert.Error(t, cdb.Init())
62
}
src/go/plugin/go.d/modules/cockroachdb/init.go
+2
-2
@@ -17,9 +17,9 @@ func (c *CockroachDB) validateConfig() error {
17
}
18
19
func (c *CockroachDB) initPrometheusClient() (prometheus.Prometheus, error) {
20
- client, err := web.NewHTTPClient(c.Client)
20
+ client, err := web.NewHTTPClient(c.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
- return prometheus.New(client, c.Request), nil
24
+ return prometheus.New(client, c.RequestConfig), nil
25
}
src/go/plugin/go.d/modules/consul/collect.go
+1
-1
@@ -68,7 +68,7 @@ func (c *Consul) isServer() bool {
68
}
69
70
func (c *Consul) doOKDecode(urlPath string, in interface{}, statusCodes ...int) error {
71
- req, err := web.NewHTTPRequestWithPath(c.Request, urlPath)
71
+ req, err := web.NewHTTPRequestWithPath(c.RequestConfig, urlPath)
72
if err != nil {
73
return fmt.Errorf("error on creating request: %v", err)
74
}
src/go/plugin/go.d/modules/consul/consul.go
+8
-7
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
16
@@ -33,12 +34,12 @@ func init() {
34
func New() *Consul {
35
return &Consul{
36
Config: Config{
36
- HTTP: web.HTTP{
37
- Request: web.Request{
37
+ HTTPConfig: web.HTTPConfig{
38
+ RequestConfig: web.RequestConfig{
39
URL: "http://127.0.0.1:8500",
40
},
40
- Client: web.Client{
41
- Timeout: web.Duration(time.Second),
41
+ ClientConfig: web.ClientConfig{
42
+ Timeout: confopt.Duration(time.Second),
43
},
44
},
45
},
@@ -50,9 +51,9 @@ func New() *Consul {
51
}
52
53
type Config struct {
53
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
54
- web.HTTP `yaml:",inline" json:""`
55
- ACLToken string `yaml:"acl_token,omitempty" json:"acl_token"`
54
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
55
+ web.HTTPConfig `yaml:",inline" json:""`
56
+ ACLToken string `yaml:"acl_token,omitempty" json:"acl_token"`
57
}
58
59
type Consul struct {
src/go/plugin/go.d/modules/consul/consul_test.go
+2
-2
@@ -75,8 +75,8 @@ func TestConsul_Init(t *testing.T) {
75
"fail when URL not set": {
76
wantFail: true,
77
config: Config{
78
- HTTP: web.HTTP{
79
- Request: web.Request{URL: ""},
78
+ HTTPConfig: web.HTTPConfig{
79
+ RequestConfig: web.RequestConfig{URL: ""},
80
},
81
},
82
},
src/go/plugin/go.d/modules/consul/init.go
+3
-3
@@ -19,13 +19,13 @@ func (c *Consul) validateConfig() error {
19
}
20
21
func (c *Consul) initHTTPClient() (*http.Client, error) {
22
- return web.NewHTTPClient(c.Client)
22
+ return web.NewHTTPClient(c.ClientConfig)
23
}
24
25
const urlPathAgentMetrics = "/v1/agent/metrics"
26
27
func (c *Consul) initPrometheusClient(httpClient *http.Client) (prometheus.Prometheus, error) {
28
- r, err := web.NewHTTPRequest(c.Request.Copy())
28
+ r, err := web.NewHTTPRequest(c.RequestConfig.Copy())
29
if err != nil {
30
return nil, err
31
}
@@ -34,7 +34,7 @@ func (c *Consul) initPrometheusClient(httpClient *http.Client) (prometheus.Prome
34
"format": []string{"prometheus"},
35
}.Encode()
36
37
- req := c.Request.Copy()
37
+ req := c.RequestConfig.Copy()
38
req.URL = r.URL.String()
39
40
if c.ACLToken != "" {
src/go/plugin/go.d/modules/coredns/collect.go
+6
-6
@@ -174,9 +174,9 @@ func (cd *CoreDNS) collectSummaryRequests(mx *metrics, raw prometheus.Series) {
174
// continue
175
// }
176
//
177
-// setRequestDuration(&mx.Summary.Request, value, le)
177
+// setRequestDuration(&mx.Summary.RequestConfig, value, le)
178
// }
179
-// processRequestDuration(&mx.Summary.Request)
179
+// processRequestDuration(&mx.Summary.RequestConfig)
180
//}
181
182
func (cd *CoreDNS) collectSummaryRequestsPerType(mx *metrics, raw prometheus.Series) {
@@ -290,10 +290,10 @@ func (cd *CoreDNS) collectPerServerRequests(mx *metrics, raw prometheus.Series)
290
// mx.PerServer[server] = &requestResponse{}
291
// }
292
//
293
-// setRequestDuration(&mx.PerServer[server].Request, value, le)
293
+// setRequestDuration(&mx.PerServer[server].RequestConfig, value, le)
294
// }
295
// for _, s := range mx.PerServer {
296
-// processRequestDuration(&s.Request)
296
+// processRequestDuration(&s.RequestConfig)
297
// }
298
//}
299
@@ -433,10 +433,10 @@ func (cd *CoreDNS) collectPerZoneRequests(mx *metrics, raw prometheus.Series) {
433
// mx.PerZone[zone] = &requestResponse{}
434
// }
435
//
436
-// setRequestDuration(&mx.PerZone[zone].Request, value, le)
436
+// setRequestDuration(&mx.PerZone[zone].RequestConfig, value, le)
437
// }
438
// for _, s := range mx.PerZone {
439
-// processRequestDuration(&s.Request)
439
+// processRequestDuration(&s.RequestConfig)
440
// }
441
//}
442
src/go/plugin/go.d/modules/coredns/coredns.go
+6
-5
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
@@ -29,12 +30,12 @@ func init() {
30
func New() *CoreDNS {
31
return &CoreDNS{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Request: web.Request{
33
+ HTTPConfig: web.HTTPConfig{
34
+ RequestConfig: web.RequestConfig{
35
URL: "http://127.0.0.1:9153/metrics",
36
},
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second),
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second),
39
},
40
},
41
},
@@ -46,7 +47,7 @@ func New() *CoreDNS {
47
48
type Config struct {
49
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
PerServerStats matcher.SimpleExpr `yaml:"per_server_stats,omitempty" json:"per_server_stats"`
52
PerZoneStats matcher.SimpleExpr `yaml:"per_zone_stats,omitempty" json:"per_zone_stats"`
53
}
src/go/plugin/go.d/modules/coredns/init.go
+2
-2
@@ -32,9 +32,9 @@ func (cd *CoreDNS) initPerZoneMatcher() (matcher.Matcher, error) {
32
}
33
34
func (cd *CoreDNS) initPrometheusClient() (prometheus.Prometheus, error) {
35
- client, err := web.NewHTTPClient(cd.Client)
35
+ client, err := web.NewHTTPClient(cd.ClientConfig)
36
if err != nil {
37
return nil, err
38
}
39
- return prometheus.New(client, cd.Request), nil
39
+ return prometheus.New(client, cd.RequestConfig), nil
40
}
src/go/plugin/go.d/modules/couchbase/collect.go
+1
-1
@@ -111,7 +111,7 @@ func (cb *Couchbase) addDimToChart(chartID string, dim *module.Dim) {
111
}
112
113
func (cb *Couchbase) scrapeCouchbase() (*cbMetrics, error) {
114
- req, err := web.NewHTTPRequestWithPath(cb.Request, urlPathBucketsStats)
114
+ req, err := web.NewHTTPRequestWithPath(cb.RequestConfig, urlPathBucketsStats)
115
if err != nil {
116
return nil, err
117
}
src/go/plugin/go.d/modules/couchbase/couchbase.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -29,12 +30,12 @@ func init() {
30
func New() *Couchbase {
31
return &Couchbase{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Request: web.Request{
33
+ HTTPConfig: web.HTTPConfig{
34
+ RequestConfig: web.RequestConfig{
35
URL: "http://127.0.0.1:8091",
36
},
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second),
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second),
39
},
40
},
41
},
@@ -43,8 +44,8 @@ func New() *Couchbase {
44
}
45
46
type Config struct {
46
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
- web.HTTP `yaml:",inline" json:""`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ web.HTTPConfig `yaml:",inline" json:""`
49
}
50
51
type Couchbase struct {
src/go/plugin/go.d/modules/couchbase/couchbase_test.go
+4
-4
@@ -47,8 +47,8 @@ func TestCouchbase_Init(t *testing.T) {
47
"fails on unset 'URL'": {
48
wantFail: true,
49
config: Config{
50
- HTTP: web.HTTP{
51
- Request: web.Request{
50
+ HTTPConfig: web.HTTPConfig{
51
+ RequestConfig: web.RequestConfig{
52
URL: "",
53
},
54
},
@@ -57,8 +57,8 @@ func TestCouchbase_Init(t *testing.T) {
57
"fails on invalid URL": {
58
wantFail: true,
59
config: Config{
60
- HTTP: web.HTTP{
61
- Request: web.Request{
60
+ HTTPConfig: web.HTTPConfig{
61
+ RequestConfig: web.RequestConfig{
62
URL: "127.0.0.1:9090",
63
},
64
},
src/go/plugin/go.d/modules/couchbase/init.go
+2
-2
@@ -25,14 +25,14 @@ func (cb *Couchbase) initCharts() (*Charts, error) {
25
}
26
27
func (cb *Couchbase) initHTTPClient() (*http.Client, error) {
28
- return web.NewHTTPClient(cb.Client)
28
+ return web.NewHTTPClient(cb.ClientConfig)
29
}
30
31
func (cb *Couchbase) validateConfig() error {
32
if cb.URL == "" {
33
return errors.New("URL not set")
34
}
35
- if _, err := web.NewHTTPRequest(cb.Request); err != nil {
35
+ if _, err := web.NewHTTPRequest(cb.RequestConfig); err != nil {
36
return err
37
}
38
return nil
src/go/plugin/go.d/modules/couchdb/collect.go
+5
-5
@@ -120,7 +120,7 @@ func (cdb *CouchDB) scrapeCouchDB() *cdbMetrics {
120
}
121
122
func (cdb *CouchDB) scrapeNodeStats(ms *cdbMetrics) {
123
- req, _ := web.NewHTTPRequestWithPath(cdb.Request, fmt.Sprintf(urlPathOverviewStats, cdb.Config.Node))
123
+ req, _ := web.NewHTTPRequestWithPath(cdb.RequestConfig, fmt.Sprintf(urlPathOverviewStats, cdb.Config.Node))
124
125
var stats cdbNodeStats
126
if err := cdb.doOKDecode(req, &stats); err != nil {
@@ -131,7 +131,7 @@ func (cdb *CouchDB) scrapeNodeStats(ms *cdbMetrics) {
131
}
132
133
func (cdb *CouchDB) scrapeSystemStats(ms *cdbMetrics) {
134
- req, _ := web.NewHTTPRequestWithPath(cdb.Request, fmt.Sprintf(urlPathSystemStats, cdb.Config.Node))
134
+ req, _ := web.NewHTTPRequestWithPath(cdb.RequestConfig, fmt.Sprintf(urlPathSystemStats, cdb.Config.Node))
135
136
var stats cdbNodeSystem
137
if err := cdb.doOKDecode(req, &stats); err != nil {
@@ -142,7 +142,7 @@ func (cdb *CouchDB) scrapeSystemStats(ms *cdbMetrics) {
142
}
143
144
func (cdb *CouchDB) scrapeActiveTasks(ms *cdbMetrics) {
145
- req, _ := web.NewHTTPRequestWithPath(cdb.Request, urlPathActiveTasks)
145
+ req, _ := web.NewHTTPRequestWithPath(cdb.RequestConfig, urlPathActiveTasks)
146
147
var stats []cdbActiveTask
148
if err := cdb.doOKDecode(req, &stats); err != nil {
@@ -153,7 +153,7 @@ func (cdb *CouchDB) scrapeActiveTasks(ms *cdbMetrics) {
153
}
154
155
func (cdb *CouchDB) scrapeDBStats(ms *cdbMetrics) {
156
- req, _ := web.NewHTTPRequestWithPath(cdb.Request, urlPathDatabases)
156
+ req, _ := web.NewHTTPRequestWithPath(cdb.RequestConfig, urlPathDatabases)
157
req.Method = http.MethodPost
158
req.Header.Add("Accept", "application/json")
159
req.Header.Add("Content-Type", "application/json")
@@ -193,7 +193,7 @@ func findMaxMQSize(MessageQueues map[string]interface{}) int64 {
193
}
194
195
func (cdb *CouchDB) pingCouchDB() error {
196
- req, _ := web.NewHTTPRequest(cdb.Request)
196
+ req, _ := web.NewHTTPRequest(cdb.RequestConfig)
197
198
var info struct{ Couchdb string }
199
if err := cdb.doOKDecode(req, &info); err != nil {
src/go/plugin/go.d/modules/couchdb/couchdb.go
+9
-8
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -30,12 +31,12 @@ func init() {
31
func New() *CouchDB {
32
return &CouchDB{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Request: web.Request{
34
+ HTTPConfig: web.HTTPConfig{
35
+ RequestConfig: web.RequestConfig{
36
URL: "http://127.0.0.1:5984",
37
},
37
- Client: web.Client{
38
- Timeout: web.Duration(time.Second * 2),
38
+ ClientConfig: web.ClientConfig{
39
+ Timeout: confopt.Duration(time.Second * 2),
40
},
41
},
42
Node: "_local",
@@ -44,10 +45,10 @@ func New() *CouchDB {
45
}
46
47
type Config struct {
47
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- web.HTTP `yaml:",inline" json:""`
49
- Node string `yaml:"node,omitempty" json:"node"`
50
- Databases string `yaml:"databases,omitempty" json:"databases"`
48
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
+ web.HTTPConfig `yaml:",inline" json:""`
50
+ Node string `yaml:"node,omitempty" json:"node"`
51
+ Databases string `yaml:"databases,omitempty" json:"databases"`
52
}
53
54
type CouchDB struct {
src/go/plugin/go.d/modules/couchdb/couchdb_test.go
+4
-4
@@ -63,15 +63,15 @@ func TestCouchDB_Init(t *testing.T) {
63
"URL not set": {
64
wantFail: true,
65
config: Config{
66
- HTTP: web.HTTP{
67
- Request: web.Request{URL: ""},
66
+ HTTPConfig: web.HTTPConfig{
67
+ RequestConfig: web.RequestConfig{URL: ""},
68
}},
69
},
70
"invalid TLSCA": {
71
wantFail: true,
72
config: Config{
73
- HTTP: web.HTTP{
74
- Client: web.Client{
73
+ HTTPConfig: web.HTTPConfig{
74
+ ClientConfig: web.ClientConfig{
75
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
76
},
77
}},
src/go/plugin/go.d/modules/couchdb/init.go
+2
-2
@@ -17,14 +17,14 @@ func (cdb *CouchDB) validateConfig() error {
17
if cdb.Node == "" {
18
return errors.New("'node' not set")
19
}
20
- if _, err := web.NewHTTPRequest(cdb.Request); err != nil {
20
+ if _, err := web.NewHTTPRequest(cdb.RequestConfig); err != nil {
21
return err
22
}
23
return nil
24
}
25
26
func (cdb *CouchDB) initHTTPClient() (*http.Client, error) {
27
- return web.NewHTTPClient(cdb.Client)
27
+ return web.NewHTTPClient(cdb.ClientConfig)
28
}
29
30
func (cdb *CouchDB) initCharts() (*Charts, error) {
src/go/plugin/go.d/modules/dmcache/dmcache.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *DmCache {
29
return &DmCache{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
devices: make(map[string]bool),
@@ -36,8 +36,8 @@ func New() *DmCache {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
}
42
43
type (
src/go/plugin/go.d/modules/dnsdist/collect.go
+1
-1
@@ -35,7 +35,7 @@ func (d *DNSdist) collectStatistic(collected map[string]int64, statistics *stati
35
}
36
37
func (d *DNSdist) scrapeStatistics() (*statisticMetrics, error) {
38
- req, err := web.NewHTTPRequestWithPath(d.Request, urlPathJSONStat)
38
+ req, err := web.NewHTTPRequestWithPath(d.RequestConfig, urlPathJSONStat)
39
if err != nil {
40
return nil, err
41
}
src/go/plugin/go.d/modules/dnsdist/dnsdist.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -29,12 +30,12 @@ func init() {
30
func New() *DNSdist {
31
return &DNSdist{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Request: web.Request{
33
+ HTTPConfig: web.HTTPConfig{
34
+ RequestConfig: web.RequestConfig{
35
URL: "http://127.0.0.1:8083",
36
},
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second),
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second),
39
},
40
},
41
},
@@ -42,8 +43,8 @@ func New() *DNSdist {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type DNSdist struct {
src/go/plugin/go.d/modules/dnsdist/dnsdist_test.go
+5
-5
@@ -48,19 +48,19 @@ func TestDNSdist_Init(t *testing.T) {
48
"fails on unset URL": {
49
wantFail: true,
50
config: Config{
51
- HTTP: web.HTTP{
52
- Request: web.Request{URL: ""},
51
+ HTTPConfig: web.HTTPConfig{
52
+ RequestConfig: web.RequestConfig{URL: ""},
53
},
54
},
55
},
56
"fails on invalid TLSCA": {
57
wantFail: true,
58
config: Config{
59
- HTTP: web.HTTP{
60
- Request: web.Request{
59
+ HTTPConfig: web.HTTPConfig{
60
+ RequestConfig: web.RequestConfig{
61
URL: "http://127.0.0.1:38001",
62
},
63
- Client: web.Client{
63
+ ClientConfig: web.ClientConfig{
64
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
65
},
66
},
src/go/plugin/go.d/modules/dnsdist/init.go
+2
-2
@@ -15,7 +15,7 @@ func (d *DNSdist) validateConfig() error {
15
return errors.New("URL not set")
16
}
17
18
- if _, err := web.NewHTTPRequest(d.Request); err != nil {
18
+ if _, err := web.NewHTTPRequest(d.RequestConfig); err != nil {
19
return err
20
}
21
@@ -23,7 +23,7 @@ func (d *DNSdist) validateConfig() error {
23
}
24
25
func (d *DNSdist) initHTTPClient() (*http.Client, error) {
26
- return web.NewHTTPClient(d.Client)
26
+ return web.NewHTTPClient(d.ClientConfig)
27
}
28
29
func (d *DNSdist) initCharts() (*module.Charts, error) {
src/go/plugin/go.d/modules/dnsmasq/dnsmasq.go
+6
-6
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
13
"github.com/miekg/dns"
14
)
@@ -29,7 +29,7 @@ func New() *Dnsmasq {
29
Config: Config{
30
Protocol: "udp",
31
Address: "127.0.0.1:53",
32
- Timeout: web.Duration(time.Second),
32
+ Timeout: confopt.Duration(time.Second),
33
},
34
35
newDNSClient: func(network string, timeout time.Duration) dnsClient {
@@ -42,10 +42,10 @@ func New() *Dnsmasq {
42
}
43
44
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- Address string `yaml:"address" json:"address"`
47
- Protocol string `yaml:"protocol,omitempty" json:"protocol"`
48
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ Address string `yaml:"address" json:"address"`
47
+ Protocol string `yaml:"protocol,omitempty" json:"protocol"`
48
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
49
}
50
51
type (
src/go/plugin/go.d/modules/dnsquery/dnsquery.go
+10
-10
@@ -7,7 +7,7 @@ import (
7
"time"
8
9
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
10
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
10
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
11
12
"github.com/miekg/dns"
13
)
@@ -29,7 +29,7 @@ func init() {
29
func New() *DNSQuery {
30
return &DNSQuery{
31
Config: Config{
32
- Timeout: web.Duration(time.Second * 2),
32
+ Timeout: confopt.Duration(time.Second * 2),
33
Network: "udp",
34
RecordTypes: []string{"A"},
35
Port: 53,
@@ -44,14 +44,14 @@ func New() *DNSQuery {
44
}
45
46
type Config struct {
47
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
49
- Domains []string `yaml:"domains" json:"domains"`
50
- Servers []string `yaml:"servers" json:"servers"`
51
- Network string `yaml:"network,omitempty" json:"network"`
52
- RecordType string `yaml:"record_type,omitempty" json:"record_type"`
53
- RecordTypes []string `yaml:"record_types,omitempty" json:"record_types"`
54
- Port int `yaml:"port,omitempty" json:"port"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
49
+ Domains []string `yaml:"domains" json:"domains"`
50
+ Servers []string `yaml:"servers" json:"servers"`
51
+ Network string `yaml:"network,omitempty" json:"network"`
52
+ RecordType string `yaml:"record_type,omitempty" json:"record_type"`
53
+ RecordTypes []string `yaml:"record_types,omitempty" json:"record_types"`
54
+ Port int `yaml:"port,omitempty" json:"port"`
55
}
56
57
type (
src/go/plugin/go.d/modules/dnsquery/dnsquery_test.go
+7
-7
@@ -9,7 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
14
"github.com/miekg/dns"
15
"github.com/stretchr/testify/assert"
@@ -47,7 +47,7 @@ func TestDNSQuery_Init(t *testing.T) {
47
Network: "udp",
48
RecordTypes: []string{"A"},
49
Port: 53,
50
- Timeout: web.Duration(time.Second),
50
+ Timeout: confopt.Duration(time.Second),
51
},
52
},
53
"success when using deprecated record_type": {
@@ -58,7 +58,7 @@ func TestDNSQuery_Init(t *testing.T) {
58
Network: "udp",
59
RecordType: "A",
60
Port: 53,
61
- Timeout: web.Duration(time.Second),
61
+ Timeout: confopt.Duration(time.Second),
62
},
63
},
64
"fail with default": {
@@ -73,7 +73,7 @@ func TestDNSQuery_Init(t *testing.T) {
73
Network: "udp",
74
RecordTypes: []string{"A"},
75
Port: 53,
76
- Timeout: web.Duration(time.Second),
76
+ Timeout: confopt.Duration(time.Second),
77
},
78
},
79
"fail when servers not set": {
@@ -84,7 +84,7 @@ func TestDNSQuery_Init(t *testing.T) {
84
Network: "udp",
85
RecordTypes: []string{"A"},
86
Port: 53,
87
- Timeout: web.Duration(time.Second),
87
+ Timeout: confopt.Duration(time.Second),
88
},
89
},
90
"fail when network is invalid": {
@@ -95,7 +95,7 @@ func TestDNSQuery_Init(t *testing.T) {
95
Network: "gcp",
96
RecordTypes: []string{"A"},
97
Port: 53,
98
- Timeout: web.Duration(time.Second),
98
+ Timeout: confopt.Duration(time.Second),
99
},
100
},
101
"fail when record_type is invalid": {
@@ -106,7 +106,7 @@ func TestDNSQuery_Init(t *testing.T) {
106
Network: "udp",
107
RecordTypes: []string{"B"},
108
Port: 53,
109
- Timeout: web.Duration(time.Second),
109
+ Timeout: confopt.Duration(time.Second),
110
},
111
},
112
}
src/go/plugin/go.d/modules/docker/docker.go
+6
-6
@@ -9,8 +9,8 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/dockerhost"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
15
"github.com/docker/docker/api/types"
16
typesContainer "github.com/docker/docker/api/types/container"
@@ -34,7 +34,7 @@ func New() *Docker {
34
return &Docker{
35
Config: Config{
36
Address: docker.DefaultDockerHost,
37
- Timeout: web.Duration(time.Second * 2),
37
+ Timeout: confopt.Duration(time.Second * 2),
38
CollectContainerSize: false,
39
},
40
@@ -47,10 +47,10 @@ func New() *Docker {
47
}
48
49
type Config struct {
50
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
51
- Address string `yaml:"address" json:"address"`
52
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
53
- CollectContainerSize bool `yaml:"collect_container_size" json:"collect_container_size"`
50
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
51
+ Address string `yaml:"address" json:"address"`
52
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
53
+ CollectContainerSize bool `yaml:"collect_container_size" json:"collect_container_size"`
54
}
55
56
type (
src/go/plugin/go.d/modules/docker_engine/docker_engine.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *DockerEngine {
28
return &DockerEngine{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:9323/metrics",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -39,8 +40,8 @@ func New() *DockerEngine {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type DockerEngine struct {
src/go/plugin/go.d/modules/docker_engine/docker_engine_test.go
+4
-4
@@ -56,13 +56,13 @@ func TestDockerEngine_Init(t *testing.T) {
56
config: New().Config,
57
},
58
"empty URL": {
59
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: ""}}},
59
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: ""}}},
60
wantFail: true,
61
},
62
"nonexistent TLS CA": {
63
- config: Config{HTTP: web.HTTP{
64
- Request: web.Request{URL: "http://127.0.0.1:9323/metrics"},
65
- Client: web.Client{TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}}}},
63
+ config: Config{HTTPConfig: web.HTTPConfig{
64
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:9323/metrics"},
65
+ ClientConfig: web.ClientConfig{TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}}}},
66
wantFail: true,
67
},
68
}
src/go/plugin/go.d/modules/docker_engine/init.go
+2
-2
@@ -17,9 +17,9 @@ func (de *DockerEngine) validateConfig() error {
17
}
18
19
func (de *DockerEngine) initPrometheusClient() (prometheus.Prometheus, error) {
20
- client, err := web.NewHTTPClient(de.Client)
20
+ client, err := web.NewHTTPClient(de.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
- return prometheus.New(client, de.Request), nil
24
+ return prometheus.New(client, de.RequestConfig), nil
25
}
src/go/plugin/go.d/modules/dockerhub/apiclient.go
+2
-2
@@ -21,13 +21,13 @@ type repository struct {
21
LastUpdated string `json:"last_updated"`
22
}
23
24
-func newAPIClient(client *http.Client, request web.Request) *apiClient {
24
+func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient {
25
return &apiClient{httpClient: client, request: request}
26
}
27
28
type apiClient struct {
29
httpClient *http.Client
30
- request web.Request
30
+ request web.RequestConfig
31
}
32
33
func (a apiClient) getRepository(repoName string) (*repository, error) {
src/go/plugin/go.d/modules/dockerhub/dockerhub.go
+8
-7
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -28,12 +29,12 @@ func init() {
29
func New() *DockerHub {
30
return &DockerHub{
31
Config: Config{
31
- HTTP: web.HTTP{
32
- Request: web.Request{
32
+ HTTPConfig: web.HTTPConfig{
33
+ RequestConfig: web.RequestConfig{
34
URL: "https://hub.docker.com/v2/repositories",
35
},
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second * 2),
36
+ ClientConfig: web.ClientConfig{
37
+ Timeout: confopt.Duration(time.Second * 2),
38
},
39
},
40
},
@@ -41,9 +42,9 @@ func New() *DockerHub {
42
}
43
44
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- web.HTTP `yaml:",inline" json:""`
46
- Repositories []string `yaml:"repositories" json:"repositories"`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ web.HTTPConfig `yaml:",inline" json:""`
47
+ Repositories []string `yaml:"repositories" json:"repositories"`
48
}
49
50
type DockerHub struct {
src/go/plugin/go.d/modules/dockerhub/init.go
+2
-2
@@ -18,9 +18,9 @@ func (dh *DockerHub) validateConfig() error {
18
}
19
20
func (dh *DockerHub) initApiClient() (*apiClient, error) {
21
- client, err := web.NewHTTPClient(dh.Client)
21
+ client, err := web.NewHTTPClient(dh.ClientConfig)
22
if err != nil {
23
return nil, err
24
}
25
- return newAPIClient(client, dh.Request), nil
25
+ return newAPIClient(client, dh.RequestConfig), nil
26
}
src/go/plugin/go.d/modules/dovecot/dovecot.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Dovecot {
26
return &Dovecot{
27
Config: Config{
28
Address: "127.0.0.1:24242",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newConn: newDovecotConn,
32
charts: charts.Copy(),
@@ -34,9 +34,9 @@ func New() *Dovecot {
34
}
35
36
type Config struct {
37
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
- Address string `yaml:"address" json:"address"`
39
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
37
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
+ Address string `yaml:"address" json:"address"`
39
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
40
}
41
42
type Dovecot struct {
src/go/plugin/go.d/modules/elasticsearch/collect.go
+5
-5
@@ -164,7 +164,7 @@ func (es *Elasticsearch) scrapeNodesStats(ms *esMetrics) {
164
p = urlPathLocalNodeStats
165
}
166
167
- req, _ := web.NewHTTPRequestWithPath(es.Request, p)
167
+ req, _ := web.NewHTTPRequestWithPath(es.RequestConfig, p)
168
169
var stats esNodesStats
170
if err := es.doOKDecode(req, &stats); err != nil {
@@ -176,7 +176,7 @@ func (es *Elasticsearch) scrapeNodesStats(ms *esMetrics) {
176
}
177
178
func (es *Elasticsearch) scrapeClusterHealth(ms *esMetrics) {
179
- req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathClusterHealth)
179
+ req, _ := web.NewHTTPRequestWithPath(es.RequestConfig, urlPathClusterHealth)
180
181
var health esClusterHealth
182
if err := es.doOKDecode(req, &health); err != nil {
@@ -188,7 +188,7 @@ func (es *Elasticsearch) scrapeClusterHealth(ms *esMetrics) {
188
}
189
190
func (es *Elasticsearch) scrapeClusterStats(ms *esMetrics) {
191
- req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathClusterStats)
191
+ req, _ := web.NewHTTPRequestWithPath(es.RequestConfig, urlPathClusterStats)
192
193
var stats esClusterStats
194
if err := es.doOKDecode(req, &stats); err != nil {
@@ -200,7 +200,7 @@ func (es *Elasticsearch) scrapeClusterStats(ms *esMetrics) {
200
}
201
202
func (es *Elasticsearch) scrapeLocalIndicesStats(ms *esMetrics) {
203
- req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathIndicesStats)
203
+ req, _ := web.NewHTTPRequestWithPath(es.RequestConfig, urlPathIndicesStats)
204
req.URL.RawQuery = "local=true&format=json"
205
206
var stats []esIndexStats
@@ -213,7 +213,7 @@ func (es *Elasticsearch) scrapeLocalIndicesStats(ms *esMetrics) {
213
}
214
215
func (es *Elasticsearch) getClusterName() (string, error) {
216
- req, _ := web.NewHTTPRequest(es.Request)
216
+ req, _ := web.NewHTTPRequest(es.RequestConfig)
217
218
var info struct {
219
ClusterName string `json:"cluster_name"`
src/go/plugin/go.d/modules/elasticsearch/elasticsearch.go
+6
-5
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -30,12 +31,12 @@ func init() {
31
func New() *Elasticsearch {
32
return &Elasticsearch{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Request: web.Request{
34
+ HTTPConfig: web.HTTPConfig{
35
+ RequestConfig: web.RequestConfig{
36
URL: "http://127.0.0.1:9200",
37
},
37
- Client: web.Client{
38
- Timeout: web.Duration(time.Second * 2),
38
+ ClientConfig: web.ClientConfig{
39
+ Timeout: confopt.Duration(time.Second * 2),
40
},
41
},
42
ClusterMode: false,
@@ -56,7 +57,7 @@ func New() *Elasticsearch {
57
58
type Config struct {
59
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
59
- web.HTTP `yaml:",inline" json:""`
60
+ web.HTTPConfig `yaml:",inline" json:""`
61
ClusterMode bool `yaml:"cluster_mode" json:"cluster_mode"`
62
DoNodeStats bool `yaml:"collect_node_stats" json:"collect_node_stats"`
63
DoClusterHealth bool `yaml:"collect_cluster_health" json:"collect_cluster_health"`
src/go/plugin/go.d/modules/elasticsearch/elasticsearch_test.go
+10
-10
@@ -57,8 +57,8 @@ func TestElasticsearch_Init(t *testing.T) {
57
},
58
"all stats": {
59
config: Config{
60
- HTTP: web.HTTP{
61
- Request: web.Request{URL: "http://127.0.0.1:38001"},
60
+ HTTPConfig: web.HTTPConfig{
61
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
62
},
63
DoNodeStats: true,
64
DoClusterHealth: true,
@@ -68,8 +68,8 @@ func TestElasticsearch_Init(t *testing.T) {
68
},
69
"only node_stats": {
70
config: Config{
71
- HTTP: web.HTTP{
72
- Request: web.Request{URL: "http://127.0.0.1:38001"},
71
+ HTTPConfig: web.HTTPConfig{
72
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
73
},
74
DoNodeStats: true,
75
DoClusterHealth: false,
@@ -80,15 +80,15 @@ func TestElasticsearch_Init(t *testing.T) {
80
"URL not set": {
81
wantFail: true,
82
config: Config{
83
- HTTP: web.HTTP{
84
- Request: web.Request{URL: ""},
83
+ HTTPConfig: web.HTTPConfig{
84
+ RequestConfig: web.RequestConfig{URL: ""},
85
}},
86
},
87
"invalid TLSCA": {
88
wantFail: true,
89
config: Config{
90
- HTTP: web.HTTP{
91
- Client: web.Client{
90
+ HTTPConfig: web.HTTPConfig{
91
+ ClientConfig: web.ClientConfig{
92
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
93
},
94
}},
@@ -96,8 +96,8 @@ func TestElasticsearch_Init(t *testing.T) {
96
"all API calls are disabled": {
97
wantFail: true,
98
config: Config{
99
- HTTP: web.HTTP{
100
- Request: web.Request{URL: "http://127.0.0.1:38001"},
99
+ HTTPConfig: web.HTTPConfig{
100
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
101
},
102
DoNodeStats: false,
103
DoClusterHealth: false,
src/go/plugin/go.d/modules/elasticsearch/init.go
+2
-2
@@ -16,12 +16,12 @@ func (es *Elasticsearch) validateConfig() error {
16
if !(es.DoNodeStats || es.DoClusterHealth || es.DoClusterStats || es.DoIndicesStats) {
17
return errors.New("all API calls are disabled")
18
}
19
- if _, err := web.NewHTTPRequest(es.Request); err != nil {
19
+ if _, err := web.NewHTTPRequest(es.RequestConfig); err != nil {
20
return err
21
}
22
return nil
23
}
24
25
func (es *Elasticsearch) initHTTPClient() (*http.Client, error) {
26
- return web.NewHTTPClient(es.Client)
26
+ return web.NewHTTPClient(es.ClientConfig)
27
}
src/go/plugin/go.d/modules/envoy/envoy.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *Envoy {
28
return &Envoy{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:9091/stats/prometheus",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -48,8 +49,8 @@ func New() *Envoy {
49
}
50
51
type Config struct {
51
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
52
- web.HTTP `yaml:",inline" json:""`
52
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
53
+ web.HTTPConfig `yaml:",inline" json:""`
54
}
55
56
type Envoy struct {
src/go/plugin/go.d/modules/envoy/envoy_test.go
+2
-2
@@ -50,8 +50,8 @@ func TestEnvoy_Init(t *testing.T) {
50
"fail when URL not set": {
51
wantFail: true,
52
config: Config{
53
- HTTP: web.HTTP{
54
- Request: web.Request{URL: ""},
53
+ HTTPConfig: web.HTTPConfig{
54
+ RequestConfig: web.RequestConfig{URL: ""},
55
},
56
},
57
},
src/go/plugin/go.d/modules/envoy/init.go
+2
-2
@@ -17,10 +17,10 @@ func (e *Envoy) validateConfig() error {
17
}
18
19
func (e *Envoy) initPrometheusClient() (prometheus.Prometheus, error) {
20
- httpClient, err := web.NewHTTPClient(e.Client)
20
+ httpClient, err := web.NewHTTPClient(e.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
25
- return prometheus.New(httpClient, e.Request), nil
25
+ return prometheus.New(httpClient, e.RequestConfig), nil
26
}
src/go/plugin/go.d/modules/exim/exim.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,15 +28,15 @@ func init() {
28
func New() *Exim {
29
return &Exim{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: charts.Copy(),
34
}
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
}
41
42
type Exim struct {
src/go/plugin/go.d/modules/fail2ban/fail2ban.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *Fail2Ban {
29
return &Fail2Ban{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
discoverEvery: time.Minute * 5,
@@ -37,8 +37,8 @@ func New() *Fail2Ban {
37
}
38
39
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
}
43
44
type (
src/go/plugin/go.d/modules/filecheck/filecheck.go
+6
-6
@@ -7,8 +7,8 @@ import (
7
"time"
8
9
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
10
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *Filecheck {
29
return &Filecheck{
30
Config: Config{
31
- DiscoveryEvery: web.Duration(time.Minute * 1),
31
+ DiscoveryEvery: confopt.Duration(time.Minute * 1),
32
Files: filesConfig{},
33
Dirs: dirsConfig{CollectDirSize: false},
34
},
@@ -40,10 +40,10 @@ func New() *Filecheck {
40
41
type (
42
Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- DiscoveryEvery web.Duration `yaml:"discovery_every,omitempty" json:"discovery_every"`
45
- Files filesConfig `yaml:"files" json:"files"`
46
- Dirs dirsConfig `yaml:"dirs" json:"dirs"`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ DiscoveryEvery confopt.Duration `yaml:"discovery_every,omitempty" json:"discovery_every"`
45
+ Files filesConfig `yaml:"files" json:"files"`
46
+ Dirs dirsConfig `yaml:"dirs" json:"dirs"`
47
}
48
filesConfig struct {
49
Include []string `yaml:"include" json:"include"`
src/go/plugin/go.d/modules/fluentd/apiclient.go
+2
-2
@@ -39,13 +39,13 @@ func (p pluginData) hasBufferTotalQueuedSize() bool {
39
return p.BufferTotalQueuedSize != nil
40
}
41
42
-func newAPIClient(client *http.Client, request web.Request) *apiClient {
42
+func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient {
43
return &apiClient{httpClient: client, request: request}
44
}
45
46
type apiClient struct {
47
httpClient *http.Client
48
- request web.Request
48
+ request web.RequestConfig
49
}
50
51
func (a apiClient) getPluginsInfo() (*pluginsInfo, error) {
src/go/plugin/go.d/modules/fluentd/fluentd.go
+8
-7
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *Fluentd {
28
return &Fluentd{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:24220",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
}},
38
activePlugins: make(map[string]bool),
@@ -40,9 +41,9 @@ func New() *Fluentd {
41
}
42
43
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- web.HTTP `yaml:",inline" json:""`
45
- PermitPlugin string `yaml:"permit_plugin_id,omitempty" json:"permit_plugin_id"`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ web.HTTPConfig `yaml:",inline" json:""`
46
+ PermitPlugin string `yaml:"permit_plugin_id,omitempty" json:"permit_plugin_id"`
47
}
48
49
type Fluentd struct {
src/go/plugin/go.d/modules/fluentd/init.go
+2
-2
@@ -26,10 +26,10 @@ func (f *Fluentd) initPermitPluginMatcher() (matcher.Matcher, error) {
26
}
27
28
func (f *Fluentd) initApiClient() (*apiClient, error) {
29
- client, err := web.NewHTTPClient(f.Client)
29
+ client, err := web.NewHTTPClient(f.ClientConfig)
30
if err != nil {
31
return nil, err
32
}
33
34
- return newAPIClient(client, f.Request), nil
34
+ return newAPIClient(client, f.RequestConfig), nil
35
}
src/go/plugin/go.d/modules/freeradius/freeradius.go
+7
-7
@@ -9,7 +9,7 @@ import (
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/freeradius/api"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
)
14
15
//go:embed "config_schema.json"
@@ -29,17 +29,17 @@ func New() *FreeRADIUS {
29
Address: "127.0.0.1",
30
Port: 18121,
31
Secret: "adminsecret",
32
- Timeout: web.Duration(time.Second),
32
+ Timeout: confopt.Duration(time.Second),
33
},
34
}
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every" json:"update_every"`
39
- Address string `yaml:"address" json:"address"`
40
- Port int `yaml:"port" json:"port"`
41
- Secret string `yaml:"secret" json:"secret"`
42
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
38
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
39
+ Address string `yaml:"address" json:"address"`
40
+ Port int `yaml:"port" json:"port"`
41
+ Secret string `yaml:"secret" json:"secret"`
42
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
43
}
44
45
type (
src/go/plugin/go.d/modules/gearman/gearman.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Gearman {
26
return &Gearman{
27
Config: Config{
28
Address: "127.0.0.1:4730",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newConn: newGearmanConn,
32
charts: summaryCharts.Copy(),
@@ -36,9 +36,9 @@ func New() *Gearman {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Address string `yaml:"address" json:"address"`
41
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Address string `yaml:"address" json:"address"`
41
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
42
}
43
44
type Gearman struct {
src/go/plugin/go.d/modules/geth/geth.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *Geth {
28
return &Geth{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:6060/debug/metrics/prometheus",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -40,8 +41,8 @@ func New() *Geth {
41
}
42
43
type Config struct {
43
- web.HTTP `yaml:",inline" json:""`
44
- UpdateEvery int `yaml:"update_every" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
46
}
47
48
type Geth struct {
src/go/plugin/go.d/modules/geth/init.go
+2
-2
@@ -15,10 +15,10 @@ func (g *Geth) validateConfig() error {
15
}
16
17
func (g *Geth) initPrometheusClient() (prometheus.Prometheus, error) {
18
- client, err := web.NewHTTPClient(g.Client)
18
+ client, err := web.NewHTTPClient(g.ClientConfig)
19
if err != nil {
20
return nil, err
21
}
22
23
- return prometheus.New(client, g.Request), nil
23
+ return prometheus.New(client, g.RequestConfig), nil
24
}
src/go/plugin/go.d/modules/haproxy/haproxy.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *Haproxy {
28
return &Haproxy{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8404/metrics",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -43,8 +44,8 @@ func New() *Haproxy {
44
}
45
46
type Config struct {
46
- web.HTTP `yaml:",inline" json:""`
47
- UpdateEvery int `yaml:"update_every" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
49
}
50
51
type Haproxy struct {
src/go/plugin/go.d/modules/haproxy/haproxy_test.go
+4
-4
@@ -47,15 +47,15 @@ func TestHaproxy_Init(t *testing.T) {
47
},
48
"fails on unset 'url'": {
49
wantFail: true,
50
- config: Config{HTTP: web.HTTP{
51
- Request: web.Request{},
50
+ config: Config{HTTPConfig: web.HTTPConfig{
51
+ RequestConfig: web.RequestConfig{},
52
}},
53
},
54
"fails on invalid TLSCA": {
55
wantFail: true,
56
config: Config{
57
- HTTP: web.HTTP{
58
- Client: web.Client{
57
+ HTTPConfig: web.HTTPConfig{
58
+ ClientConfig: web.ClientConfig{
59
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
60
},
61
}},
src/go/plugin/go.d/modules/haproxy/init.go
+3
-3
@@ -14,19 +14,19 @@ func (h *Haproxy) validateConfig() error {
14
if h.URL == "" {
15
return errors.New("'url' is not set")
16
}
17
- if _, err := web.NewHTTPRequest(h.Request); err != nil {
17
+ if _, err := web.NewHTTPRequest(h.RequestConfig); err != nil {
18
return err
19
}
20
return nil
21
}
22
23
func (h *Haproxy) initPrometheusClient() (prometheus.Prometheus, error) {
24
- httpClient, err := web.NewHTTPClient(h.Client)
24
+ httpClient, err := web.NewHTTPClient(h.ClientConfig)
25
if err != nil {
26
return nil, err
27
}
28
29
- prom := prometheus.NewWithSelector(httpClient, h.Request, sr)
29
+ prom := prometheus.NewWithSelector(httpClient, h.RequestConfig, sr)
30
return prom, nil
31
}
32
src/go/plugin/go.d/modules/hddtemp/hddtemp.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *HddTemp {
26
return &HddTemp{
27
Config: Config{
28
Address: "127.0.0.1:7634",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newHddTempConn: newHddTempConn,
32
charts: &module.Charts{},
@@ -36,9 +36,9 @@ func New() *HddTemp {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every" json:"update_every"`
40
- Address string `yaml:"address" json:"address"`
41
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
39
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
40
+ Address string `yaml:"address" json:"address"`
41
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
42
}
43
44
type (
src/go/plugin/go.d/modules/hdfs/client.go
+2
-2
@@ -10,7 +10,7 @@ import (
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
)
12
13
-func newClient(httpClient *http.Client, request web.Request) *client {
13
+func newClient(httpClient *http.Client, request web.RequestConfig) *client {
14
return &client{
15
httpClient: httpClient,
16
request: request,
@@ -19,7 +19,7 @@ func newClient(httpClient *http.Client, request web.Request) *client {
19
20
type client struct {
21
httpClient *http.Client
22
- request web.Request
22
+ request web.RequestConfig
23
}
24
25
func (c *client) do() (*http.Response, error) {
src/go/plugin/go.d/modules/hdfs/hdfs.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -24,12 +25,12 @@ func init() {
25
26
func New() *HDFS {
27
config := Config{
27
- HTTP: web.HTTP{
28
- Request: web.Request{
28
+ HTTPConfig: web.HTTPConfig{
29
+ RequestConfig: web.RequestConfig{
30
URL: "http://127.0.0.1:9870/jmx",
31
},
31
- Client: web.Client{
32
- Timeout: web.Duration(time.Second),
32
+ ClientConfig: web.ClientConfig{
33
+ Timeout: confopt.Duration(time.Second),
34
},
35
},
36
}
@@ -40,8 +41,8 @@ func New() *HDFS {
41
}
42
43
type Config struct {
43
- web.HTTP `yaml:",inline" json:""`
44
- UpdateEvery int `yaml:"update_every" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
46
}
47
48
type (
src/go/plugin/go.d/modules/hdfs/hdfs_test.go
+1
-1
@@ -47,7 +47,7 @@ func TestHDFS_Init(t *testing.T) {
47
48
func TestHDFS_InitErrorOnCreatingClientWrongTLSCA(t *testing.T) {
49
job := New()
50
- job.Client.TLSConfig.TLSCA = "testdata/tls"
50
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
51
52
assert.Error(t, job.Init())
53
}
src/go/plugin/go.d/modules/hdfs/init.go
+2
-2
@@ -16,10 +16,10 @@ func (h *HDFS) validateConfig() error {
16
}
17
18
func (h *HDFS) createClient() (*client, error) {
19
- httpClient, err := web.NewHTTPClient(h.Client)
19
+ httpClient, err := web.NewHTTPClient(h.ClientConfig)
20
if err != nil {
21
return nil, err
22
}
23
24
- return newClient(httpClient, h.Request), nil
24
+ return newClient(httpClient, h.RequestConfig), nil
25
}
src/go/plugin/go.d/modules/hpssa/hpssa.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *Hpssa {
29
return &Hpssa{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
seenControllers: make(map[string]*hpssaController),
@@ -39,8 +39,8 @@ func New() *Hpssa {
39
}
40
41
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
}
45
46
type (
src/go/plugin/go.d/modules/httpcheck/collect.go
+2
-2
@@ -25,9 +25,9 @@ const (
25
)
26
27
func (hc *HTTPCheck) collect() (map[string]int64, error) {
28
- req, err := web.NewHTTPRequest(hc.Request)
28
+ req, err := web.NewHTTPRequest(hc.RequestConfig)
29
if err != nil {
30
- return nil, fmt.Errorf("error on creating HTTP requests to %s : %v", hc.Request.URL, err)
30
+ return nil, fmt.Errorf("error on creating HTTP requests to %s : %v", hc.RequestConfig.URL, err)
31
}
32
33
if hc.CookieFile != "" {
src/go/plugin/go.d/modules/httpcheck/httpcheck.go
+6
-5
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -30,9 +31,9 @@ func init() {
31
func New() *HTTPCheck {
32
return &HTTPCheck{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Client: web.Client{
35
- Timeout: web.Duration(time.Second),
34
+ HTTPConfig: web.HTTPConfig{
35
+ ClientConfig: web.ClientConfig{
36
+ Timeout: confopt.Duration(time.Second),
37
},
38
},
39
AcceptedStatuses: []int{200},
@@ -45,7 +46,7 @@ func New() *HTTPCheck {
46
type (
47
Config struct {
48
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- web.HTTP `yaml:",inline" json:""`
49
+ web.HTTPConfig `yaml:",inline" json:""`
50
AcceptedStatuses []int `yaml:"status_accepted" json:"status_accepted"`
51
ResponseMatch string `yaml:"response_match,omitempty" json:"response_match"`
52
CookieFile string `yaml:"cookie_file,omitempty" json:"cookie_file"`
@@ -113,7 +114,7 @@ func (hc *HTTPCheck) Init() error {
114
115
hc.Debugf("using URL %s", hc.URL)
116
hc.Debugf("using HTTP timeout %s", hc.Timeout.Duration())
116
- hc.Debugf("using accepted HTTP statuses %v", hc.AcceptedStatuses)
117
+ hc.Debugf("using accepted HTTPConfig statuses %v", hc.AcceptedStatuses)
118
if hc.reResponse != nil {
119
hc.Debugf("using response match regexp %s", hc.reResponse)
120
}
src/go/plugin/go.d/modules/httpcheck/httpcheck_test.go
+8
-7
@@ -4,6 +4,7 @@ package httpcheck
4
5
import (
6
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
7
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
8
"net/http"
9
"net/http/httptest"
10
"os"
@@ -42,8 +43,8 @@ func TestHTTPCheck_Init(t *testing.T) {
43
"success if url set": {
44
wantFail: false,
45
config: Config{
45
- HTTP: web.HTTP{
46
- Request: web.Request{URL: "http://127.0.0.1:38001"},
46
+ HTTPConfig: web.HTTPConfig{
47
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
48
},
49
},
50
},
@@ -54,16 +55,16 @@ func TestHTTPCheck_Init(t *testing.T) {
55
"fail when URL not set": {
56
wantFail: true,
57
config: Config{
57
- HTTP: web.HTTP{
58
- Request: web.Request{URL: ""},
58
+ HTTPConfig: web.HTTPConfig{
59
+ RequestConfig: web.RequestConfig{URL: ""},
60
},
61
},
62
},
63
"fail if wrong response regex": {
64
wantFail: true,
65
config: Config{
65
- HTTP: web.HTTP{
66
- Request: web.Request{URL: "http://127.0.0.1:38001"},
66
+ HTTPConfig: web.HTTPConfig{
67
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:38001"},
68
},
69
ResponseMatch: "(?:qwe))",
70
},
@@ -495,7 +496,7 @@ func prepareSuccessCase() (*HTTPCheck, func()) {
496
func prepareTimeoutCase() (*HTTPCheck, func()) {
497
httpCheck := New()
498
httpCheck.UpdateEvery = 1
498
- httpCheck.Timeout = web.Duration(time.Millisecond * 100)
499
+ httpCheck.Timeout = confopt.Duration(time.Millisecond * 100)
500
501
srv := httptest.NewServer(http.HandlerFunc(
502
func(w http.ResponseWriter, r *http.Request) {
src/go/plugin/go.d/modules/httpcheck/init.go
+1
-1
@@ -27,7 +27,7 @@ func (hc *HTTPCheck) validateConfig() error {
27
}
28
29
func (hc *HTTPCheck) initHTTPClient() (*http.Client, error) {
30
- return web.NewHTTPClient(hc.Client)
30
+ return web.NewHTTPClient(hc.ClientConfig)
31
}
32
33
func (hc *HTTPCheck) initResponseMatchRegexp() (*regexp.Regexp, error) {
src/go/plugin/go.d/modules/icecast/collect.go
+1
-1
@@ -67,7 +67,7 @@ func (ic *Icecast) collectServerStats(mx map[string]int64) error {
67
}
68
69
func (ic *Icecast) queryServerStats() (*serverStats, error) {
70
- req, err := web.NewHTTPRequestWithPath(ic.Request, urlPathServerStats)
70
+ req, err := web.NewHTTPRequestWithPath(ic.RequestConfig, urlPathServerStats)
71
if err != nil {
72
return nil, err
73
}
src/go/plugin/go.d/modules/icecast/icecast.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Icecast {
28
return &Icecast{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8000",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -42,8 +43,8 @@ func New() *Icecast {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type Icecast struct {
@@ -67,7 +68,7 @@ func (ic *Icecast) Init() error {
68
return errors.New("url not set")
69
}
70
70
- client, err := web.NewHTTPClient(ic.Client)
71
+ client, err := web.NewHTTPClient(ic.ClientConfig)
72
if err != nil {
73
ic.Error(err)
74
return err
src/go/plugin/go.d/modules/icecast/icecast_test.go
+2
-2
@@ -52,8 +52,8 @@ func TestIcecast_Init(t *testing.T) {
52
"fail when URL not set": {
53
wantFail: true,
54
config: Config{
55
- HTTP: web.HTTP{
56
- Request: web.Request{URL: ""},
55
+ HTTPConfig: web.HTTPConfig{
56
+ RequestConfig: web.RequestConfig{URL: ""},
57
},
58
},
59
},
src/go/plugin/go.d/modules/ipfs/collect.go
+4
-4
@@ -124,7 +124,7 @@ func (ip *IPFS) collectPinLs(mx map[string]int64) error {
124
}
125
126
func (ip *IPFS) queryStatsBandwidth() (*ipfsStatsBw, error) {
127
- req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathStatsBandwidth)
127
+ req, err := web.NewHTTPRequestWithPath(ip.RequestConfig, urlPathStatsBandwidth)
128
if err != nil {
129
return nil, err
130
}
@@ -142,7 +142,7 @@ func (ip *IPFS) queryStatsBandwidth() (*ipfsStatsBw, error) {
142
}
143
144
func (ip *IPFS) querySwarmPeers() (*ipfsSwarmPeers, error) {
145
- req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathSwarmPeers)
145
+ req, err := web.NewHTTPRequestWithPath(ip.RequestConfig, urlPathSwarmPeers)
146
if err != nil {
147
return nil, err
148
}
@@ -156,7 +156,7 @@ func (ip *IPFS) querySwarmPeers() (*ipfsSwarmPeers, error) {
156
}
157
158
func (ip *IPFS) queryStatsRepo() (*ipfsStatsRepo, error) {
159
- req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathStatsRepo)
159
+ req, err := web.NewHTTPRequestWithPath(ip.RequestConfig, urlPathStatsRepo)
160
if err != nil {
161
return nil, err
162
}
@@ -170,7 +170,7 @@ func (ip *IPFS) queryStatsRepo() (*ipfsStatsRepo, error) {
170
}
171
172
func (ip *IPFS) queryPinLs() (*ipfsPinsLs, error) {
173
- req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathPinLs)
173
+ req, err := web.NewHTTPRequestWithPath(ip.RequestConfig, urlPathPinLs)
174
if err != nil {
175
return nil, err
176
}
src/go/plugin/go.d/modules/ipfs/ipfs.go
+10
-9
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,13 +27,13 @@ func init() {
27
func New() *IPFS {
28
return &IPFS{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:5001",
33
Method: http.MethodPost,
34
},
34
- Client: web.Client{
35
- Timeout: web.Duration(time.Second * 1),
35
+ ClientConfig: web.ClientConfig{
36
+ Timeout: confopt.Duration(time.Second * 1),
37
},
38
},
39
QueryRepoApi: false,
@@ -43,10 +44,10 @@ func New() *IPFS {
44
}
45
46
type Config struct {
46
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
- web.HTTP `yaml:",inline" json:""`
48
- QueryPinApi bool `yaml:"pinapi" json:"pinapi"`
49
- QueryRepoApi bool `yaml:"repoapi" json:"repoapi"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ web.HTTPConfig `yaml:",inline" json:""`
49
+ QueryPinApi bool `yaml:"pinapi" json:"pinapi"`
50
+ QueryRepoApi bool `yaml:"repoapi" json:"repoapi"`
51
}
52
53
type IPFS struct {
@@ -68,7 +69,7 @@ func (ip *IPFS) Init() error {
69
return errors.New("url not set")
70
}
71
71
- client, err := web.NewHTTPClient(ip.Client)
72
+ client, err := web.NewHTTPClient(ip.ClientConfig)
73
if err != nil {
74
ip.Error(err)
75
return err
src/go/plugin/go.d/modules/ipfs/ipfs_test.go
+2
-2
@@ -54,8 +54,8 @@ func TestIPFS_Init(t *testing.T) {
54
"fail when URL not set": {
55
wantFail: true,
56
config: Config{
57
- HTTP: web.HTTP{
58
- Request: web.Request{URL: ""},
57
+ HTTPConfig: web.HTTPConfig{
58
+ RequestConfig: web.RequestConfig{URL: ""},
59
},
60
},
61
},
src/go/plugin/go.d/modules/k8s_kubelet/init.go
+2
-2
@@ -26,10 +26,10 @@ func (k *Kubelet) initAuthToken() string {
26
}
27
28
func (k *Kubelet) initPrometheusClient() (prometheus.Prometheus, error) {
29
- httpClient, err := web.NewHTTPClient(k.Client)
29
+ httpClient, err := web.NewHTTPClient(k.ClientConfig)
30
if err != nil {
31
return nil, err
32
}
33
34
- return prometheus.New(httpClient, k.Request), nil
34
+ return prometheus.New(httpClient, k.RequestConfig), nil
35
}
src/go/plugin/go.d/modules/k8s_kubelet/kubelet.go
+9
-8
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -30,13 +31,13 @@ func init() {
31
func New() *Kubelet {
32
return &Kubelet{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Request: web.Request{
34
+ HTTPConfig: web.HTTPConfig{
35
+ RequestConfig: web.RequestConfig{
36
URL: "http://127.0.0.1:10255/metrics",
37
Headers: make(map[string]string),
38
},
38
- Client: web.Client{
39
- Timeout: web.Duration(time.Second),
39
+ ClientConfig: web.ClientConfig{
40
+ Timeout: confopt.Duration(time.Second),
41
},
42
},
43
TokenPath: "/var/run/secrets/kubernetes.io/serviceaccount/token",
@@ -48,9 +49,9 @@ func New() *Kubelet {
49
}
50
51
type Config struct {
51
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
52
- web.HTTP `yaml:",inline" json:""`
53
- TokenPath string `yaml:"token_path,omitempty" json:"token_path"`
52
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
53
+ web.HTTPConfig `yaml:",inline" json:""`
54
+ TokenPath string `yaml:"token_path,omitempty" json:"token_path"`
55
}
56
57
type Kubelet struct {
@@ -82,7 +83,7 @@ func (k *Kubelet) Init() error {
83
k.prom = prom
84
85
if tok := k.initAuthToken(); tok != "" {
85
- k.Request.Headers["Authorization"] = "Bearer " + tok
86
+ k.RequestConfig.Headers["Authorization"] = "Bearer " + tok
87
}
88
89
return nil
src/go/plugin/go.d/modules/k8s_kubelet/kubelet_test.go
+2
-2
@@ -54,12 +54,12 @@ func TestKubelet_Init_ReadServiceAccountToken(t *testing.T) {
54
job.TokenPath = "testdata/token.txt"
55
56
assert.NoError(t, job.Init())
57
- assert.Equal(t, "Bearer "+string(dataServiceAccountToken), job.Request.Headers["Authorization"])
57
+ assert.Equal(t, "Bearer "+string(dataServiceAccountToken), job.RequestConfig.Headers["Authorization"])
58
}
59
60
func TestKubelet_InitErrorOnCreatingClientWrongTLSCA(t *testing.T) {
61
job := New()
62
- job.Client.TLSConfig.TLSCA = "testdata/tls"
62
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
63
64
assert.Error(t, job.Init())
65
}
src/go/plugin/go.d/modules/k8s_kubeproxy/init.go
+2
-2
@@ -17,10 +17,10 @@ func (kp *KubeProxy) validateConfig() error {
17
}
18
19
func (kp *KubeProxy) initPrometheusClient() (prometheus.Prometheus, error) {
20
- httpClient, err := web.NewHTTPClient(kp.Client)
20
+ httpClient, err := web.NewHTTPClient(kp.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
25
- return prometheus.New(httpClient, kp.Request), nil
25
+ return prometheus.New(httpClient, kp.RequestConfig), nil
26
}
src/go/plugin/go.d/modules/k8s_kubeproxy/kubeproxy.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -30,12 +31,12 @@ func init() {
31
func New() *KubeProxy {
32
return &KubeProxy{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Request: web.Request{
34
+ HTTPConfig: web.HTTPConfig{
35
+ RequestConfig: web.RequestConfig{
36
URL: "http://127.0.0.1:10249/metrics",
37
},
37
- Client: web.Client{
38
- Timeout: web.Duration(time.Second),
38
+ ClientConfig: web.ClientConfig{
39
+ Timeout: confopt.Duration(time.Second),
40
},
41
},
42
},
@@ -44,8 +45,8 @@ func New() *KubeProxy {
45
}
46
47
type Config struct {
47
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- web.HTTP `yaml:",inline" json:""`
48
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
+ web.HTTPConfig `yaml:",inline" json:""`
50
}
51
52
type KubeProxy struct {
src/go/plugin/go.d/modules/lighttpd/apiclient.go
+2
-2
@@ -25,13 +25,13 @@ const (
25
scoreBoard = "Scoreboard"
26
)
27
28
-func newAPIClient(client *http.Client, request web.Request) *apiClient {
28
+func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient {
29
return &apiClient{httpClient: client, request: request}
30
}
31
32
type apiClient struct {
33
httpClient *http.Client
34
- request web.Request
34
+ request web.RequestConfig
35
}
36
37
func (a apiClient) getServerStatus() (*serverStatus, error) {
src/go/plugin/go.d/modules/lighttpd/init.go
+2
-2
@@ -21,9 +21,9 @@ func (l *Lighttpd) validateConfig() error {
21
}
22
23
func (l *Lighttpd) initApiClient() (*apiClient, error) {
24
- client, err := web.NewHTTPClient(l.Client)
24
+ client, err := web.NewHTTPClient(l.ClientConfig)
25
if err != nil {
26
return nil, err
27
}
28
- return newAPIClient(client, l.Request), nil
28
+ return newAPIClient(client, l.RequestConfig), nil
29
}
src/go/plugin/go.d/modules/lighttpd/lighttpd.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -24,20 +25,20 @@ func init() {
25
26
func New() *Lighttpd {
27
return &Lighttpd{Config: Config{
27
- HTTP: web.HTTP{
28
- Request: web.Request{
28
+ HTTPConfig: web.HTTPConfig{
29
+ RequestConfig: web.RequestConfig{
30
URL: "http://127.0.0.1/server-status?auto",
31
},
31
- Client: web.Client{
32
- Timeout: web.Duration(time.Second * 2),
32
+ ClientConfig: web.ClientConfig{
33
+ Timeout: confopt.Duration(time.Second * 2),
34
},
35
},
36
}}
37
}
38
39
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- web.HTTP `yaml:",inline" json:""`
40
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
+ web.HTTPConfig `yaml:",inline" json:""`
42
}
43
44
type Lighttpd struct {
src/go/plugin/go.d/modules/logind/logind.go
+4
-4
@@ -11,7 +11,7 @@ import (
11
"time"
12
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
15
)
16
17
//go:embed "config_schema.json"
@@ -31,7 +31,7 @@ func init() {
31
func New() *Logind {
32
return &Logind{
33
Config: Config{
34
- Timeout: web.Duration(time.Second),
34
+ Timeout: confopt.Duration(time.Second),
35
},
36
newLogindConn: func(cfg Config) (logindConnection, error) {
37
return newLogindConnection(cfg.Timeout.Duration())
@@ -41,8 +41,8 @@ func New() *Logind {
41
}
42
43
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
46
}
47
48
type Logind struct {
src/go/plugin/go.d/modules/logstash/collect.go
+1
-1
@@ -45,7 +45,7 @@ func (l *Logstash) updateCharts(pipelines map[string]pipelineStats) {
45
}
46
47
func (l *Logstash) queryNodeStats() (*nodeStats, error) {
48
- req, err := web.NewHTTPRequestWithPath(l.Request, urlPathNodeStatsAPI)
48
+ req, err := web.NewHTTPRequestWithPath(l.RequestConfig, urlPathNodeStatsAPI)
49
if err != nil {
50
return nil, err
51
}
src/go/plugin/go.d/modules/logstash/logstash.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Logstash {
28
return &Logstash{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://localhost:9600",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -41,8 +42,8 @@ func New() *Logstash {
42
}
43
44
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- web.HTTP `yaml:",inline" json:""`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ web.HTTPConfig `yaml:",inline" json:""`
47
}
48
49
type Logstash struct {
@@ -66,7 +67,7 @@ func (l *Logstash) Init() error {
67
return errors.New("url not set")
68
}
69
69
- httpClient, err := web.NewHTTPClient(l.Client)
70
+ httpClient, err := web.NewHTTPClient(l.ClientConfig)
71
if err != nil {
72
l.Errorf("init HTTP client: %v", err)
73
return err
src/go/plugin/go.d/modules/logstash/logstash_test.go
+2
-2
@@ -49,8 +49,8 @@ func TestLogstash_Init(t *testing.T) {
49
"fail when URL not set": {
50
wantFail: true,
51
config: Config{
52
- HTTP: web.HTTP{
53
- Request: web.Request{URL: ""},
52
+ HTTPConfig: web.HTTPConfig{
53
+ RequestConfig: web.RequestConfig{URL: ""},
54
},
55
},
56
},
src/go/plugin/go.d/modules/lvm/lvm.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *LVM {
29
return &LVM{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
lvmThinPools: make(map[string]bool),
@@ -36,8 +36,8 @@ func New() *LVM {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
}
42
43
type (
src/go/plugin/go.d/modules/megacli/megacli.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *MegaCli {
29
return &MegaCli{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
adapters: make(map[string]bool),
@@ -38,8 +38,8 @@ func New() *MegaCli {
38
}
39
40
type Config struct {
41
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
}
44
45
type (
src/go/plugin/go.d/modules/memcached/memcached.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Memcached {
26
return &Memcached{
27
Config: Config{
28
Address: "127.0.0.1:11211",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newMemcachedConn: newMemcachedConn,
32
charts: charts.Copy(),
@@ -34,9 +34,9 @@ func New() *Memcached {
34
}
35
36
type Config struct {
37
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
- Address string `yaml:"address" json:"address"`
39
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
37
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
+ Address string `yaml:"address" json:"address"`
39
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
40
}
41
42
type (
src/go/plugin/go.d/modules/mongodb/mongodb.go
+3
-3
@@ -9,8 +9,8 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
16
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func New() *Mongo {
28
return &Mongo{
29
Config: Config{
30
URI: "mongodb://localhost:27017",
31
- Timeout: web.Duration(time.Second),
31
+ Timeout: confopt.Duration(time.Second),
32
Databases: matcher.SimpleExpr{
33
Includes: []string{},
34
Excludes: []string{},
@@ -50,7 +50,7 @@ func New() *Mongo {
50
type Config struct {
51
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
52
URI string `yaml:"uri" json:"uri"`
53
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
53
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
54
Databases matcher.SimpleExpr `yaml:"databases,omitempty" json:"databases"`
55
}
56
src/go/plugin/go.d/modules/monit/collect.go
+1
-1
@@ -73,7 +73,7 @@ func (m *Monit) collectStatus(mx map[string]int64) error {
73
}
74
75
func (m *Monit) fetchStatus() (*monitStatus, error) {
76
- req, err := web.NewHTTPRequestWithPath(m.Request, urlPathStatus)
76
+ req, err := web.NewHTTPRequestWithPath(m.RequestConfig, urlPathStatus)
77
if err != nil {
78
return nil, err
79
}
src/go/plugin/go.d/modules/monit/monit.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,14 +27,14 @@ func init() {
27
func New() *Monit {
28
return &Monit{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:2812",
33
Username: "admin",
34
Password: "monit",
35
},
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second),
36
+ ClientConfig: web.ClientConfig{
37
+ Timeout: confopt.Duration(time.Second),
38
},
39
},
40
},
@@ -43,8 +44,8 @@ func New() *Monit {
44
}
45
46
type Config struct {
46
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
- web.HTTP `yaml:",inline" json:""`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ web.HTTPConfig `yaml:",inline" json:""`
49
}
50
51
type Monit struct {
@@ -68,7 +69,7 @@ func (m *Monit) Init() error {
69
return errors.New("config: missing URL")
70
}
71
71
- httpClient, err := web.NewHTTPClient(m.Client)
72
+ httpClient, err := web.NewHTTPClient(m.ClientConfig)
73
if err != nil {
74
m.Errorf("init HTTP client: %v", err)
75
return err
src/go/plugin/go.d/modules/monit/monit_test.go
+2
-2
@@ -49,8 +49,8 @@ func TestMonit_Init(t *testing.T) {
49
"fail when URL not set": {
50
wantFail: true,
51
config: Config{
52
- HTTP: web.HTTP{
53
- Request: web.Request{URL: ""},
52
+ HTTPConfig: web.HTTPConfig{
53
+ RequestConfig: web.RequestConfig{URL: ""},
54
},
55
},
56
},
src/go/plugin/go.d/modules/mysql/mysql.go
+8
-8
@@ -10,12 +10,12 @@ import (
10
"sync"
11
"time"
12
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
-
13
"github.com/blang/semver/v4"
14
"github.com/go-sql-driver/mysql"
15
_ "github.com/go-sql-driver/mysql"
16
+
17
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
18
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
19
)
20
21
//go:embed "config_schema.json"
@@ -33,7 +33,7 @@ func New() *MySQL {
33
return &MySQL{
34
Config: Config{
35
DSN: "root@tcp(localhost:3306)/",
36
- Timeout: web.Duration(time.Second),
36
+ Timeout: confopt.Duration(time.Second),
37
},
38
39
charts: baseCharts.Copy(),
@@ -55,10 +55,10 @@ func New() *MySQL {
55
}
56
57
type Config struct {
58
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
59
- DSN string `yaml:"dsn" json:"dsn"`
60
- MyCNF string `yaml:"my.cnf,omitempty" json:"my.cnf"`
61
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
58
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
59
+ DSN string `yaml:"dsn" json:"dsn"`
60
+ MyCNF string `yaml:"my.cnf,omitempty" json:"my.cnf"`
61
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
62
}
63
64
type MySQL struct {
src/go/plugin/go.d/modules/nginx/apiclient.go
+2
-2
@@ -49,13 +49,13 @@ var (
49
reStatus = regexp.MustCompile(`^Active connections: ([0-9]+)\n[^\d]+([0-9]+) ([0-9]+) ([0-9]+) ?([0-9]+)?\nReading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+)`)
50
)
51
52
-func newAPIClient(client *http.Client, request web.Request) *apiClient {
52
+func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient {
53
return &apiClient{httpClient: client, request: request}
54
}
55
56
type apiClient struct {
57
httpClient *http.Client
58
- request web.Request
58
+ request web.RequestConfig
59
}
60
61
func (a apiClient) getStubStatus() (*stubStatus, error) {
src/go/plugin/go.d/modules/nginx/nginx.go
+9
-8
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -25,20 +26,20 @@ func init() {
26
func New() *Nginx {
27
return &Nginx{
28
Config: Config{
28
- HTTP: web.HTTP{
29
- Request: web.Request{
29
+ HTTPConfig: web.HTTPConfig{
30
+ RequestConfig: web.RequestConfig{
31
URL: "http://127.0.0.1/stub_status",
32
},
32
- Client: web.Client{
33
- Timeout: web.Duration(time.Second * 1),
33
+ ClientConfig: web.ClientConfig{
34
+ Timeout: confopt.Duration(time.Second * 1),
35
},
36
},
37
}}
38
}
39
40
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- web.HTTP `yaml:",inline" json:""`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ web.HTTPConfig `yaml:",inline" json:""`
43
}
44
45
type Nginx struct {
@@ -58,13 +59,13 @@ func (n *Nginx) Init() error {
59
return errors.New("url not set")
60
}
61
61
- client, err := web.NewHTTPClient(n.Client)
62
+ client, err := web.NewHTTPClient(n.ClientConfig)
63
if err != nil {
64
n.Error(err)
65
return err
66
}
67
67
- n.apiClient = newAPIClient(client, n.Request)
68
+ n.apiClient = newAPIClient(client, n.RequestConfig)
69
70
n.Debugf("using URL %s", n.URL)
71
n.Debugf("using timeout: %s", n.Timeout)
src/go/plugin/go.d/modules/nginxplus/nginx_http_api_query.go
+15
-15
@@ -46,7 +46,7 @@ type nginxMetrics struct {
46
}
47
48
func (n *NginxPlus) queryAPIVersion() (int64, error) {
49
- req, _ := web.NewHTTPRequestWithPath(n.Request, urlPathAPIVersions)
49
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, urlPathAPIVersions)
50
51
var versions nginxAPIVersions
52
if err := n.doWithDecode(&versions, req); err != nil {
@@ -61,7 +61,7 @@ func (n *NginxPlus) queryAPIVersion() (int64, error) {
61
}
62
63
func (n *NginxPlus) queryAvailableEndpoints() error {
64
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsRoot, n.apiVersion))
64
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIEndpointsRoot, n.apiVersion))
65
66
var endpoints []string
67
if err := n.doWithDecode(&endpoints, req); err != nil {
@@ -89,7 +89,7 @@ func (n *NginxPlus) queryAvailableEndpoints() error {
89
90
if hasHTTP {
91
endpoints = endpoints[:0]
92
- req, _ = web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsHTTP, n.apiVersion))
92
+ req, _ = web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIEndpointsHTTP, n.apiVersion))
93
94
if err := n.doWithDecode(&endpoints, req); err != nil {
95
return err
@@ -114,7 +114,7 @@ func (n *NginxPlus) queryAvailableEndpoints() error {
114
115
if hasStream {
116
endpoints = endpoints[:0]
117
- req, _ = web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsStream, n.apiVersion))
117
+ req, _ = web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIEndpointsStream, n.apiVersion))
118
119
if err := n.doWithDecode(&endpoints, req); err != nil {
120
return err
@@ -167,7 +167,7 @@ func (n *NginxPlus) queryMetrics() *nginxMetrics {
167
}
168
169
func (n *NginxPlus) queryNginxInfo(ms *nginxMetrics) {
170
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPINginx, n.apiVersion))
170
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPINginx, n.apiVersion))
171
172
var v nginxInfo
173
@@ -181,7 +181,7 @@ func (n *NginxPlus) queryNginxInfo(ms *nginxMetrics) {
181
}
182
183
func (n *NginxPlus) queryConnections(ms *nginxMetrics) {
184
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIConnections, n.apiVersion))
184
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIConnections, n.apiVersion))
185
186
var v nginxConnections
187
@@ -195,7 +195,7 @@ func (n *NginxPlus) queryConnections(ms *nginxMetrics) {
195
}
196
197
func (n *NginxPlus) querySSL(ms *nginxMetrics) {
198
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPISSL, n.apiVersion))
198
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPISSL, n.apiVersion))
199
200
var v nginxSSL
201
@@ -209,7 +209,7 @@ func (n *NginxPlus) querySSL(ms *nginxMetrics) {
209
}
210
211
func (n *NginxPlus) queryHTTPRequests(ms *nginxMetrics) {
212
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPRequests, n.apiVersion))
212
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIHTTPRequests, n.apiVersion))
213
214
var v nginxHTTPRequests
215
@@ -223,7 +223,7 @@ func (n *NginxPlus) queryHTTPRequests(ms *nginxMetrics) {
223
}
224
225
func (n *NginxPlus) queryHTTPServerZones(ms *nginxMetrics) {
226
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPServerZones, n.apiVersion))
226
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIHTTPServerZones, n.apiVersion))
227
228
var v nginxHTTPServerZones
229
@@ -237,7 +237,7 @@ func (n *NginxPlus) queryHTTPServerZones(ms *nginxMetrics) {
237
}
238
239
func (n *NginxPlus) queryHTTPLocationZones(ms *nginxMetrics) {
240
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPLocationZones, n.apiVersion))
240
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIHTTPLocationZones, n.apiVersion))
241
242
var v nginxHTTPLocationZones
243
@@ -251,7 +251,7 @@ func (n *NginxPlus) queryHTTPLocationZones(ms *nginxMetrics) {
251
}
252
253
func (n *NginxPlus) queryHTTPUpstreams(ms *nginxMetrics) {
254
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPUpstreams, n.apiVersion))
254
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIHTTPUpstreams, n.apiVersion))
255
256
var v nginxHTTPUpstreams
257
@@ -265,7 +265,7 @@ func (n *NginxPlus) queryHTTPUpstreams(ms *nginxMetrics) {
265
}
266
267
func (n *NginxPlus) queryHTTPCaches(ms *nginxMetrics) {
268
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPCaches, n.apiVersion))
268
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIHTTPCaches, n.apiVersion))
269
270
var v nginxHTTPCaches
271
@@ -279,7 +279,7 @@ func (n *NginxPlus) queryHTTPCaches(ms *nginxMetrics) {
279
}
280
281
func (n *NginxPlus) queryStreamServerZones(ms *nginxMetrics) {
282
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIStreamServerZones, n.apiVersion))
282
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIStreamServerZones, n.apiVersion))
283
284
var v nginxStreamServerZones
285
@@ -293,7 +293,7 @@ func (n *NginxPlus) queryStreamServerZones(ms *nginxMetrics) {
293
}
294
295
func (n *NginxPlus) queryStreamUpstreams(ms *nginxMetrics) {
296
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIStreamUpstreams, n.apiVersion))
296
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIStreamUpstreams, n.apiVersion))
297
298
var v nginxStreamUpstreams
299
@@ -307,7 +307,7 @@ func (n *NginxPlus) queryStreamUpstreams(ms *nginxMetrics) {
307
}
308
309
func (n *NginxPlus) queryResolvers(ms *nginxMetrics) {
310
- req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIResolvers, n.apiVersion))
310
+ req, _ := web.NewHTTPRequestWithPath(n.RequestConfig, fmt.Sprintf(urlPathAPIResolvers, n.apiVersion))
311
312
var v nginxResolvers
313
src/go/plugin/go.d/modules/nginxplus/nginxplus.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *NginxPlus {
28
return &NginxPlus{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -42,8 +43,8 @@ func New() *NginxPlus {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type NginxPlus struct {
@@ -83,7 +84,7 @@ func (n *NginxPlus) Init() error {
84
return errors.New("url not set")
85
}
86
86
- client, err := web.NewHTTPClient(n.Client)
87
+ client, err := web.NewHTTPClient(n.ClientConfig)
88
if err != nil {
89
n.Errorf("init HTTP client: %v", err)
90
return err
src/go/plugin/go.d/modules/nginxplus/nginxplus_test.go
+2
-2
@@ -77,8 +77,8 @@ func TestNginxPlus_Init(t *testing.T) {
77
"fail when URL not set": {
78
wantFail: true,
79
config: Config{
80
- HTTP: web.HTTP{
81
- Request: web.Request{URL: ""},
80
+ HTTPConfig: web.HTTPConfig{
81
+ RequestConfig: web.RequestConfig{URL: ""},
82
},
83
},
84
},
src/go/plugin/go.d/modules/nginxvts/collect.go
+1
-1
@@ -44,7 +44,7 @@ func (vts *NginxVTS) collectServerZones(collected map[string]interface{}, ms *vt
44
}
45
46
func (vts *NginxVTS) scapeVTS() (*vtsMetrics, error) {
47
- req, _ := web.NewHTTPRequest(vts.Request)
47
+ req, _ := web.NewHTTPRequest(vts.RequestConfig)
48
49
var total vtsMetrics
50
src/go/plugin/go.d/modules/nginxvts/init.go
+2
-2
@@ -15,14 +15,14 @@ func (vts *NginxVTS) validateConfig() error {
15
return errors.New("URL not set")
16
}
17
18
- if _, err := web.NewHTTPRequest(vts.Request); err != nil {
18
+ if _, err := web.NewHTTPRequest(vts.RequestConfig); err != nil {
19
return err
20
}
21
return nil
22
}
23
24
func (vts *NginxVTS) initHTTPClient() (*http.Client, error) {
25
- return web.NewHTTPClient(vts.Client)
25
+ return web.NewHTTPClient(vts.ClientConfig)
26
}
27
28
func (vts *NginxVTS) initCharts() (*module.Charts, error) {
src/go/plugin/go.d/modules/nginxvts/nginxvts.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -29,12 +30,12 @@ func init() {
30
func New() *NginxVTS {
31
return &NginxVTS{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Request: web.Request{
33
+ HTTPConfig: web.HTTPConfig{
34
+ RequestConfig: web.RequestConfig{
35
URL: "http://localhost/status/format/json",
36
},
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second),
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second),
39
},
40
},
41
},
@@ -42,8 +43,8 @@ func New() *NginxVTS {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type NginxVTS struct {
src/go/plugin/go.d/modules/nginxvts/nginxvts_test.go
+4
-4
@@ -54,15 +54,15 @@ func TestNginxVTS_Init(t *testing.T) {
54
"URL not set": {
55
wantFail: true,
56
config: Config{
57
- HTTP: web.HTTP{
58
- Request: web.Request{URL: ""},
57
+ HTTPConfig: web.HTTPConfig{
58
+ RequestConfig: web.RequestConfig{URL: ""},
59
}},
60
},
61
"invalid TLSCA": {
62
wantFail: true,
63
config: Config{
64
- HTTP: web.HTTP{
65
- Client: web.Client{
64
+ HTTPConfig: web.HTTPConfig{
65
+ ClientConfig: web.ClientConfig{
66
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
67
},
68
}},
src/go/plugin/go.d/modules/nsd/nsd.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,15 +28,15 @@ func init() {
28
func New() *Nsd {
29
return &Nsd{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: charts.Copy(),
34
}
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
}
41
42
type Nsd struct {
src/go/plugin/go.d/modules/ntpd/ntpd.go
+6
-6
@@ -9,8 +9,8 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/iprange"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
16
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func New() *NTPd {
28
return &NTPd{
29
Config: Config{
30
Address: "127.0.0.1:123",
31
- Timeout: web.Duration(time.Second),
31
+ Timeout: confopt.Duration(time.Second),
32
CollectPeers: false,
33
},
34
charts: systemCharts.Copy(),
@@ -39,10 +39,10 @@ func New() *NTPd {
39
}
40
41
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- Address string `yaml:"address" json:"address"`
44
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
45
- CollectPeers bool `yaml:"collect_peers" json:"collect_peers"`
42
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
+ Address string `yaml:"address" json:"address"`
44
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
45
+ CollectPeers bool `yaml:"collect_peers" json:"collect_peers"`
46
}
47
48
type (
src/go/plugin/go.d/modules/nvidia_smi/nvidia_smi.go
+6
-6
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *NvidiaSmi {
29
return &NvidiaSmi{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 10),
31
+ Timeout: confopt.Duration(time.Second * 10),
32
LoopMode: true,
33
},
34
binName: "nvidia-smi",
@@ -40,10 +40,10 @@ func New() *NvidiaSmi {
40
}
41
42
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
45
- BinaryPath string `yaml:"binary_path" json:"binary_path"`
46
- LoopMode bool `yaml:"loop_mode,omitempty" json:"loop_mode"`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
45
+ BinaryPath string `yaml:"binary_path" json:"binary_path"`
46
+ LoopMode bool `yaml:"loop_mode,omitempty" json:"loop_mode"`
47
}
48
49
type NvidiaSmi struct {
src/go/plugin/go.d/modules/nvme/nvme.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *NVMe {
29
return &NVMe{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
34
charts: &module.Charts{},
@@ -39,8 +39,8 @@ func New() *NVMe {
39
}
40
41
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
}
45
46
type (
src/go/plugin/go.d/modules/openvpn/openvpn.go
+3
-3
@@ -8,9 +8,9 @@ import (
8
9
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/openvpn/client"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
16
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func New() *OpenVPN {
28
return &OpenVPN{
29
Config: Config{
30
Address: "127.0.0.1:7505",
31
- Timeout: web.Duration(time.Second),
31
+ Timeout: confopt.Duration(time.Second),
32
},
33
34
charts: charts.Copy(),
@@ -39,7 +39,7 @@ func New() *OpenVPN {
39
type Config struct {
40
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
Address string `yaml:"address" json:"address"`
42
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
PerUserStats matcher.SimpleExpr `yaml:"per_user_stats,omitempty" json:"per_user_stats"`
44
}
45
src/go/plugin/go.d/modules/pgbouncer/pgbouncer.go
+5
-5
@@ -9,7 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
14
"github.com/blang/semver/v4"
15
_ "github.com/jackc/pgx/v4/stdlib"
@@ -29,7 +29,7 @@ func init() {
29
func New() *PgBouncer {
30
return &PgBouncer{
31
Config: Config{
32
- Timeout: web.Duration(time.Second),
32
+ Timeout: confopt.Duration(time.Second),
33
DSN: "postgres://postgres:postgres@127.0.0.1:6432/pgbouncer",
34
},
35
charts: globalCharts.Copy(),
@@ -41,9 +41,9 @@ func New() *PgBouncer {
41
}
42
43
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- DSN string `yaml:"dsn" json:"dsn"`
46
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ DSN string `yaml:"dsn" json:"dsn"`
46
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
47
}
48
49
type PgBouncer struct {
src/go/plugin/go.d/modules/phpdaemon/client.go
+3
-3
@@ -15,7 +15,7 @@ type decodeFunc func(dst interface{}, reader io.Reader) error
15
16
func decodeJson(dst interface{}, reader io.Reader) error { return json.NewDecoder(reader).Decode(dst) }
17
18
-func newAPIClient(httpClient *http.Client, request web.Request) *client {
18
+func newAPIClient(httpClient *http.Client, request web.RequestConfig) *client {
19
return &client{
20
httpClient: httpClient,
21
request: request,
@@ -24,7 +24,7 @@ func newAPIClient(httpClient *http.Client, request web.Request) *client {
24
25
type client struct {
26
httpClient *http.Client
27
- request web.Request
27
+ request web.RequestConfig
28
}
29
30
func (c *client) queryFullStatus() (*FullStatus, error) {
@@ -37,7 +37,7 @@ func (c *client) queryFullStatus() (*FullStatus, error) {
37
return &status, nil
38
}
39
40
-func (c *client) doWithDecode(dst interface{}, decode decodeFunc, request web.Request) error {
40
+func (c *client) doWithDecode(dst interface{}, decode decodeFunc, request web.RequestConfig) error {
41
req, err := web.NewHTTPRequest(request)
42
if err != nil {
43
return fmt.Errorf("error on creating http request to %s : %v", request.URL, err)
src/go/plugin/go.d/modules/phpdaemon/init.go
+3
-3
@@ -12,16 +12,16 @@ func (p *PHPDaemon) validateConfig() error {
12
if p.URL == "" {
13
return errors.New("url not set")
14
}
15
- if _, err := web.NewHTTPRequest(p.Request); err != nil {
15
+ if _, err := web.NewHTTPRequest(p.RequestConfig); err != nil {
16
return err
17
}
18
return nil
19
}
20
21
func (p *PHPDaemon) initClient() (*client, error) {
22
- httpClient, err := web.NewHTTPClient(p.Client)
22
+ httpClient, err := web.NewHTTPClient(p.ClientConfig)
23
if err != nil {
24
return nil, err
25
}
26
- return newAPIClient(httpClient, p.Request), nil
26
+ return newAPIClient(httpClient, p.RequestConfig), nil
27
}
src/go/plugin/go.d/modules/phpdaemon/phpdaemon.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -25,12 +26,12 @@ func init() {
26
func New() *PHPDaemon {
27
return &PHPDaemon{
28
Config: Config{
28
- HTTP: web.HTTP{
29
- Request: web.Request{
29
+ HTTPConfig: web.HTTPConfig{
30
+ RequestConfig: web.RequestConfig{
31
URL: "http://127.0.0.1:8509/FullStatus",
32
},
32
- Client: web.Client{
33
- Timeout: web.Duration(time.Second),
33
+ ClientConfig: web.ClientConfig{
34
+ Timeout: confopt.Duration(time.Second),
35
},
36
},
37
},
@@ -39,8 +40,8 @@ func New() *PHPDaemon {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type PHPDaemon struct {
src/go/plugin/go.d/modules/phpfpm/client.go
+2
-2
@@ -53,11 +53,11 @@ type client interface {
53
54
type httpClient struct {
55
client *http.Client
56
- req web.Request
56
+ req web.RequestConfig
57
dec decoder
58
}
59
60
-func newHTTPClient(c *http.Client, r web.Request) (*httpClient, error) {
60
+func newHTTPClient(c *http.Client, r web.RequestConfig) (*httpClient, error) {
61
u, err := url.Parse(r.URL)
62
if err != nil {
63
return nil, err
src/go/plugin/go.d/modules/phpfpm/init.go
+2
-2
@@ -25,14 +25,14 @@ func (p *Phpfpm) initClient() (client, error) {
25
}
26
27
func (p *Phpfpm) initHTTPClient() (*httpClient, error) {
28
- c, err := web.NewHTTPClient(p.Client)
28
+ c, err := web.NewHTTPClient(p.ClientConfig)
29
if err != nil {
30
return nil, fmt.Errorf("create HTTP client: %v", err)
31
}
32
33
p.Debugf("using HTTP client: url='%s', timeout='%s'", p.URL, p.Timeout)
34
35
- return newHTTPClient(c, p.Request)
35
+ return newHTTPClient(c, p.RequestConfig)
36
}
37
38
func (p *Phpfpm) initSocketClient() (*socketClient, error) {
src/go/plugin/go.d/modules/phpfpm/phpfpm.go
+10
-9
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -25,12 +26,12 @@ func init() {
26
func New() *Phpfpm {
27
return &Phpfpm{
28
Config: Config{
28
- HTTP: web.HTTP{
29
- Request: web.Request{
29
+ HTTPConfig: web.HTTPConfig{
30
+ RequestConfig: web.RequestConfig{
31
URL: "http://127.0.0.1/status?full&json",
32
},
32
- Client: web.Client{
33
- Timeout: web.Duration(time.Second),
33
+ ClientConfig: web.ClientConfig{
34
+ Timeout: confopt.Duration(time.Second),
35
},
36
},
37
FcgiPath: "/status",
@@ -39,11 +40,11 @@ func New() *Phpfpm {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
44
- Socket string `yaml:"socket,omitempty" json:"socket"`
45
- Address string `yaml:"address,omitempty" json:"address"`
46
- FcgiPath string `yaml:"fcgi_path,omitempty" json:"fcgi_path"`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
+ Socket string `yaml:"socket,omitempty" json:"socket"`
46
+ Address string `yaml:"address,omitempty" json:"address"`
47
+ FcgiPath string `yaml:"fcgi_path,omitempty" json:"fcgi_path"`
48
}
49
50
type Phpfpm struct {
src/go/plugin/go.d/modules/pihole/collect.go
+4
-4
@@ -131,7 +131,7 @@ func (p *Pihole) queryMetrics(pmx *piholeMetrics, doConcurrently bool) {
131
}
132
133
func (p *Pihole) querySummary(pmx *piholeMetrics) {
134
- req, err := web.NewHTTPRequestWithPath(p.Request, urlPathAPI)
134
+ req, err := web.NewHTTPRequestWithPath(p.RequestConfig, urlPathAPI)
135
if err != nil {
136
p.Error(err)
137
return
@@ -152,7 +152,7 @@ func (p *Pihole) querySummary(pmx *piholeMetrics) {
152
}
153
154
func (p *Pihole) queryQueryTypes(pmx *piholeMetrics) {
155
- req, err := web.NewHTTPRequestWithPath(p.Request, urlPathAPI)
155
+ req, err := web.NewHTTPRequestWithPath(p.RequestConfig, urlPathAPI)
156
if err != nil {
157
p.Error(err)
158
return
@@ -174,7 +174,7 @@ func (p *Pihole) queryQueryTypes(pmx *piholeMetrics) {
174
}
175
176
func (p *Pihole) queryForwardedDestinations(pmx *piholeMetrics) {
177
- req, err := web.NewHTTPRequestWithPath(p.Request, urlPathAPI)
177
+ req, err := web.NewHTTPRequestWithPath(p.RequestConfig, urlPathAPI)
178
if err != nil {
179
p.Error(err)
180
return
@@ -196,7 +196,7 @@ func (p *Pihole) queryForwardedDestinations(pmx *piholeMetrics) {
196
}
197
198
func (p *Pihole) queryAPIVersion() (int, error) {
199
- req, err := web.NewHTTPRequestWithPath(p.Request, urlPathAPI)
199
+ req, err := web.NewHTTPRequestWithPath(p.RequestConfig, urlPathAPI)
200
if err != nil {
201
return 0, err
202
}
src/go/plugin/go.d/modules/pihole/init.go
+1
-1
@@ -21,7 +21,7 @@ func (p *Pihole) validateConfig() error {
21
}
22
23
func (p *Pihole) initHTTPClient() (*http.Client, error) {
24
- return web.NewHTTPClient(p.Client)
24
+ return web.NewHTTPClient(p.ClientConfig)
25
}
26
27
func (p *Pihole) getWebPassword() string {
src/go/plugin/go.d/modules/pihole/pihole.go
+8
-7
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -30,12 +31,12 @@ func init() {
31
func New() *Pihole {
32
return &Pihole{
33
Config: Config{
33
- HTTP: web.HTTP{
34
- Request: web.Request{
34
+ HTTPConfig: web.HTTPConfig{
35
+ RequestConfig: web.RequestConfig{
36
URL: "http://127.0.0.1",
37
},
37
- Client: web.Client{
38
- Timeout: web.Duration(time.Second * 5),
38
+ ClientConfig: web.ClientConfig{
39
+ Timeout: confopt.Duration(time.Second * 5),
40
},
41
},
42
SetupVarsPath: "/etc/pihole/setupVars.conf",
@@ -48,9 +49,9 @@ func New() *Pihole {
49
}
50
51
type Config struct {
51
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
52
- web.HTTP `yaml:",inline" json:""`
53
- SetupVarsPath string `yaml:"setup_vars_path" json:"setup_vars_path"`
52
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
53
+ web.HTTPConfig `yaml:",inline" json:""`
54
+ SetupVarsPath string `yaml:"setup_vars_path" json:"setup_vars_path"`
55
}
56
57
type Pihole struct {
src/go/plugin/go.d/modules/pihole/pihole_test.go
+2
-2
@@ -60,8 +60,8 @@ func TestPihole_Init(t *testing.T) {
60
"fail when URL not set": {
61
wantFail: true,
62
config: Config{
63
- HTTP: web.HTTP{
64
- Request: web.Request{URL: ""},
63
+ HTTPConfig: web.HTTPConfig{
64
+ RequestConfig: web.RequestConfig{URL: ""},
65
},
66
},
67
},
src/go/plugin/go.d/modules/pika/pika.go
+5
-5
@@ -9,8 +9,8 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
15
"github.com/blang/semver/v4"
16
"github.com/redis/go-redis/v9"
@@ -31,7 +31,7 @@ func New() *Pika {
31
return &Pika{
32
Config: Config{
33
Address: "redis://@localhost:9221",
34
- Timeout: web.Duration(time.Second),
34
+ Timeout: confopt.Duration(time.Second),
35
},
36
37
collectedCommands: make(map[string]bool),
@@ -40,9 +40,9 @@ func New() *Pika {
40
}
41
42
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- Address string `yaml:"address" json:"address"`
45
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ Address string `yaml:"address" json:"address"`
45
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
46
tlscfg.TLSConfig `yaml:",inline" json:""`
47
}
48
src/go/plugin/go.d/modules/ping/ping.go
+9
-9
@@ -9,7 +9,7 @@ import (
9
10
"github.com/netdata/netdata/go/plugins/logger"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
14
probing "github.com/prometheus-community/pro-bing"
15
)
@@ -34,7 +34,7 @@ func New() *Ping {
34
Network: "ip",
35
Privileged: true,
36
SendPackets: 5,
37
- Interval: web.Duration(time.Millisecond * 100),
37
+ Interval: confopt.Duration(time.Millisecond * 100),
38
},
39
40
charts: &module.Charts{},
@@ -44,13 +44,13 @@ func New() *Ping {
44
}
45
46
type Config struct {
47
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- Hosts []string `yaml:"hosts" json:"hosts"`
49
- Network string `yaml:"network,omitempty" json:"network"`
50
- Privileged bool `yaml:"privileged" json:"privileged"`
51
- SendPackets int `yaml:"packets,omitempty" json:"packets"`
52
- Interval web.Duration `yaml:"interval,omitempty" json:"interval"`
53
- Interface string `yaml:"interface,omitempty" json:"interface"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ Hosts []string `yaml:"hosts" json:"hosts"`
49
+ Network string `yaml:"network,omitempty" json:"network"`
50
+ Privileged bool `yaml:"privileged" json:"privileged"`
51
+ SendPackets int `yaml:"packets,omitempty" json:"packets"`
52
+ Interval confopt.Duration `yaml:"interval,omitempty" json:"interval"`
53
+ Interface string `yaml:"interface,omitempty" json:"interface"`
54
}
55
56
type (
src/go/plugin/go.d/modules/portcheck/portcheck.go
+6
-6
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,17 +28,17 @@ func init() {
28
func New() *PortCheck {
29
return &PortCheck{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
dial: net.DialTimeout,
34
}
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Host string `yaml:"host" json:"host"`
40
- Ports []int `yaml:"ports" json:"ports"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Host string `yaml:"host" json:"host"`
40
+ Ports []int `yaml:"ports" json:"ports"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
}
43
44
type PortCheck struct {
src/go/plugin/go.d/modules/postfix/postfix.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -29,16 +29,16 @@ func New() *Postfix {
29
return &Postfix{
30
Config: Config{
31
BinaryPath: "/usr/sbin/postqueue",
32
- Timeout: web.Duration(time.Second * 2),
32
+ Timeout: confopt.Duration(time.Second * 2),
33
},
34
charts: charts.Copy(),
35
}
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
- BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
+ BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
42
}
43
44
type (
src/go/plugin/go.d/modules/postgres/postgres.go
+10
-10
@@ -10,9 +10,9 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
15
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
16
17
"github.com/jackc/pgx/v5/stdlib"
18
_ "github.com/jackc/pgx/v5/stdlib"
@@ -32,7 +32,7 @@ func init() {
32
func New() *Postgres {
33
return &Postgres{
34
Config: Config{
35
- Timeout: web.Duration(time.Second * 2),
35
+ Timeout: confopt.Duration(time.Second * 2),
36
DSN: "postgres://postgres:postgres@127.0.0.1:5432/postgres",
37
XactTimeHistogram: []float64{.1, .5, 1, 2.5, 5, 10},
38
QueryTimeHistogram: []float64{.1, .5, 1, 2.5, 5, 10},
@@ -58,14 +58,14 @@ func New() *Postgres {
58
}
59
60
type Config struct {
61
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
62
- DSN string `yaml:"dsn" json:"dsn"`
63
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
64
- DBSelector string `yaml:"collect_databases_matching,omitempty" json:"collect_databases_matching"`
65
- XactTimeHistogram []float64 `yaml:"transaction_time_histogram,omitempty" json:"transaction_time_histogram"`
66
- QueryTimeHistogram []float64 `yaml:"query_time_histogram,omitempty" json:"query_time_histogram"`
67
- MaxDBTables int64 `yaml:"max_db_tables" json:"max_db_tables"`
68
- MaxDBIndexes int64 `yaml:"max_db_indexes" json:"max_db_indexes"`
61
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
62
+ DSN string `yaml:"dsn" json:"dsn"`
63
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
64
+ DBSelector string `yaml:"collect_databases_matching,omitempty" json:"collect_databases_matching"`
65
+ XactTimeHistogram []float64 `yaml:"transaction_time_histogram,omitempty" json:"transaction_time_histogram"`
66
+ QueryTimeHistogram []float64 `yaml:"query_time_histogram,omitempty" json:"query_time_histogram"`
67
+ MaxDBTables int64 `yaml:"max_db_tables" json:"max_db_tables"`
68
+ MaxDBIndexes int64 `yaml:"max_db_indexes" json:"max_db_indexes"`
69
}
70
71
type (
src/go/plugin/go.d/modules/powerdns/authoritativens.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *AuthoritativeNS {
28
return &AuthoritativeNS{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8081",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -39,8 +40,8 @@ func New() *AuthoritativeNS {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type AuthoritativeNS struct {
src/go/plugin/go.d/modules/powerdns/authoritativens_test.go
+5
-5
@@ -50,19 +50,19 @@ func TestAuthoritativeNS_Init(t *testing.T) {
50
"fails on unset URL": {
51
wantFail: true,
52
config: Config{
53
- HTTP: web.HTTP{
54
- Request: web.Request{URL: ""},
53
+ HTTPConfig: web.HTTPConfig{
54
+ RequestConfig: web.RequestConfig{URL: ""},
55
},
56
},
57
},
58
"fails on invalid TLSCA": {
59
wantFail: true,
60
config: Config{
61
- HTTP: web.HTTP{
62
- Request: web.Request{
61
+ HTTPConfig: web.HTTPConfig{
62
+ RequestConfig: web.RequestConfig{
63
URL: "http://127.0.0.1:38001",
64
},
65
- Client: web.Client{
65
+ ClientConfig: web.ClientConfig{
66
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
67
},
68
},
src/go/plugin/go.d/modules/powerdns/collect.go
+1
-1
@@ -64,7 +64,7 @@ func (ns *AuthoritativeNS) collectStatistics(collected map[string]int64, statist
64
}
65
66
func (ns *AuthoritativeNS) scrapeStatistics() ([]statisticMetric, error) {
67
- req, _ := web.NewHTTPRequestWithPath(ns.Request, urlPathLocalStatistics)
67
+ req, _ := web.NewHTTPRequestWithPath(ns.RequestConfig, urlPathLocalStatistics)
68
69
var statistics statisticMetrics
70
if err := ns.doOKDecode(req, &statistics); err != nil {
src/go/plugin/go.d/modules/powerdns/init.go
+2
-2
@@ -14,14 +14,14 @@ func (ns *AuthoritativeNS) validateConfig() error {
14
if ns.URL == "" {
15
return errors.New("URL not set")
16
}
17
- if _, err := web.NewHTTPRequest(ns.Request); err != nil {
17
+ if _, err := web.NewHTTPRequest(ns.RequestConfig); err != nil {
18
return err
19
}
20
return nil
21
}
22
23
func (ns *AuthoritativeNS) initHTTPClient() (*http.Client, error) {
24
- return web.NewHTTPClient(ns.Client)
24
+ return web.NewHTTPClient(ns.ClientConfig)
25
}
26
27
func (ns *AuthoritativeNS) initCharts() (*module.Charts, error) {
src/go/plugin/go.d/modules/powerdns_recursor/collect.go
+1
-1
@@ -64,7 +64,7 @@ func (r *Recursor) collectStatistics(collected map[string]int64, statistics stat
64
}
65
66
func (r *Recursor) scrapeStatistics() ([]statisticMetric, error) {
67
- req, _ := web.NewHTTPRequestWithPath(r.Request, urlPathLocalStatistics)
67
+ req, _ := web.NewHTTPRequestWithPath(r.RequestConfig, urlPathLocalStatistics)
68
69
var statistics statisticMetrics
70
if err := r.doOKDecode(req, &statistics); err != nil {
src/go/plugin/go.d/modules/powerdns_recursor/init.go
+2
-2
@@ -14,14 +14,14 @@ func (r *Recursor) validateConfig() error {
14
if r.URL == "" {
15
return errors.New("URL not set")
16
}
17
- if _, err := web.NewHTTPRequest(r.Request); err != nil {
17
+ if _, err := web.NewHTTPRequest(r.RequestConfig); err != nil {
18
return err
19
}
20
return nil
21
}
22
23
func (r *Recursor) initHTTPClient() (*http.Client, error) {
24
- return web.NewHTTPClient(r.Client)
24
+ return web.NewHTTPClient(r.ClientConfig)
25
}
26
27
func (r *Recursor) initCharts() (*module.Charts, error) {
src/go/plugin/go.d/modules/powerdns_recursor/recursor.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Recursor {
28
return &Recursor{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8081",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -39,8 +40,8 @@ func New() *Recursor {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type Recursor struct {
src/go/plugin/go.d/modules/powerdns_recursor/recursor_test.go
+5
-5
@@ -50,19 +50,19 @@ func TestRecursor_Init(t *testing.T) {
50
"fails on unset URL": {
51
wantFail: true,
52
config: Config{
53
- HTTP: web.HTTP{
54
- Request: web.Request{URL: ""},
53
+ HTTPConfig: web.HTTPConfig{
54
+ RequestConfig: web.RequestConfig{URL: ""},
55
},
56
},
57
},
58
"fails on invalid TLSCA": {
59
wantFail: true,
60
config: Config{
61
- HTTP: web.HTTP{
62
- Request: web.Request{
61
+ HTTPConfig: web.HTTPConfig{
62
+ RequestConfig: web.RequestConfig{
63
URL: "http://127.0.0.1:38001",
64
},
65
- Client: web.Client{
65
+ ClientConfig: web.ClientConfig{
66
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
67
},
68
},
src/go/plugin/go.d/modules/prometheus/init.go
+2
-2
@@ -20,12 +20,12 @@ func (p *Prometheus) validateConfig() error {
20
}
21
22
func (p *Prometheus) initPrometheusClient() (prometheus.Prometheus, error) {
23
- httpClient, err := web.NewHTTPClient(p.Client)
23
+ httpClient, err := web.NewHTTPClient(p.ClientConfig)
24
if err != nil {
25
return nil, fmt.Errorf("init HTTP client: %v", err)
26
}
27
28
- req := p.Request.Copy()
28
+ req := p.RequestConfig.Copy()
29
if p.BearerTokenFile != "" {
30
token, err := os.ReadFile(p.BearerTokenFile)
31
if err != nil {
src/go/plugin/go.d/modules/prometheus/prometheus.go
+5
-4
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus/selector"
@@ -31,9 +32,9 @@ func init() {
32
func New() *Prometheus {
33
return &Prometheus{
34
Config: Config{
34
- HTTP: web.HTTP{
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second * 10),
35
+ HTTPConfig: web.HTTPConfig{
36
+ ClientConfig: web.ClientConfig{
37
+ Timeout: confopt.Duration(time.Second * 10),
38
},
39
},
40
MaxTS: 2000,
@@ -46,7 +47,7 @@ func New() *Prometheus {
47
48
type Config struct {
49
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
Name string `yaml:"name,omitempty" json:"name"`
52
Application string `yaml:"app,omitempty" json:"app"`
53
BearerTokenFile string `yaml:"bearer_token_file,omitempty" json:"bearer_token_file"`
src/go/plugin/go.d/modules/prometheus/prometheus_test.go
+3
-3
@@ -42,13 +42,13 @@ func TestPrometheus_Init(t *testing.T) {
42
}{
43
"non empty URL": {
44
wantFail: false,
45
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:9090/metric"}}},
45
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:9090/metric"}}},
46
},
47
"invalid selector syntax": {
48
wantFail: true,
49
config: Config{
50
- HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:9090/metric"}},
51
- Selector: selector.Expr{Allow: []string{`name{label=#"value"}`}},
50
+ HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:9090/metric"}},
51
+ Selector: selector.Expr{Allow: []string{`name{label=#"value"}`}},
52
},
53
},
54
"default": {
src/go/plugin/go.d/modules/proxysql/proxysql.go
+7
-6
@@ -6,12 +6,13 @@ import (
6
"database/sql"
7
_ "embed"
8
"errors"
9
- _ "github.com/go-sql-driver/mysql"
9
"sync"
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
+
15
+ _ "github.com/go-sql-driver/mysql"
16
)
17
18
//go:embed "config_schema.json"
@@ -29,7 +30,7 @@ func New() *ProxySQL {
30
return &ProxySQL{
31
Config: Config{
32
DSN: "stats:stats@tcp(127.0.0.1:6032)/",
32
- Timeout: web.Duration(time.Second),
33
+ Timeout: confopt.Duration(time.Second),
34
},
35
36
charts: baseCharts.Copy(),
@@ -43,9 +44,9 @@ func New() *ProxySQL {
44
}
45
46
type Config struct {
46
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
- DSN string `yaml:"dsn" json:"dsn"`
48
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ DSN string `yaml:"dsn" json:"dsn"`
49
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
50
}
51
52
type ProxySQL struct {
src/go/plugin/go.d/modules/pulsar/init.go
+2
-2
@@ -18,12 +18,12 @@ func (p *Pulsar) validateConfig() error {
18
}
19
20
func (p *Pulsar) initPrometheusClient() (prometheus.Prometheus, error) {
21
- client, err := web.NewHTTPClient(p.Client)
21
+ client, err := web.NewHTTPClient(p.ClientConfig)
22
if err != nil {
23
return nil, err
24
}
25
26
- return prometheus.New(client, p.Request), nil
26
+ return prometheus.New(client, p.RequestConfig), nil
27
}
28
29
func (p *Pulsar) initTopicFilerMatcher() (matcher.Matcher, error) {
src/go/plugin/go.d/modules/pulsar/pulsar.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
@@ -31,12 +32,12 @@ func init() {
32
func New() *Pulsar {
33
return &Pulsar{
34
Config: Config{
34
- HTTP: web.HTTP{
35
- Request: web.Request{
35
+ HTTPConfig: web.HTTPConfig{
36
+ RequestConfig: web.RequestConfig{
37
URL: "http://127.0.0.1:8080/metrics",
38
},
38
- Client: web.Client{
39
- Timeout: web.Duration(time.Second * 5),
39
+ ClientConfig: web.ClientConfig{
40
+ Timeout: confopt.Duration(time.Second * 5),
41
},
42
},
43
TopicFilter: matcher.SimpleExpr{
@@ -54,9 +55,9 @@ func New() *Pulsar {
55
}
56
57
type Config struct {
57
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
58
- web.HTTP `yaml:",inline" json:""`
59
- TopicFilter matcher.SimpleExpr `yaml:"topic_filter,omitempty" json:"topic_filter"`
58
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
59
+ web.HTTPConfig `yaml:",inline" json:""`
60
+ TopicFilter matcher.SimpleExpr `yaml:"topic_filter,omitempty" json:"topic_filter"`
61
}
62
63
type Pulsar struct {
src/go/plugin/go.d/modules/pulsar/pulsar_test.go
+6
-6
@@ -54,22 +54,22 @@ func TestPulsar_Init(t *testing.T) {
54
config: New().Config,
55
},
56
"empty topic filter": {
57
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:8080/metric"}}},
57
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:8080/metric"}}},
58
},
59
"bad syntax topic filer": {
60
config: Config{
61
- HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:8080/metrics"}},
61
+ HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:8080/metrics"}},
62
TopicFilter: matcher.SimpleExpr{Includes: []string{"+"}}},
63
wantFail: true,
64
},
65
"empty URL": {
66
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: ""}}},
66
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: ""}}},
67
wantFail: true,
68
},
69
"nonexistent TLS CA": {
70
- config: Config{HTTP: web.HTTP{
71
- Request: web.Request{URL: "http://127.0.0.1:8080/metric"},
72
- Client: web.Client{TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}}}},
70
+ config: Config{HTTPConfig: web.HTTPConfig{
71
+ RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:8080/metric"},
72
+ ClientConfig: web.ClientConfig{TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}}}},
73
wantFail: true,
74
},
75
}
src/go/plugin/go.d/modules/puppet/collect.go
+1
-1
@@ -30,7 +30,7 @@ func (p *Puppet) collect() (map[string]int64, error) {
30
}
31
32
func (p *Puppet) queryStatsService() (*statusServiceResponse, error) {
33
- req, err := web.NewHTTPRequestWithPath(p.Request, urlPathStatusService)
33
+ req, err := web.NewHTTPRequestWithPath(p.RequestConfig, urlPathStatusService)
34
if err != nil {
35
return nil, err
36
}
src/go/plugin/go.d/modules/puppet/puppet.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Puppet {
28
return &Puppet{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "https://127.0.0.1:8140",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -40,8 +41,8 @@ func New() *Puppet {
41
}
42
43
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- web.HTTP `yaml:",inline" json:""`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ web.HTTPConfig `yaml:",inline" json:""`
46
}
47
48
type Puppet struct {
@@ -63,7 +64,7 @@ func (p *Puppet) Init() error {
64
return errors.New("url not set")
65
}
66
66
- client, err := web.NewHTTPClient(p.Client)
67
+ client, err := web.NewHTTPClient(p.ClientConfig)
68
if err != nil {
69
p.Error(err)
70
return err
src/go/plugin/go.d/modules/puppet/puppet_test.go
+2
-2
@@ -48,8 +48,8 @@ func TestPuppet_Init(t *testing.T) {
48
"fail when URL not set": {
49
wantFail: true,
50
config: Config{
51
- HTTP: web.HTTP{
52
- Request: web.Request{URL: ""},
51
+ HTTPConfig: web.HTTPConfig{
52
+ RequestConfig: web.RequestConfig{URL: ""},
53
},
54
},
55
},
src/go/plugin/go.d/modules/rabbitmq/collect.go
+2
-2
@@ -144,12 +144,12 @@ func (r *RabbitMQ) collectQueuesStats(mx map[string]int64) error {
144
}
145
146
func (r *RabbitMQ) doOKDecode(urlPath string, in interface{}) error {
147
- req, err := web.NewHTTPRequestWithPath(r.Request, urlPath)
147
+ req, err := web.NewHTTPRequestWithPath(r.RequestConfig, urlPath)
148
if err != nil {
149
return fmt.Errorf("error on creating request: %v", err)
150
}
151
152
- r.Debugf("doing HTTP %s to '%s'", req.Method, req.URL)
152
+ r.Debugf("doing HTTPConfig %s to '%s'", req.Method, req.URL)
153
resp, err := r.httpClient.Do(req)
154
if err != nil {
155
return fmt.Errorf("error on request to %s: %v", req.URL, err)
src/go/plugin/go.d/modules/rabbitmq/rabbitmq.go
+9
-8
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,14 +27,14 @@ func init() {
27
func New() *RabbitMQ {
28
return &RabbitMQ{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://localhost:15672",
33
Username: "guest",
34
Password: "guest",
35
},
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second),
36
+ ClientConfig: web.ClientConfig{
37
+ Timeout: confopt.Duration(time.Second),
38
},
39
},
40
CollectQueues: false,
@@ -45,9 +46,9 @@ func New() *RabbitMQ {
46
}
47
48
type Config struct {
48
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
50
- CollectQueues bool `yaml:"collect_queues_metrics" json:"collect_queues_metrics"`
49
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
+ CollectQueues bool `yaml:"collect_queues_metrics" json:"collect_queues_metrics"`
52
}
53
54
type (
@@ -78,7 +79,7 @@ func (r *RabbitMQ) Init() error {
79
return errors.New("url not set")
80
}
81
81
- client, err := web.NewHTTPClient(r.Client)
82
+ client, err := web.NewHTTPClient(r.ClientConfig)
83
if err != nil {
84
r.Errorf("init HTTP client: %v", err)
85
return err
src/go/plugin/go.d/modules/rabbitmq/rabbitmq_test.go
+2
-2
@@ -55,8 +55,8 @@ func TestRabbitMQ_Init(t *testing.T) {
55
"fail when URL not set": {
56
wantFail: true,
57
config: Config{
58
- HTTP: web.HTTP{
59
- Request: web.Request{URL: ""},
58
+ HTTPConfig: web.HTTPConfig{
59
+ RequestConfig: web.RequestConfig{URL: ""},
60
},
61
},
62
},
src/go/plugin/go.d/modules/redis/redis.go
+7
-7
@@ -10,9 +10,9 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
15
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
16
17
"github.com/blang/semver/v4"
18
"github.com/redis/go-redis/v9"
@@ -33,7 +33,7 @@ func New() *Redis {
33
return &Redis{
34
Config: Config{
35
Address: "redis://@localhost:6379",
36
- Timeout: web.Duration(time.Second),
36
+ Timeout: confopt.Duration(time.Second),
37
PingSamples: 5,
38
},
39
@@ -46,11 +46,11 @@ func New() *Redis {
46
}
47
48
type Config struct {
49
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
- Address string `yaml:"address" json:"address"`
51
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
52
- Username string `yaml:"username,omitempty" json:"username"`
53
- Password string `yaml:"password,omitempty" json:"password"`
49
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
+ Address string `yaml:"address" json:"address"`
51
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
52
+ Username string `yaml:"username,omitempty" json:"username"`
53
+ Password string `yaml:"password,omitempty" json:"password"`
54
tlscfg.TLSConfig `yaml:",inline" json:""`
55
PingSamples int `yaml:"ping_samples" json:"ping_samples"`
56
}
src/go/plugin/go.d/modules/rethinkdb/rethinkdb.go
+7
-7
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Rethinkdb {
26
return &Rethinkdb{
27
Config: Config{
28
Address: "127.0.0.1:28015",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
32
charts: clusterCharts.Copy(),
@@ -36,11 +36,11 @@ func New() *Rethinkdb {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Address string `yaml:"address" json:"address"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
- Username string `yaml:"username,omitempty" json:"username"`
43
- Password string `yaml:"password,omitempty" json:"password"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Address string `yaml:"address" json:"address"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ Username string `yaml:"username,omitempty" json:"username"`
43
+ Password string `yaml:"password,omitempty" json:"password"`
44
}
45
46
type (
src/go/plugin/go.d/modules/riakkv/collect.go
+1
-1
@@ -30,7 +30,7 @@ func (r *RiakKv) collect() (map[string]int64, error) {
30
}
31
32
func (r *RiakKv) getStats() (*riakStats, error) {
33
- req, err := web.NewHTTPRequest(r.Request)
33
+ req, err := web.NewHTTPRequest(r.RequestConfig)
34
if err != nil {
35
return nil, err
36
}
src/go/plugin/go.d/modules/riakkv/riakkv.go
+8
-7
@@ -10,6 +10,7 @@ import (
10
"time"
11
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
)
16
@@ -33,13 +34,13 @@ func init() {
34
func New() *RiakKv {
35
return &RiakKv{
36
Config: Config{
36
- HTTP: web.HTTP{
37
- Request: web.Request{
37
+ HTTPConfig: web.HTTPConfig{
38
+ RequestConfig: web.RequestConfig{
39
// https://docs.riak.com/riak/kv/2.2.3/developing/api/http/status.1.html
40
URL: "http://127.0.0.1:8098/stats",
41
},
41
- Client: web.Client{
42
- Timeout: web.Duration(time.Second),
42
+ ClientConfig: web.ClientConfig{
43
+ Timeout: confopt.Duration(time.Second),
44
},
45
},
46
},
@@ -49,8 +50,8 @@ func New() *RiakKv {
50
}
51
52
type Config struct {
52
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
53
- web.HTTP `yaml:",inline" json:""`
53
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
54
+ web.HTTPConfig `yaml:",inline" json:""`
55
}
56
57
type RiakKv struct {
@@ -73,7 +74,7 @@ func (r *RiakKv) Init() error {
74
return errors.New("url not set")
75
}
76
76
- httpClient, err := web.NewHTTPClient(r.Client)
77
+ httpClient, err := web.NewHTTPClient(r.ClientConfig)
78
if err != nil {
79
r.Errorf("init HTTP client: %v", err)
80
return err
src/go/plugin/go.d/modules/riakkv/riakkv_test.go
+2
-2
@@ -49,8 +49,8 @@ func TestRiakKv_Init(t *testing.T) {
49
"fail when URL not set": {
50
wantFail: true,
51
config: Config{
52
- HTTP: web.HTTP{
53
- Request: web.Request{URL: ""},
52
+ HTTPConfig: web.HTTPConfig{
53
+ RequestConfig: web.RequestConfig{URL: ""},
54
},
55
},
56
},
src/go/plugin/go.d/modules/rspamd/collect.go
+1
-1
@@ -49,7 +49,7 @@ func (r *Rspamd) collect() (map[string]int64, error) {
49
}
50
51
func (r *Rspamd) queryRspamdStats() (*rspamdStats, error) {
52
- req, err := web.NewHTTPRequestWithPath(r.Request, "/stat")
52
+ req, err := web.NewHTTPRequestWithPath(r.RequestConfig, "/stat")
53
if err != nil {
54
return nil, err
55
}
src/go/plugin/go.d/modules/rspamd/rspamd.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Rspamd {
28
return &Rspamd{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:11334",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -40,8 +41,8 @@ func New() *Rspamd {
41
}
42
43
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- web.HTTP `yaml:",inline" json:""`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ web.HTTPConfig `yaml:",inline" json:""`
46
}
47
48
type Rspamd struct {
@@ -63,7 +64,7 @@ func (r *Rspamd) Init() error {
64
return errors.New("url not set")
65
}
66
66
- client, err := web.NewHTTPClient(r.Client)
67
+ client, err := web.NewHTTPClient(r.ClientConfig)
68
if err != nil {
69
r.Error(err)
70
return err
src/go/plugin/go.d/modules/rspamd/rspamd_test.go
+2
-2
@@ -48,8 +48,8 @@ func TestRspamd_Init(t *testing.T) {
48
"fail when URL not set": {
49
wantFail: true,
50
config: Config{
51
- HTTP: web.HTTP{
52
- Request: web.Request{URL: ""},
51
+ HTTPConfig: web.HTTPConfig{
52
+ RequestConfig: web.RequestConfig{URL: ""},
53
},
54
},
55
},
src/go/plugin/go.d/modules/samba/samba.go
+4
-4
@@ -9,7 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
)
14
15
//go:embed "config_schema.json"
@@ -29,7 +29,7 @@ func init() {
29
func New() *Samba {
30
return &Samba{
31
Config: Config{
32
- Timeout: web.Duration(time.Second * 2),
32
+ Timeout: confopt.Duration(time.Second * 2),
33
},
34
charts: &module.Charts{},
35
once: &sync.Once{},
@@ -37,8 +37,8 @@ func New() *Samba {
37
}
38
39
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
40
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
}
43
44
type Samba struct {
src/go/plugin/go.d/modules/scaleio/client/client.go
+11
-11
@@ -74,7 +74,7 @@ Relationships:
74
*/
75
76
// New creates new ScaleIO client.
77
-func New(client web.Client, request web.Request) (*Client, error) {
77
+func New(client web.ClientConfig, request web.RequestConfig) (*Client, error) {
78
httpClient, err := web.NewHTTPClient(client)
79
if err != nil {
80
return nil, err
@@ -88,7 +88,7 @@ func New(client web.Client, request web.Request) (*Client, error) {
88
89
// Client represents ScaleIO client.
90
type Client struct {
91
- Request web.Request
91
+ Request web.RequestConfig
92
httpClient *http.Client
93
token *token
94
}
@@ -160,7 +160,7 @@ func (c *Client) Instances() (Instances, error) {
160
return instances, err
161
}
162
163
-func (c *Client) createLoginRequest() web.Request {
163
+func (c *Client) createLoginRequest() web.RequestConfig {
164
req := c.Request.Copy()
165
u, _ := url.Parse(req.URL)
166
u.Path = path.Join(u.Path, "/api/login")
@@ -168,7 +168,7 @@ func (c *Client) createLoginRequest() web.Request {
168
return req
169
}
170
171
-func (c *Client) createLogoutRequest() web.Request {
171
+func (c *Client) createLogoutRequest() web.RequestConfig {
172
req := c.Request.Copy()
173
u, _ := url.Parse(req.URL)
174
u.Path = path.Join(u.Path, "/api/logout")
@@ -177,7 +177,7 @@ func (c *Client) createLogoutRequest() web.Request {
177
return req
178
}
179
180
-func (c *Client) createAPIVersionRequest() web.Request {
180
+func (c *Client) createAPIVersionRequest() web.RequestConfig {
181
req := c.Request.Copy()
182
u, _ := url.Parse(req.URL)
183
u.Path = path.Join(u.Path, "/api/version")
@@ -186,7 +186,7 @@ func (c *Client) createAPIVersionRequest() web.Request {
186
return req
187
}
188
189
-func (c *Client) createSelectedStatisticsRequest(query []byte) web.Request {
189
+func (c *Client) createSelectedStatisticsRequest(query []byte) web.RequestConfig {
190
req := c.Request.Copy()
191
u, _ := url.Parse(req.URL)
192
u.Path = path.Join(u.Path, "/api/instances/querySelectedStatistics")
@@ -200,7 +200,7 @@ func (c *Client) createSelectedStatisticsRequest(query []byte) web.Request {
200
return req
201
}
202
203
-func (c *Client) createInstancesRequest() web.Request {
203
+func (c *Client) createInstancesRequest() web.RequestConfig {
204
req := c.Request.Copy()
205
u, _ := url.Parse(req.URL)
206
u.Path = path.Join(u.Path, "/api/instances")
@@ -209,7 +209,7 @@ func (c *Client) createInstancesRequest() web.Request {
209
return req
210
}
211
212
-func (c *Client) do(req web.Request) (*http.Response, error) {
212
+func (c *Client) do(req web.RequestConfig) (*http.Response, error) {
213
httpReq, err := web.NewHTTPRequest(req)
214
if err != nil {
215
return nil, fmt.Errorf("error on creating http request to %s: %v", req.URL, err)
@@ -217,7 +217,7 @@ func (c *Client) do(req web.Request) (*http.Response, error) {
217
return c.httpClient.Do(httpReq)
218
}
219
220
-func (c *Client) doOK(req web.Request) (*http.Response, error) {
220
+func (c *Client) doOK(req web.RequestConfig) (*http.Response, error) {
221
resp, err := c.do(req)
222
if err != nil {
223
return nil, err
@@ -228,7 +228,7 @@ func (c *Client) doOK(req web.Request) (*http.Response, error) {
228
return resp, err
229
}
230
231
-func (c *Client) doOKWithRetry(req web.Request) (*http.Response, error) {
231
+func (c *Client) doOKWithRetry(req web.RequestConfig) (*http.Response, error) {
232
resp, err := c.do(req)
233
if err != nil {
234
return nil, err
@@ -246,7 +246,7 @@ func (c *Client) doOKWithRetry(req web.Request) (*http.Response, error) {
246
return resp, err
247
}
248
249
-func (c *Client) doJSONWithRetry(dst interface{}, req web.Request) error {
249
+func (c *Client) doJSONWithRetry(dst interface{}, req web.RequestConfig) error {
250
resp, err := c.doOKWithRetry(req)
251
defer web.CloseBody(resp)
252
if err != nil {
src/go/plugin/go.d/modules/scaleio/client/client_test.go
+2
-2
@@ -13,7 +13,7 @@ import (
13
)
14
15
func TestNew(t *testing.T) {
16
- _, err := New(web.Client{}, web.Request{})
16
+ _, err := New(web.ClientConfig{}, web.RequestConfig{})
17
assert.NoError(t, err)
18
}
19
@@ -110,7 +110,7 @@ func prepareSrvClient(t *testing.T) (*httptest.Server, *Client) {
110
Instances: testInstances,
111
Statistics: testStatistics,
112
})
113
- client, err := New(web.Client{}, web.Request{
113
+ client, err := New(web.ClientConfig{}, web.RequestConfig{
114
URL: srv.URL,
115
Username: testUser,
116
Password: testPassword,
src/go/plugin/go.d/modules/scaleio/scaleio.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/scaleio/client"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *ScaleIO {
28
return &ScaleIO{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "https://127.0.0.1",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -41,8 +42,8 @@ func New() *ScaleIO {
42
}
43
44
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- web.HTTP `yaml:",inline" json:""`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ web.HTTPConfig `yaml:",inline" json:""`
47
}
48
49
type (
@@ -75,7 +76,7 @@ func (s *ScaleIO) Init() error {
76
return errors.New("username and password aren't set")
77
}
78
78
- c, err := client.New(s.Client, s.Request)
79
+ c, err := client.New(s.ClientConfig, s.RequestConfig)
80
if err != nil {
81
s.Errorf("error on creating ScaleIO client: %v", err)
82
return err
src/go/plugin/go.d/modules/scaleio/scaleio_test.go
+1
-1
@@ -53,7 +53,7 @@ func TestScaleIO_Init_ErrorOnCreatingClientWrongTLSCA(t *testing.T) {
53
job := New()
54
job.Username = "username"
55
job.Password = "password"
56
- job.Client.TLSConfig.TLSCA = "testdata/tls"
56
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
57
58
assert.Error(t, job.Init())
59
}
src/go/plugin/go.d/modules/sensors/sensors.go
+5
-5
@@ -9,7 +9,7 @@ import (
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/sensors/lmsensors"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
)
14
15
//go:embed "config_schema.json"
@@ -30,7 +30,7 @@ func New() *Sensors {
30
return &Sensors{
31
Config: Config{
32
BinaryPath: "/usr/bin/sensors",
33
- Timeout: web.Duration(time.Second * 2),
33
+ Timeout: confopt.Duration(time.Second * 2),
34
},
35
charts: &module.Charts{},
36
sensors: make(map[string]bool),
@@ -38,9 +38,9 @@ func New() *Sensors {
38
}
39
40
type Config struct {
41
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
- BinaryPath string `yaml:"binary_path" json:"binary_path"`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
+ BinaryPath string `yaml:"binary_path" json:"binary_path"`
44
}
45
46
type (
src/go/plugin/go.d/modules/smartctl/smartctl.go
+7
-7
@@ -8,8 +8,8 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
14
"github.com/tidwall/gjson"
15
)
@@ -31,9 +31,9 @@ func init() {
31
func New() *Smartctl {
32
return &Smartctl{
33
Config: Config{
34
- Timeout: web.Duration(time.Second * 5),
35
- ScanEvery: web.Duration(time.Minute * 15),
36
- PollDevicesEvery: web.Duration(time.Minute * 5),
34
+ Timeout: confopt.Duration(time.Second * 5),
35
+ ScanEvery: confopt.Duration(time.Minute * 15),
36
+ PollDevicesEvery: confopt.Duration(time.Minute * 5),
37
NoCheckPowerMode: "standby",
38
DeviceSelector: "*",
39
},
@@ -47,9 +47,9 @@ func New() *Smartctl {
47
type (
48
Config struct {
49
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
51
- ScanEvery web.Duration `yaml:"scan_every,omitempty" json:"scan_every"`
52
- PollDevicesEvery web.Duration `yaml:"poll_devices_every,omitempty" json:"poll_devices_every"`
50
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
51
+ ScanEvery confopt.Duration `yaml:"scan_every,omitempty" json:"scan_every"`
52
+ PollDevicesEvery confopt.Duration `yaml:"poll_devices_every,omitempty" json:"poll_devices_every"`
53
NoCheckPowerMode string `yaml:"no_check_power_mode,omitempty" json:"no_check_power_mode"`
54
DeviceSelector string `yaml:"device_selector,omitempty" json:"device_selector"`
55
ExtraDevices []ConfigExtraDevice `yaml:"extra_devices,omitempty" json:"extra_devices"`
src/go/plugin/go.d/modules/smartctl/smartctl_test.go
+3
-3
@@ -9,7 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
14
"github.com/stretchr/testify/assert"
15
"github.com/stretchr/testify/require"
@@ -357,8 +357,8 @@ func TestSmartctl_Collect(t *testing.T) {
357
}
358
mock := test.prepareMock()
359
smart.exec = mock
360
- smart.ScanEvery = web.Duration(time.Microsecond * 1)
361
- smart.PollDevicesEvery = web.Duration(time.Microsecond * 1)
360
+ smart.ScanEvery = confopt.Duration(time.Microsecond * 1)
361
+ smart.PollDevicesEvery = confopt.Duration(time.Microsecond * 1)
362
363
var mx map[string]int64
364
for i := 0; i < 10; i++ {
src/go/plugin/go.d/modules/squid/collect.go
+1
-1
@@ -42,7 +42,7 @@ func (s *Squid) collect() (map[string]int64, error) {
42
}
43
44
func (s *Squid) collectCounters(mx map[string]int64) error {
45
- req, err := web.NewHTTPRequestWithPath(s.Request, urlPathServerStats)
45
+ req, err := web.NewHTTPRequestWithPath(s.RequestConfig, urlPathServerStats)
46
if err != nil {
47
return err
48
}
src/go/plugin/go.d/modules/squid/squid.go
+8
-7
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Squid {
28
return &Squid{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:3128",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -40,8 +41,8 @@ func New() *Squid {
41
}
42
43
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- web.HTTP `yaml:",inline" json:""`
44
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
+ web.HTTPConfig `yaml:",inline" json:""`
46
}
47
48
type Squid struct {
@@ -63,7 +64,7 @@ func (s *Squid) Init() error {
64
return errors.New("url not set")
65
}
66
66
- client, err := web.NewHTTPClient(s.Client)
67
+ client, err := web.NewHTTPClient(s.ClientConfig)
68
if err != nil {
69
s.Error(err)
70
return err
src/go/plugin/go.d/modules/squid/squid_test.go
+2
-2
@@ -47,8 +47,8 @@ func TestSquid_Init(t *testing.T) {
47
"fail when URL not set": {
48
wantFail: true,
49
config: Config{
50
- HTTP: web.HTTP{
51
- Request: web.Request{URL: ""},
50
+ HTTPConfig: web.HTTPConfig{
51
+ RequestConfig: web.RequestConfig{URL: ""},
52
},
53
},
54
},
src/go/plugin/go.d/modules/storcli/storcli.go
+4
-4
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *StorCli {
29
return &StorCli{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
charts: &module.Charts{},
34
controllers: make(map[string]bool),
@@ -38,8 +38,8 @@ func New() *StorCli {
38
}
39
40
type Config struct {
41
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
}
44
45
type (
src/go/plugin/go.d/modules/supervisord/client.go
+1
-1
@@ -28,7 +28,7 @@ func newSupervisorRPCClient(serverURL *url.URL, httpClient *http.Client) (superv
28
c := xmlrpc.NewClient("http://unix/RPC2")
29
t, ok := httpClient.Transport.(*http.Transport)
30
if !ok {
31
- return nil, errors.New("unexpected HTTP client transport")
31
+ return nil, errors.New("unexpected HTTPConfig client transport")
32
}
33
t.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
34
d := net.Dialer{Timeout: httpClient.Timeout}
src/go/plugin/go.d/modules/supervisord/init.go
+1
-1
@@ -22,7 +22,7 @@ func (s *Supervisord) initSupervisorClient() (supervisorClient, error) {
22
if err != nil {
23
return nil, fmt.Errorf("parse 'url': %v (%s)", err, s.URL)
24
}
25
- httpClient, err := web.NewHTTPClient(s.Client)
25
+ httpClient, err := web.NewHTTPClient(s.ClientConfig)
26
if err != nil {
27
return nil, fmt.Errorf("create HTTP client: %v", err)
28
}
src/go/plugin/go.d/modules/supervisord/supervisord.go
+6
-5
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -26,8 +27,8 @@ func New() *Supervisord {
27
return &Supervisord{
28
Config: Config{
29
URL: "http://127.0.0.1:9001/RPC2",
29
- Client: web.Client{
30
- Timeout: web.Duration(time.Second),
30
+ ClientConfig: web.ClientConfig{
31
+ Timeout: confopt.Duration(time.Second),
32
},
33
},
34
@@ -37,9 +38,9 @@ func New() *Supervisord {
38
}
39
40
type Config struct {
40
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
41
- URL string `yaml:"url" json:"url"`
42
- web.Client `yaml:",inline" json:""`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ URL string `yaml:"url" json:"url"`
43
+ web.ClientConfig `yaml:",inline" json:""`
44
}
45
46
type (
src/go/plugin/go.d/modules/systemdunits/systemdunits.go
+10
-10
@@ -11,8 +11,8 @@ import (
11
"time"
12
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
15
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
16
17
"github.com/coreos/go-systemd/v22/dbus"
18
)
@@ -34,12 +34,12 @@ func init() {
34
func New() *SystemdUnits {
35
return &SystemdUnits{
36
Config: Config{
37
- Timeout: web.Duration(time.Second * 2),
37
+ Timeout: confopt.Duration(time.Second * 2),
38
Include: []string{"*.service"},
39
SkipTransient: false,
40
CollectUnitFiles: false,
41
IncludeUnitFiles: []string{"*.service"},
42
- CollectUnitFilesEvery: web.Duration(time.Minute * 5),
42
+ CollectUnitFilesEvery: confopt.Duration(time.Minute * 5),
43
},
44
charts: &module.Charts{},
45
client: newSystemdDBusClient(),
@@ -50,13 +50,13 @@ func New() *SystemdUnits {
50
}
51
52
type Config struct {
53
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
54
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
55
- Include []string `yaml:"include,omitempty" json:"include"`
56
- SkipTransient bool `yaml:"skip_transient" json:"skip_transient"`
57
- CollectUnitFiles bool `yaml:"collect_unit_files" json:"collect_unit_files"`
58
- IncludeUnitFiles []string `yaml:"include_unit_files,omitempty" json:"include_unit_files"`
59
- CollectUnitFilesEvery web.Duration `yaml:"collect_unit_files_every,omitempty" json:"collect_unit_files_every"`
53
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
54
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
55
+ Include []string `yaml:"include,omitempty" json:"include"`
56
+ SkipTransient bool `yaml:"skip_transient" json:"skip_transient"`
57
+ CollectUnitFiles bool `yaml:"collect_unit_files" json:"collect_unit_files"`
58
+ IncludeUnitFiles []string `yaml:"include_unit_files,omitempty" json:"include_unit_files"`
59
+ CollectUnitFilesEvery confopt.Duration `yaml:"collect_unit_files_every,omitempty" json:"collect_unit_files_every"`
60
}
61
62
type SystemdUnits struct {
src/go/plugin/go.d/modules/tengine/apiclient.go
+3
-3
@@ -77,13 +77,13 @@ var defaultLineFormat = []string{
77
httpUps5xx,
78
}
79
80
-func newAPIClient(client *http.Client, request web.Request) *apiClient {
80
+func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient {
81
return &apiClient{httpClient: client, request: request}
82
}
83
84
type apiClient struct {
85
httpClient *http.Client
86
- request web.Request
86
+ request web.RequestConfig
87
}
88
89
func (a apiClient) getStatus() (*tengineStatus, error) {
@@ -112,7 +112,7 @@ func (a apiClient) doRequestOK(req *http.Request) (*http.Response, error) {
112
return nil, fmt.Errorf("error on request : %v", err)
113
}
114
if resp.StatusCode != http.StatusOK {
115
- return resp, fmt.Errorf("%s returned HTTP code %d", req.URL, resp.StatusCode)
115
+ return resp, fmt.Errorf("%s returned HTTPConfig code %d", req.URL, resp.StatusCode)
116
}
117
return resp, nil
118
}
src/go/plugin/go.d/modules/tengine/tengine.go
+9
-8
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -25,12 +26,12 @@ func init() {
26
func New() *Tengine {
27
return &Tengine{
28
Config: Config{
28
- HTTP: web.HTTP{
29
- Request: web.Request{
29
+ HTTPConfig: web.HTTPConfig{
30
+ RequestConfig: web.RequestConfig{
31
URL: "http://127.0.0.1/us",
32
},
32
- Client: web.Client{
33
- Timeout: web.Duration(time.Second * 2),
33
+ ClientConfig: web.ClientConfig{
34
+ Timeout: confopt.Duration(time.Second * 2),
35
},
36
},
37
},
@@ -39,8 +40,8 @@ func New() *Tengine {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type Tengine struct {
@@ -62,13 +63,13 @@ func (t *Tengine) Init() error {
63
return errors.New("url not set")
64
}
65
65
- client, err := web.NewHTTPClient(t.Client)
66
+ client, err := web.NewHTTPClient(t.ClientConfig)
67
if err != nil {
68
t.Errorf("error on creating http client : %v", err)
69
return err
70
}
71
71
- t.apiClient = newAPIClient(client, t.Request)
72
+ t.apiClient = newAPIClient(client, t.RequestConfig)
73
74
t.Debugf("using URL: %s", t.URL)
75
t.Debugf("using timeout: %s", t.Timeout)
src/go/plugin/go.d/modules/tomcat/charts.go
+1
-1
@@ -103,7 +103,7 @@ var (
103
104
connectorRequestThreadsChartTmpl = module.Chart{
105
ID: "connector_%s_request_threads",
106
- Title: "Connector Request Threads",
106
+ Title: "Connector RequestConfig Threads",
107
Units: "threads",
108
Fam: "threads",
109
Ctx: "tomcat.connector_request_threads",
src/go/plugin/go.d/modules/tomcat/collect.go
+1
-1
@@ -87,7 +87,7 @@ func cleanName(name string) string {
87
}
88
89
func (t *Tomcat) queryServerStatus() (*serverStatusResponse, error) {
90
- req, err := web.NewHTTPRequestWithPath(t.Request, urlPathServerStatus)
90
+ req, err := web.NewHTTPRequestWithPath(t.RequestConfig, urlPathServerStatus)
91
if err != nil {
92
return nil, err
93
}
src/go/plugin/go.d/modules/tomcat/init.go
+1
-1
@@ -17,5 +17,5 @@ func (t *Tomcat) validateConfig() error {
17
}
18
19
func (t *Tomcat) initHTTPClient() (*http.Client, error) {
20
- return web.NewHTTPClient(t.Client)
20
+ return web.NewHTTPClient(t.ClientConfig)
21
}
src/go/plugin/go.d/modules/tomcat/tomcat.go
+7
-6
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
@@ -26,12 +27,12 @@ func init() {
27
func New() *Tomcat {
28
return &Tomcat{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8080",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 1),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 1),
36
},
37
},
38
},
@@ -42,8 +43,8 @@ func New() *Tomcat {
43
}
44
45
type Config struct {
45
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
- web.HTTP `yaml:",inline" json:""`
46
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
+ web.HTTPConfig `yaml:",inline" json:""`
48
}
49
50
type Tomcat struct {
src/go/plugin/go.d/modules/tomcat/tomcat_test.go
+2
-2
@@ -48,8 +48,8 @@ func TestTomcat_Init(t *testing.T) {
48
"fail when URL not set": {
49
wantFail: true,
50
config: Config{
51
- HTTP: web.HTTP{
52
- Request: web.Request{URL: ""},
51
+ HTTPConfig: web.HTTPConfig{
52
+ RequestConfig: web.RequestConfig{URL: ""},
53
},
54
},
55
},
src/go/plugin/go.d/modules/tor/tor.go
+6
-6
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Tor {
26
return &Tor{
27
Config: Config{
28
Address: "127.0.0.1:9051",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newConn: newControlConn,
32
charts: charts.Copy(),
@@ -34,10 +34,10 @@ func New() *Tor {
34
}
35
36
type Config struct {
37
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
- Address string `yaml:"address" json:"address"`
39
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
40
- Password string `yaml:"password" json:"password"`
37
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
38
+ Address string `yaml:"address" json:"address"`
39
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
40
+ Password string `yaml:"password" json:"password"`
41
}
42
43
type Tor struct {
src/go/plugin/go.d/modules/traefik/init.go
+2
-2
@@ -18,12 +18,12 @@ func (t *Traefik) validateConfig() error {
18
}
19
20
func (t *Traefik) initPrometheusClient() (prometheus.Prometheus, error) {
21
- httpClient, err := web.NewHTTPClient(t.Client)
21
+ httpClient, err := web.NewHTTPClient(t.ClientConfig)
22
if err != nil {
23
return nil, err
24
}
25
26
- prom := prometheus.NewWithSelector(httpClient, t.Request, sr)
26
+ prom := prometheus.NewWithSelector(httpClient, t.RequestConfig, sr)
27
return prom, nil
28
}
29
src/go/plugin/go.d/modules/traefik/traefik.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *Traefik {
28
return &Traefik{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8082/metrics",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -45,8 +46,8 @@ func New() *Traefik {
46
}
47
48
type Config struct {
48
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
49
- web.HTTP `yaml:",inline" json:""`
49
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
50
+ web.HTTPConfig `yaml:",inline" json:""`
51
}
52
53
type (
src/go/plugin/go.d/modules/traefik/traefik_test.go
+4
-4
@@ -47,15 +47,15 @@ func TestTraefik_Init(t *testing.T) {
47
},
48
"fails on unset 'url'": {
49
wantFail: true,
50
- config: Config{HTTP: web.HTTP{
51
- Request: web.Request{},
50
+ config: Config{HTTPConfig: web.HTTPConfig{
51
+ RequestConfig: web.RequestConfig{},
52
}},
53
},
54
"fails on invalid TLSCA": {
55
wantFail: true,
56
config: Config{
57
- HTTP: web.HTTP{
58
- Client: web.Client{
57
+ HTTPConfig: web.HTTPConfig{
58
+ ClientConfig: web.ClientConfig{
59
TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"},
60
},
61
}},
src/go/plugin/go.d/modules/typesense/collect.go
+2
-2
@@ -53,7 +53,7 @@ func (ts *Typesense) collect() (map[string]int64, error) {
53
}
54
55
func (ts *Typesense) collectHealth(mx map[string]int64) error {
56
- req, err := web.NewHTTPRequestWithPath(ts.Request, urlPathHealth)
56
+ req, err := web.NewHTTPRequestWithPath(ts.RequestConfig, urlPathHealth)
57
if err != nil {
58
return fmt.Errorf("creating health request: %w", err)
59
}
@@ -87,7 +87,7 @@ func (ts *Typesense) collectStats(mx map[string]int64) error {
87
return nil
88
}
89
90
- req, err := web.NewHTTPRequestWithPath(ts.Request, urlPathStats)
90
+ req, err := web.NewHTTPRequestWithPath(ts.RequestConfig, urlPathStats)
91
if err != nil {
92
return fmt.Errorf("creating stats request: %w", err)
93
}
src/go/plugin/go.d/modules/typesense/typesense.go
+9
-8
@@ -11,6 +11,7 @@ import (
11
"time"
12
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
16
)
17
@@ -28,12 +29,12 @@ func init() {
29
func New() *Typesense {
30
return &Typesense{
31
Config: Config{
31
- HTTP: web.HTTP{
32
- Request: web.Request{
32
+ HTTPConfig: web.HTTPConfig{
33
+ RequestConfig: web.RequestConfig{
34
URL: "http://127.0.0.1:8108",
35
},
35
- Client: web.Client{
36
- Timeout: web.Duration(time.Second),
36
+ ClientConfig: web.ClientConfig{
37
+ Timeout: confopt.Duration(time.Second),
38
},
39
},
40
},
@@ -43,9 +44,9 @@ func New() *Typesense {
44
}
45
46
type Config struct {
46
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
47
- web.HTTP `yaml:",inline" json:""`
48
- APIKey string `yaml:"api_key,omitempty" json:"api_key"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ web.HTTPConfig `yaml:",inline" json:""`
49
+ APIKey string `yaml:"api_key,omitempty" json:"api_key"`
50
}
51
52
type Typesense struct {
@@ -70,7 +71,7 @@ func (ts *Typesense) Init() error {
71
return errors.New("typesense URL not configured")
72
}
73
73
- httpClient, err := web.NewHTTPClient(ts.Client)
74
+ httpClient, err := web.NewHTTPClient(ts.ClientConfig)
75
if err != nil {
76
return fmt.Errorf("initialize http client: %w", err)
77
}
src/go/plugin/go.d/modules/typesense/typesense_test.go
+2
-2
@@ -55,8 +55,8 @@ func TestTypesense_Init(t *testing.T) {
55
"fail when URL not set": {
56
wantFail: true,
57
config: Config{
58
- HTTP: web.HTTP{
59
- Request: web.Request{URL: ""},
58
+ HTTPConfig: web.HTTPConfig{
59
+ RequestConfig: web.RequestConfig{URL: ""},
60
},
61
},
62
},
src/go/plugin/go.d/modules/unbound/unbound.go
+8
-8
@@ -8,9 +8,9 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
15
16
//go:embed "config_schema.json"
@@ -29,7 +29,7 @@ func New() *Unbound {
29
Config: Config{
30
Address: "127.0.0.1:8953",
31
ConfPath: "/etc/unbound/unbound.conf",
32
- Timeout: web.Duration(time.Second),
32
+ Timeout: confopt.Duration(time.Second),
33
Cumulative: false,
34
UseTLS: true,
35
TLSConfig: tlscfg.TLSConfig{
@@ -44,12 +44,12 @@ func New() *Unbound {
44
}
45
46
type Config struct {
47
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
- Address string `yaml:"address" json:"address"`
49
- ConfPath string `yaml:"conf_path,omitempty" json:"conf_path"`
50
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
51
- Cumulative bool `yaml:"cumulative_stats" json:"cumulative_stats"`
52
- UseTLS bool `yaml:"use_tls,omitempty" json:"use_tls"`
47
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
48
+ Address string `yaml:"address" json:"address"`
49
+ ConfPath string `yaml:"conf_path,omitempty" json:"conf_path"`
50
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
51
+ Cumulative bool `yaml:"cumulative_stats" json:"cumulative_stats"`
52
+ UseTLS bool `yaml:"use_tls,omitempty" json:"use_tls"`
53
tlscfg.TLSConfig `yaml:",inline" json:""`
54
}
55
src/go/plugin/go.d/modules/upsd/upsd.go
+7
-7
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Upsd {
26
return &Upsd{
27
Config: Config{
28
Address: "127.0.0.1:3493",
29
- Timeout: web.Duration(time.Second * 2),
29
+ Timeout: confopt.Duration(time.Second * 2),
30
},
31
newUpsdConn: newUpsdConn,
32
charts: &module.Charts{},
@@ -35,11 +35,11 @@ func New() *Upsd {
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Address string `yaml:"address" json:"address"`
40
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
- Username string `yaml:"username,omitempty" json:"username"`
42
- Password string `yaml:"password,omitempty" json:"password"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Address string `yaml:"address" json:"address"`
40
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
41
+ Username string `yaml:"username,omitempty" json:"username"`
42
+ Password string `yaml:"password,omitempty" json:"password"`
43
}
44
45
type (
src/go/plugin/go.d/modules/uwsgi/uwsgi.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -26,7 +26,7 @@ func New() *Uwsgi {
26
return &Uwsgi{
27
Config: Config{
28
Address: "127.0.0.1:1717",
29
- Timeout: web.Duration(time.Second * 1),
29
+ Timeout: confopt.Duration(time.Second * 1),
30
},
31
newConn: newUwsgiConn,
32
charts: charts.Copy(),
@@ -35,9 +35,9 @@ func New() *Uwsgi {
35
}
36
37
type Config struct {
38
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
- Address string `yaml:"address" json:"address"`
40
- Timeout web.Duration `yaml:"timeout" json:"timeout"`
38
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
39
+ Address string `yaml:"address" json:"address"`
40
+ Timeout confopt.Duration `yaml:"timeout" json:"timeout"`
41
}
42
43
type Uwsgi struct {
src/go/plugin/go.d/modules/varnish/varnish.go
+6
-6
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *Varnish {
29
return &Varnish{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 2),
31
+ Timeout: confopt.Duration(time.Second * 2),
32
},
33
34
seenBackends: make(map[string]bool),
@@ -39,10 +39,10 @@ func New() *Varnish {
39
}
40
41
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
- InstanceName string `yaml:"instance_name,omitempty" json:"instance_name,omitempty"`
45
- DockerContainer string `yaml:"docker_container,omitempty" json:"docker_container,omitempty"`
42
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
44
+ InstanceName string `yaml:"instance_name,omitempty" json:"instance_name,omitempty"`
45
+ DockerContainer string `yaml:"docker_container,omitempty" json:"docker_container,omitempty"`
46
}
47
48
type Varnish struct {
src/go/plugin/go.d/modules/vcsa/client/client.go
+7
-7
@@ -71,7 +71,7 @@ type Client struct {
71
// Login creates a session with the API. This operation exchanges user credentials supplied in the security context
72
// for a session identifier that is to be used for authenticating subsequent calls.
73
func (c *Client) Login() error {
74
- req := web.Request{
74
+ req := web.RequestConfig{
75
URL: fmt.Sprintf("%s%s", c.url, pathCISSession),
76
Username: c.username,
77
Password: c.password,
@@ -88,7 +88,7 @@ func (c *Client) Login() error {
88
89
// Logout terminates the validity of a session token.
90
func (c *Client) Logout() error {
91
- req := web.Request{
91
+ req := web.RequestConfig{
92
URL: fmt.Sprintf("%s%s", c.url, pathCISSession),
93
Method: http.MethodDelete,
94
Headers: map[string]string{apiSessIDKey: c.token.get()},
@@ -103,7 +103,7 @@ func (c *Client) Logout() error {
103
// Ping sent a request to VCSA server to ensure the link is operating.
104
// In case of 401 error Ping tries to re authenticate.
105
func (c *Client) Ping() error {
106
- req := web.Request{
106
+ req := web.RequestConfig{
107
URL: fmt.Sprintf("%s%s?~action=get", c.url, pathCISSession),
108
Method: http.MethodPost,
109
Headers: map[string]string{apiSessIDKey: c.token.get()},
@@ -117,7 +117,7 @@ func (c *Client) Ping() error {
117
}
118
119
func (c *Client) health(urlPath string) (string, error) {
120
- req := web.Request{
120
+ req := web.RequestConfig{
121
URL: fmt.Sprintf("%s%s", c.url, urlPath),
122
Headers: map[string]string{apiSessIDKey: c.token.get()},
123
}
@@ -170,7 +170,7 @@ func (c *Client) System() (string, error) {
170
return c.health(pathHealthSystem)
171
}
172
173
-func (c *Client) do(req web.Request) (*http.Response, error) {
173
+func (c *Client) do(req web.RequestConfig) (*http.Response, error) {
174
httpReq, err := web.NewHTTPRequest(req)
175
if err != nil {
176
return nil, fmt.Errorf("error on creating http request to %s : %v", req.URL, err)
@@ -178,7 +178,7 @@ func (c *Client) do(req web.Request) (*http.Response, error) {
178
return c.httpClient.Do(httpReq)
179
}
180
181
-func (c *Client) doOK(req web.Request) (*http.Response, error) {
181
+func (c *Client) doOK(req web.RequestConfig) (*http.Response, error) {
182
resp, err := c.do(req)
183
if err != nil {
184
return nil, err
@@ -190,7 +190,7 @@ func (c *Client) doOK(req web.Request) (*http.Response, error) {
190
return resp, nil
191
}
192
193
-func (c *Client) doOKWithDecode(req web.Request, dst interface{}) error {
193
+func (c *Client) doOKWithDecode(req web.RequestConfig, dst interface{}) error {
194
resp, err := c.doOK(req)
195
defer web.CloseBody(resp)
196
if err != nil {
src/go/plugin/go.d/modules/vcsa/init.go
+1
-1
@@ -20,7 +20,7 @@ func (vc *VCSA) validateConfig() error {
20
}
21
22
func (vc *VCSA) initHealthClient() (*client.Client, error) {
23
- httpClient, err := web.NewHTTPClient(vc.Client)
23
+ httpClient, err := web.NewHTTPClient(vc.ClientConfig)
24
if err != nil {
25
return nil, err
26
}
src/go/plugin/go.d/modules/vcsa/vcsa.go
+6
-5
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
@@ -28,9 +29,9 @@ func init() {
29
func New() *VCSA {
30
return &VCSA{
31
Config: Config{
31
- HTTP: web.HTTP{
32
- Client: web.Client{
33
- Timeout: web.Duration(time.Second * 5),
32
+ HTTPConfig: web.HTTPConfig{
33
+ ClientConfig: web.ClientConfig{
34
+ Timeout: confopt.Duration(time.Second * 5),
35
},
36
},
37
},
@@ -39,8 +40,8 @@ func New() *VCSA {
40
}
41
42
type Config struct {
42
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
43
- web.HTTP `yaml:",inline" json:""`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ web.HTTPConfig `yaml:",inline" json:""`
45
}
46
47
type (
src/go/plugin/go.d/modules/vcsa/vcsa_test.go
+1
-1
@@ -46,7 +46,7 @@ func TestVCenter_InitErrorOnValidatingInitParameters(t *testing.T) {
46
47
func TestVCenter_InitErrorOnCreatingClient(t *testing.T) {
48
job := prepareVCSA()
49
- job.Client.TLSConfig.TLSCA = "testdata/tls"
49
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
50
51
assert.Error(t, job.Init())
52
}
src/go/plugin/go.d/modules/vernemq/init.go
+2
-2
@@ -17,10 +17,10 @@ func (v *VerneMQ) validateConfig() error {
17
}
18
19
func (v *VerneMQ) initPrometheusClient() (prometheus.Prometheus, error) {
20
- client, err := web.NewHTTPClient(v.Client)
20
+ client, err := web.NewHTTPClient(v.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
25
- return prometheus.New(client, v.Request), nil
25
+ return prometheus.New(client, v.RequestConfig), nil
26
}
src/go/plugin/go.d/modules/vernemq/vernemq.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -26,12 +27,12 @@ func init() {
27
func New() *VerneMQ {
28
return &VerneMQ{
29
Config: Config{
29
- HTTP: web.HTTP{
30
- Request: web.Request{
30
+ HTTPConfig: web.HTTPConfig{
31
+ RequestConfig: web.RequestConfig{
32
URL: "http://127.0.0.1:8888/metrics",
33
},
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second),
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second),
36
},
37
},
38
},
@@ -41,8 +42,8 @@ func New() *VerneMQ {
42
}
43
44
type Config struct {
44
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
45
- web.HTTP `yaml:",inline" json:""`
45
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
46
+ web.HTTPConfig `yaml:",inline" json:""`
47
}
48
49
type (
src/go/plugin/go.d/modules/vernemq/vernemq_test.go
+1
-1
@@ -52,7 +52,7 @@ func TestVerneMQ_Init_ReturnsFalseIfURLIsNotSet(t *testing.T) {
52
53
func TestVerneMQ_Init_ReturnsFalseIfClientWrongTLSCA(t *testing.T) {
54
verneMQ := prepareVerneMQ()
55
- verneMQ.Client.TLSConfig.TLSCA = "testdata/tls"
55
+ verneMQ.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
56
57
assert.Error(t, verneMQ.Init())
58
}
src/go/plugin/go.d/modules/vsphere/init.go
+1
-1
@@ -31,7 +31,7 @@ func (vs *VSphere) initClient() (*client.Client, error) {
31
User: vs.Username,
32
Password: vs.Password,
33
Timeout: vs.Timeout.Duration(),
34
- TLSConfig: vs.Client.TLSConfig,
34
+ TLSConfig: vs.ClientConfig.TLSConfig,
35
}
36
return client.New(config)
37
}
src/go/plugin/go.d/modules/vsphere/vsphere.go
+7
-6
@@ -10,6 +10,7 @@ import (
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/match"
12
rs "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/resources"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
16
"github.com/vmware/govmomi/performance"
@@ -32,12 +33,12 @@ func init() {
33
func New() *VSphere {
34
return &VSphere{
35
Config: Config{
35
- HTTP: web.HTTP{
36
- Client: web.Client{
37
- Timeout: web.Duration(time.Second * 20),
36
+ HTTPConfig: web.HTTPConfig{
37
+ ClientConfig: web.ClientConfig{
38
+ Timeout: confopt.Duration(time.Second * 20),
39
},
40
},
40
- DiscoveryInterval: web.Duration(time.Minute * 5),
41
+ DiscoveryInterval: confopt.Duration(time.Minute * 5),
42
HostsInclude: []string{"/*"},
43
VMsInclude: []string{"/*"},
44
},
@@ -51,8 +52,8 @@ func New() *VSphere {
52
53
type Config struct {
54
UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
54
- web.HTTP `yaml:",inline" json:""`
55
- DiscoveryInterval web.Duration `yaml:"discovery_interval,omitempty" json:"discovery_interval"`
55
+ web.HTTPConfig `yaml:",inline" json:""`
56
+ DiscoveryInterval confopt.Duration `yaml:"discovery_interval,omitempty" json:"discovery_interval"`
57
HostsInclude match.HostIncludes `yaml:"host_include,omitempty" json:"host_include"`
58
VMsInclude match.VMIncludes `yaml:"vm_include,omitempty" json:"vm_include"`
59
}
src/go/plugin/go.d/modules/vsphere/vsphere_test.go
+3
-3
@@ -12,7 +12,7 @@ import (
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/discover"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/match"
14
rs "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/resources"
15
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
16
17
"github.com/stretchr/testify/assert"
18
"github.com/stretchr/testify/require"
@@ -77,7 +77,7 @@ func TestVSphere_Init_ReturnsFalseIfPasswordNotSet(t *testing.T) {
77
func TestVSphere_Init_ReturnsFalseIfClientWrongTLSCA(t *testing.T) {
78
vSphere, _, teardown := prepareVSphereSim(t)
79
defer teardown()
80
- vSphere.Client.TLSConfig.TLSCA = "testdata/tls"
80
+ vSphere.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
81
82
assert.Error(t, vSphere.Init())
83
}
@@ -402,7 +402,7 @@ func TestVSphere_Collect_Run(t *testing.T) {
402
vSphere, model, teardown := prepareVSphereSim(t)
403
defer teardown()
404
405
- vSphere.DiscoveryInterval = web.Duration(time.Second * 2)
405
+ vSphere.DiscoveryInterval = confopt.Duration(time.Second * 2)
406
require.NoError(t, vSphere.Init())
407
require.NoError(t, vSphere.Check())
408
src/go/plugin/go.d/modules/whoisquery/whoisquery.go
+7
-7
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -28,7 +28,7 @@ func init() {
28
func New() *WhoisQuery {
29
return &WhoisQuery{
30
Config: Config{
31
- Timeout: web.Duration(time.Second * 5),
31
+ Timeout: confopt.Duration(time.Second * 5),
32
DaysUntilWarn: 30,
33
DaysUntilCrit: 15,
34
},
@@ -36,11 +36,11 @@ func New() *WhoisQuery {
36
}
37
38
type Config struct {
39
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
- Source string `yaml:"source" json:"source"`
41
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
- DaysUntilWarn int64 `yaml:"days_until_expiration_warning,omitempty" json:"days_until_expiration_warning"`
43
- DaysUntilCrit int64 `yaml:"days_until_expiration_critical,omitempty" json:"days_until_expiration_critical"`
39
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
40
+ Source string `yaml:"source" json:"source"`
41
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
42
+ DaysUntilWarn int64 `yaml:"days_until_expiration_warning,omitempty" json:"days_until_expiration_warning"`
43
+ DaysUntilCrit int64 `yaml:"days_until_expiration_critical,omitempty" json:"days_until_expiration_critical"`
44
}
45
46
type WhoisQuery struct {
src/go/plugin/go.d/modules/windows/init.go
+2
-2
@@ -17,9 +17,9 @@ func (w *Windows) validateConfig() error {
17
}
18
19
func (w *Windows) initPrometheusClient() (prometheus.Prometheus, error) {
20
- client, err := web.NewHTTPClient(w.Client)
20
+ client, err := web.NewHTTPClient(w.ClientConfig)
21
if err != nil {
22
return nil, err
23
}
24
- return prometheus.New(client, w.Request), nil
24
+ return prometheus.New(client, w.RequestConfig), nil
25
}
src/go/plugin/go.d/modules/windows/windows.go
+7
-6
@@ -8,6 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
)
@@ -29,9 +30,9 @@ func init() {
30
func New() *Windows {
31
return &Windows{
32
Config: Config{
32
- HTTP: web.HTTP{
33
- Client: web.Client{
34
- Timeout: web.Duration(time.Second * 5),
33
+ HTTPConfig: web.HTTPConfig{
34
+ ClientConfig: web.ClientConfig{
35
+ Timeout: confopt.Duration(time.Second * 5),
36
},
37
},
38
},
@@ -69,9 +70,9 @@ func New() *Windows {
70
}
71
72
type Config struct {
72
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
73
- web.HTTP `yaml:",inline" json:""`
74
- Vnode string `yaml:"vnode,omitempty" json:"vnode"`
73
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
74
+ web.HTTPConfig `yaml:",inline" json:""`
75
+ Vnode string `yaml:"vnode,omitempty" json:"vnode"`
76
}
77
78
type (
src/go/plugin/go.d/modules/windows/windows_test.go
+2
-2
@@ -49,7 +49,7 @@ func TestWindows_Init(t *testing.T) {
49
}{
50
"success if 'url' is set": {
51
config: Config{
52
- HTTP: web.HTTP{Request: web.Request{URL: "http://127.0.0.1:9182/metrics"}}},
52
+ HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: "http://127.0.0.1:9182/metrics"}}},
53
},
54
"fails on default config": {
55
wantFail: true,
@@ -57,7 +57,7 @@ func TestWindows_Init(t *testing.T) {
57
},
58
"fails if 'url' is unset": {
59
wantFail: true,
60
- config: Config{HTTP: web.HTTP{Request: web.Request{URL: ""}}},
60
+ config: Config{HTTPConfig: web.HTTPConfig{RequestConfig: web.RequestConfig{URL: ""}}},
61
},
62
}
63
src/go/plugin/go.d/modules/x509check/x509check.go
+9
-9
@@ -7,11 +7,11 @@ import (
7
"errors"
8
"time"
9
10
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
14
cfssllog "github.com/cloudflare/cfssl/log"
14
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
15
)
16
17
//go:embed "config_schema.json"
@@ -32,7 +32,7 @@ func init() {
32
func New() *X509Check {
33
return &X509Check{
34
Config: Config{
35
- Timeout: web.Duration(time.Second * 2),
35
+ Timeout: confopt.Duration(time.Second * 2),
36
DaysUntilWarn: 14,
37
DaysUntilCritical: 7,
38
},
@@ -40,12 +40,12 @@ func New() *X509Check {
40
}
41
42
type Config struct {
43
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
- Source string `yaml:"source" json:"source"`
45
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
46
- DaysUntilWarn int64 `yaml:"days_until_expiration_warning,omitempty" json:"days_until_expiration_warning"`
47
- DaysUntilCritical int64 `yaml:"days_until_expiration_critical,omitempty" json:"days_until_expiration_critical"`
48
- CheckRevocation bool `yaml:"check_revocation_status" json:"check_revocation_status"`
43
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
44
+ Source string `yaml:"source" json:"source"`
45
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
46
+ DaysUntilWarn int64 `yaml:"days_until_expiration_warning,omitempty" json:"days_until_expiration_warning"`
47
+ DaysUntilCritical int64 `yaml:"days_until_expiration_critical,omitempty" json:"days_until_expiration_critical"`
48
+ CheckRevocation bool `yaml:"check_revocation_status" json:"check_revocation_status"`
49
tlscfg.TLSConfig `yaml:",inline" json:""`
50
}
51
src/go/plugin/go.d/modules/zfspool/zfspool.go
+5
-5
@@ -8,7 +8,7 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
)
13
14
//go:embed "config_schema.json"
@@ -29,7 +29,7 @@ func New() *ZFSPool {
29
return &ZFSPool{
30
Config: Config{
31
BinaryPath: "/usr/bin/zpool",
32
- Timeout: web.Duration(time.Second * 2),
32
+ Timeout: confopt.Duration(time.Second * 2),
33
},
34
charts: &module.Charts{},
35
seenZpools: make(map[string]bool),
@@ -38,9 +38,9 @@ func New() *ZFSPool {
38
}
39
40
type Config struct {
41
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
- BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
41
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
42
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
43
+ BinaryPath string `yaml:"binary_path,omitempty" json:"binary_path"`
44
}
45
46
type (
src/go/plugin/go.d/modules/zookeeper/zookeeper.go
+5
-5
@@ -8,8 +8,8 @@ import (
8
"time"
9
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
)
14
15
//go:embed "config_schema.json"
@@ -27,15 +27,15 @@ func New() *Zookeeper {
27
return &Zookeeper{
28
Config: Config{
29
Address: "127.0.0.1:2181",
30
- Timeout: web.Duration(time.Second),
30
+ Timeout: confopt.Duration(time.Second),
31
UseTLS: false,
32
}}
33
}
34
35
type Config struct {
36
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
37
- Address string `yaml:"address" json:"address"`
38
- Timeout web.Duration `yaml:"timeout,omitempty" json:"timeout"`
36
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
37
+ Address string `yaml:"address" json:"address"`
38
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
39
tlscfg.TLSConfig `yaml:",inline" json:""`
40
UseTLS bool `yaml:"use_tls,omitempty" json:"use_tls"`
41
}
src/go/plugin/go.d/pkg/confopt/duration.go
renamed
+1
-1
@@ -1,6 +1,6 @@
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
-package web
3
+package confopt
4
5
import (
6
"encoding/json"
src/go/plugin/go.d/pkg/confopt/duration_test.go
renamed
+1
-1
@@ -1,6 +1,6 @@
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
-package web
3
+package confopt
4
5
import (
6
"encoding/json"
src/go/plugin/go.d/pkg/prometheus/client.go
+3
-3
@@ -28,7 +28,7 @@ type (
28
29
prometheus struct {
30
client *http.Client
31
- request web.Request
31
+ request web.RequestConfig
32
filepath string
33
34
sr selector.Selector
@@ -46,7 +46,7 @@ const (
46
)
47
48
// New creates a Prometheus instance.
49
-func New(client *http.Client, request web.Request) Prometheus {
49
+func New(client *http.Client, request web.RequestConfig) Prometheus {
50
return &prometheus{
51
client: client,
52
request: request,
@@ -55,7 +55,7 @@ func New(client *http.Client, request web.Request) Prometheus {
55
}
56
57
// NewWithSelector creates a Prometheus instance with the selector.
58
-func NewWithSelector(client *http.Client, request web.Request, sr selector.Selector) Prometheus {
58
+func NewWithSelector(client *http.Client, request web.RequestConfig, sr selector.Selector) Prometheus {
59
p := &prometheus{
60
client: client,
61
request: request,
src/go/plugin/go.d/pkg/prometheus/client_test.go
+5
-5
@@ -39,7 +39,7 @@ func TestPrometheus404(t *testing.T) {
39
ts := httptest.NewServer(tsMux)
40
defer ts.Close()
41
42
- req := web.Request{URL: ts.URL + "/metrics"}
42
+ req := web.RequestConfig{URL: ts.URL + "/metrics"}
43
prom := New(http.DefaultClient, req)
44
res, err := prom.ScrapeSeries()
45
@@ -55,7 +55,7 @@ func TestPrometheusPlain(t *testing.T) {
55
ts := httptest.NewServer(tsMux)
56
defer ts.Close()
57
58
- req := web.Request{URL: ts.URL + "/metrics"}
58
+ req := web.RequestConfig{URL: ts.URL + "/metrics"}
59
prom := New(http.DefaultClient, req)
60
res, err := prom.ScrapeSeries()
61
@@ -71,7 +71,7 @@ func TestPrometheusPlainWithSelector(t *testing.T) {
71
ts := httptest.NewServer(tsMux)
72
defer ts.Close()
73
74
- req := web.Request{URL: ts.URL + "/metrics"}
74
+ req := web.RequestConfig{URL: ts.URL + "/metrics"}
75
sr, err := selector.Parse("go_gc*")
76
require.NoError(t, err)
77
prom := NewWithSelector(http.DefaultClient, req, sr)
@@ -101,7 +101,7 @@ func TestPrometheusGzip(t *testing.T) {
101
ts := httptest.NewServer(tsMux)
102
defer ts.Close()
103
104
- req := web.Request{URL: ts.URL + "/metrics"}
104
+ req := web.RequestConfig{URL: ts.URL + "/metrics"}
105
prom := New(http.DefaultClient, req)
106
107
for i := 0; i < 2; i++ {
@@ -112,7 +112,7 @@ func TestPrometheusGzip(t *testing.T) {
112
}
113
114
func TestPrometheusReadFromFile(t *testing.T) {
115
- req := web.Request{URL: "file://testdata/testdata.txt"}
115
+ req := web.RequestConfig{URL: "file://testdata/testdata.txt"}
116
prom := NewWithSelector(http.DefaultClient, req, nil)
117
118
for i := 0; i < 2; i++ {
src/go/plugin/go.d/pkg/web/client_config.go
renamed
+7
-6
@@ -10,19 +10,20 @@ import (
10
"net/http"
11
"net/url"
12
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
15
)
16
17
// ErrRedirectAttempted indicates that a redirect occurred.
18
var ErrRedirectAttempted = errors.New("redirect")
19
19
-// Client is the configuration of the HTTP client.
20
+// ClientConfig is the configuration of the HTTPConfig client.
21
// This structure is not intended to be used directly as part of a module's configuration.
22
// Supported configuration file formats: YAML.
22
-type Client struct {
23
- // Timeout specifies a time limit for requests made by this Client.
23
+type ClientConfig struct {
24
+ // Timeout specifies a time limit for requests made by this ClientConfig.
25
// Default (zero value) is no timeout. Must be set before http.Client creation.
25
- Timeout Duration `yaml:"timeout,omitempty" json:"timeout"`
26
+ Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
27
28
// NotFollowRedirect specifies the policy for handling redirects.
29
// Default (zero value) is std http package default policy (stop after 10 consecutive requests).
@@ -36,8 +37,8 @@ type Client struct {
37
tlscfg.TLSConfig `yaml:",inline" json:""`
38
}
39
39
-// NewHTTPClient returns a new *http.Client given a Client configuration and an error if any.
40
-func NewHTTPClient(cfg Client) (*http.Client, error) {
40
+// NewHTTPClient returns a new *http.Client given a ClientConfig configuration and an error if any.
41
+func NewHTTPClient(cfg ClientConfig) (*http.Client, error) {
42
tlsConfig, err := tlscfg.NewTLSConfig(cfg.TLSConfig)
43
if err != nil {
44
return nil, fmt.Errorf("error on creating TLS config: %v", err)
src/go/plugin/go.d/pkg/web/client_config_test.go
renamed
+3
-2
@@ -3,6 +3,7 @@
3
package web
4
5
import (
6
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
7
"net/http"
8
"testing"
9
"time"
@@ -11,8 +12,8 @@ import (
12
)
13
14
func TestNewHTTPClient(t *testing.T) {
14
- client, _ := NewHTTPClient(Client{
15
- Timeout: Duration(time.Second * 5),
15
+ client, _ := NewHTTPClient(ClientConfig{
16
+ Timeout: confopt.Duration(time.Second * 5),
17
NotFollowRedirect: true,
18
ProxyURL: "http://127.0.0.1:3128",
19
})
src/go/plugin/go.d/pkg/web/doc.go
+1
-1
@@ -2,7 +2,7 @@
2
3
/*
4
Package web contains HTTP request and client configurations.
5
-HTTP structure embeds both of them, and it's the only structure that intended to be used as part of a module's configuration.
5
+HTTPConfig structure embeds both of them, and it's the only structure that intended to be used as part of a module's configuration.
6
Every module that uses HTTP requests to collect metrics should use it.
7
It allows to have same set of user configurable options across all modules.
8
*/
src/go/plugin/go.d/pkg/web/doc_test.go
+6
-6
@@ -2,14 +2,14 @@
2
3
package web
4
5
-func ExampleHTTP_usage() {
6
- // Just embed HTTP into your module structure.
7
- // It allows you to have both Request and Client fields in the module configuration file.
5
+func ExampleHTTPConfig_usage() {
6
+ // Just embed HTTPConfig into your module structure.
7
+ // It allows you to have both RequestConfig and ClientConfig fields in the module configuration file.
8
type myModule struct {
9
- HTTP `yaml:",inline"`
9
+ HTTPConfig `yaml:",inline"`
10
}
11
12
var m myModule
13
- _, _ = NewHTTPRequest(m.Request)
14
- _, _ = NewHTTPClient(m.Client)
13
+ _, _ = NewHTTPRequest(m.RequestConfig)
14
+ _, _ = NewHTTPClient(m.ClientConfig)
15
}
src/go/plugin/go.d/pkg/web/request_config.go
renamed
+12
-12
@@ -14,28 +14,28 @@ import (
14
"github.com/netdata/netdata/go/plugins/pkg/executable"
15
)
16
17
-// Request is the configuration of the HTTP request.
17
+// RequestConfig is the configuration of the HTTP request.
18
// This structure is not intended to be used directly as part of a module's configuration.
19
// Supported configuration file formats: YAML.
20
-type Request struct {
20
+type RequestConfig struct {
21
// URL specifies the URL to access.
22
URL string `yaml:"url" json:"url"`
23
24
- // Username specifies the username for basic HTTP authentication.
24
+ // Username specifies the username for basic HTTPConfig authentication.
25
Username string `yaml:"username,omitempty" json:"username"`
26
27
- // Password specifies the password for basic HTTP authentication.
27
+ // Password specifies the password for basic HTTPConfig authentication.
28
Password string `yaml:"password,omitempty" json:"password"`
29
30
- // ProxyUsername specifies the username for basic HTTP authentication.
30
+ // ProxyUsername specifies the username for basic HTTPConfig authentication.
31
// It is used to authenticate a user agent to a proxy server.
32
ProxyUsername string `yaml:"proxy_username,omitempty" json:"proxy_username"`
33
34
- // ProxyPassword specifies the password for basic HTTP authentication.
34
+ // ProxyPassword specifies the password for basic HTTPConfig authentication.
35
// It is used to authenticate a user agent to a proxy server.
36
ProxyPassword string `yaml:"proxy_password,omitempty" json:"proxy_password"`
37
38
- // Method specifies the HTTP method (GET, POST, PUT, etc.). An empty string means GET.
38
+ // Method specifies the HTTPConfig method (GET, POST, PUT, etc.). An empty string means GET.
39
Method string `yaml:"method,omitempty" json:"method"`
40
41
// Headers specifies the HTTP request header fields to be sent by the client.
@@ -45,8 +45,8 @@ type Request struct {
45
Body string `yaml:"body,omitempty" json:"body"`
46
}
47
48
-// Copy makes a full copy of the Request.
49
-func (r Request) Copy() Request {
48
+// Copy makes a full copy of the RequestConfig.
49
+func (r RequestConfig) Copy() RequestConfig {
50
headers := make(map[string]string, len(r.Headers))
51
for k, v := range r.Headers {
52
headers[k] = v
@@ -57,8 +57,8 @@ func (r Request) Copy() Request {
57
58
var userAgent = fmt.Sprintf("Netdata %s.plugin/%s", executable.Name, buildinfo.Version)
59
60
-// NewHTTPRequest returns a new *http.Requests given a Request configuration and an error if any.
61
-func NewHTTPRequest(cfg Request) (*http.Request, error) {
60
+// NewHTTPRequest returns a new *http.Requests given a RequestConfig configuration and an error if any.
61
+func NewHTTPRequest(cfg RequestConfig) (*http.Request, error) {
62
var body io.Reader
63
if cfg.Body != "" {
64
body = strings.NewReader(cfg.Body)
@@ -92,7 +92,7 @@ func NewHTTPRequest(cfg Request) (*http.Request, error) {
92
return req, nil
93
}
94
95
-func NewHTTPRequestWithPath(cfg Request, urlPath string) (*http.Request, error) {
95
+func NewHTTPRequestWithPath(cfg RequestConfig, urlPath string) (*http.Request, error) {
96
cfg = cfg.Copy()
97
98
v, err := url.JoinPath(cfg.URL, urlPath)
src/go/plugin/go.d/pkg/web/request_config_test.go
renamed
+14
-14
@@ -14,11 +14,11 @@ import (
14
15
func TestRequest_Copy(t *testing.T) {
16
tests := map[string]struct {
17
- orig Request
18
- change func(req *Request)
17
+ orig RequestConfig
18
+ change func(req *RequestConfig)
19
}{
20
"change headers": {
21
- orig: Request{
21
+ orig: RequestConfig{
22
URL: "http://127.0.0.1:19999/api/v1/info",
23
Method: "POST",
24
Headers: map[string]string{
@@ -29,7 +29,7 @@ func TestRequest_Copy(t *testing.T) {
29
ProxyUsername: "proxy_username",
30
ProxyPassword: "proxy_password",
31
},
32
- change: func(req *Request) {
32
+ change: func(req *RequestConfig) {
33
req.Headers["header_key"] = "header_value"
34
},
35
},
@@ -48,29 +48,29 @@ func TestRequest_Copy(t *testing.T) {
48
49
func TestNewHTTPRequest(t *testing.T) {
50
tests := map[string]struct {
51
- req Request
51
+ req RequestConfig
52
wantErr bool
53
}{
54
"test url": {
55
- req: Request{
55
+ req: RequestConfig{
56
URL: "http://127.0.0.1:19999/api/v1/info",
57
},
58
wantErr: false,
59
},
60
"test body": {
61
- req: Request{
61
+ req: RequestConfig{
62
Body: "content",
63
},
64
wantErr: false,
65
},
66
"test method": {
67
- req: Request{
67
+ req: RequestConfig{
68
Method: "POST",
69
},
70
wantErr: false,
71
},
72
"test headers": {
73
- req: Request{
73
+ req: RequestConfig{
74
Headers: map[string]string{
75
"X-Api-Key": "secret",
76
},
@@ -78,7 +78,7 @@ func TestNewHTTPRequest(t *testing.T) {
78
wantErr: false,
79
},
80
"test special headers (host)": {
81
- req: Request{
81
+ req: RequestConfig{
82
Headers: map[string]string{
83
"host": "Host",
84
},
@@ -86,7 +86,7 @@ func TestNewHTTPRequest(t *testing.T) {
86
wantErr: false,
87
},
88
"test special headers (Host)": {
89
- req: Request{
89
+ req: RequestConfig{
90
Headers: map[string]string{
91
"Host": "Host",
92
},
@@ -94,14 +94,14 @@ func TestNewHTTPRequest(t *testing.T) {
94
wantErr: false,
95
},
96
"test username and password": {
97
- req: Request{
97
+ req: RequestConfig{
98
Username: "username",
99
Password: "password",
100
},
101
wantErr: false,
102
},
103
"test proxy username and proxy password": {
104
- req: Request{
104
+ req: RequestConfig{
105
ProxyUsername: "proxy_username",
106
ProxyPassword: "proxy_password",
107
},
@@ -179,7 +179,7 @@ func TestNewRequest(t *testing.T) {
179
180
for name, test := range tests {
181
t.Run(name, func(t *testing.T) {
182
- req, err := NewHTTPRequestWithPath(Request{URL: test.url}.Copy(), test.path)
182
+ req, err := NewHTTPRequestWithPath(RequestConfig{URL: test.url}.Copy(), test.path)
183
require.NoError(t, err)
184
185
assert.Equal(t, test.wantURL, req.URL.String())
src/go/plugin/go.d/pkg/web/web.go
+4
-4
@@ -2,10 +2,10 @@
2
3
package web
4
5
-// HTTP is a struct with embedded Request and Client.
5
+// HTTPConfig is a struct with embedded RequestConfig and ClientConfig.
6
// This structure intended to be part of the module configuration.
7
// Supported configuration file formats: YAML.
8
-type HTTP struct {
9
- Request `yaml:",inline" json:""`
10
- Client `yaml:",inline" json:""`
8
+type HTTPConfig struct {
9
+ RequestConfig `yaml:",inline" json:""`
10
+ ClientConfig `yaml:",inline" json:""`
11
}