diff options
Diffstat (limited to 'src/go/plugin/go.d/modules/traefik')
-rw-r--r-- | src/go/plugin/go.d/modules/traefik/init.go | 4 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/traefik/integrations/traefik.md | 4 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/traefik/traefik.go | 21 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/traefik/traefik_test.go | 32 |
4 files changed, 22 insertions, 39 deletions
diff --git a/src/go/plugin/go.d/modules/traefik/init.go b/src/go/plugin/go.d/modules/traefik/init.go index 02c1dde0..2e80728f 100644 --- a/src/go/plugin/go.d/modules/traefik/init.go +++ b/src/go/plugin/go.d/modules/traefik/init.go @@ -18,12 +18,12 @@ func (t *Traefik) validateConfig() error { } func (t *Traefik) initPrometheusClient() (prometheus.Prometheus, error) { - httpClient, err := web.NewHTTPClient(t.Client) + httpClient, err := web.NewHTTPClient(t.ClientConfig) if err != nil { return nil, err } - prom := prometheus.NewWithSelector(httpClient, t.Request, sr) + prom := prometheus.NewWithSelector(httpClient, t.RequestConfig, sr) return prom, nil } diff --git a/src/go/plugin/go.d/modules/traefik/integrations/traefik.md b/src/go/plugin/go.d/modules/traefik/integrations/traefik.md index f5dc10eb..0a5d0930 100644 --- a/src/go/plugin/go.d/modules/traefik/integrations/traefik.md +++ b/src/go/plugin/go.d/modules/traefik/integrations/traefik.md @@ -92,8 +92,8 @@ To enable see [Prometheus exporter](https://doc.traefik.io/traefik/observability The configuration file name for this integration is `go.d/traefik.conf`. -You can edit the configuration file using the `edit-config` script from the -Netdata [config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory). +You can edit the configuration file using the [`edit-config`](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#edit-a-configuration-file-using-edit-config) script from the +Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#the-netdata-config-directory). ```bash cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata diff --git a/src/go/plugin/go.d/modules/traefik/traefik.go b/src/go/plugin/go.d/modules/traefik/traefik.go index e38ff969..bbed6d0d 100644 --- a/src/go/plugin/go.d/modules/traefik/traefik.go +++ b/src/go/plugin/go.d/modules/traefik/traefik.go @@ -5,9 +5,11 @@ package traefik import ( _ "embed" "errors" + "fmt" "time" "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module" + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt" "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus" "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web" ) @@ -26,12 +28,12 @@ func init() { func New() *Traefik { return &Traefik{ Config: Config{ - HTTP: web.HTTP{ - Request: web.Request{ + HTTPConfig: web.HTTPConfig{ + RequestConfig: web.RequestConfig{ URL: "http://127.0.0.1:8082/metrics", }, - Client: web.Client{ - Timeout: web.Duration(time.Second), + ClientConfig: web.ClientConfig{ + Timeout: confopt.Duration(time.Second), }, }, }, @@ -45,8 +47,8 @@ func New() *Traefik { } type Config struct { - UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"` - web.HTTP `yaml:",inline" json:""` + UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"` + web.HTTPConfig `yaml:",inline" json:""` } type ( @@ -84,14 +86,12 @@ func (t *Traefik) Configuration() any { func (t *Traefik) Init() error { if err := t.validateConfig(); err != nil { - t.Errorf("config validation: %v", err) - return err + return fmt.Errorf("config validation: %v", err) } prom, err := t.initPrometheusClient() if err != nil { - t.Errorf("prometheus client initialization: %v", err) - return err + return fmt.Errorf("prometheus client initialization: %v", err) } t.prom = prom @@ -101,7 +101,6 @@ func (t *Traefik) Init() error { func (t *Traefik) Check() error { mx, err := t.collect() if err != nil { - t.Error(err) return err } if len(mx) == 0 { diff --git a/src/go/plugin/go.d/modules/traefik/traefik_test.go b/src/go/plugin/go.d/modules/traefik/traefik_test.go index f3ef024b..b606c1b3 100644 --- a/src/go/plugin/go.d/modules/traefik/traefik_test.go +++ b/src/go/plugin/go.d/modules/traefik/traefik_test.go @@ -47,15 +47,15 @@ func TestTraefik_Init(t *testing.T) { }, "fails on unset 'url'": { wantFail: true, - config: Config{HTTP: web.HTTP{ - Request: web.Request{}, + config: Config{HTTPConfig: web.HTTPConfig{ + RequestConfig: web.RequestConfig{}, }}, }, "fails on invalid TLSCA": { wantFail: true, config: Config{ - HTTP: web.HTTP{ - Client: web.Client{ + HTTPConfig: web.HTTPConfig{ + ClientConfig: web.ClientConfig{ TLSConfig: tlscfg.TLSConfig{TLSCA: "testdata/tls"}, }, }}, @@ -241,13 +241,13 @@ func TestTraefik_Collect(t *testing.T) { tk, cleanup := test.prepare(t) defer cleanup() - var ms map[string]int64 + var mx map[string]int64 for _, want := range test.wantCollected { - ms = tk.Collect() - assert.Equal(t, want, ms) + mx = tk.Collect() + assert.Equal(t, want, mx) } if len(test.wantCollected) > 0 { - ensureCollectedHasAllChartsDimsVarsIDs(t, tk, ms) + module.TestMetricsHasAllChartsDims(t, tk.Charts(), mx) } }) } @@ -352,19 +352,3 @@ func prepareCaseConnectionRefused(t *testing.T) (*Traefik, func()) { return h, func() {} } - -func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, tk *Traefik, ms map[string]int64) { - for _, chart := range *tk.Charts() { - if chart.Obsolete { - continue - } - for _, dim := range chart.Dims { - _, ok := ms[dim.ID] - assert.Truef(t, ok, "chart '%s' dim '%s': no dim in collected", dim.ID, chart.ID) - } - for _, v := range chart.Vars { - _, ok := ms[v.ID] - assert.Truef(t, ok, "chart '%s' dim '%s': no dim in collected", v.ID, chart.ID) - } - } -} |