diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-09 08:36:07 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-09 08:36:07 +0000 |
commit | e8c44275b9a1937b5948010a042294d580d36d7c (patch) | |
tree | e87c73e25556c3c9d5442f5ca4ba0cf46c64ec70 /src/go/plugin/go.d/modules/fluentd | |
parent | Adding upstream version 1.47.5. (diff) | |
download | netdata-upstream.tar.xz netdata-upstream.zip |
Adding upstream version 2.0.0.upstream/2.0.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/plugin/go.d/modules/fluentd')
-rw-r--r-- | src/go/plugin/go.d/modules/fluentd/apiclient.go | 35 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/fluentd/fluentd.go | 28 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/fluentd/init.go | 6 | ||||
-rw-r--r-- | src/go/plugin/go.d/modules/fluentd/integrations/fluentd.md | 4 |
4 files changed, 22 insertions, 51 deletions
diff --git a/src/go/plugin/go.d/modules/fluentd/apiclient.go b/src/go/plugin/go.d/modules/fluentd/apiclient.go index 1c6bf85a..8996dec4 100644 --- a/src/go/plugin/go.d/modules/fluentd/apiclient.go +++ b/src/go/plugin/go.d/modules/fluentd/apiclient.go @@ -3,9 +3,7 @@ package fluentd import ( - "encoding/json" "fmt" - "io" "net/http" "net/url" "path" @@ -40,13 +38,13 @@ func (p pluginData) hasBufferTotalQueuedSize() bool { return p.BufferTotalQueuedSize != nil } -func newAPIClient(client *http.Client, request web.Request) *apiClient { +func newAPIClient(client *http.Client, request web.RequestConfig) *apiClient { return &apiClient{httpClient: client, request: request} } type apiClient struct { httpClient *http.Client - request web.Request + request web.RequestConfig } func (a apiClient) getPluginsInfo() (*pluginsInfo, error) { @@ -55,32 +53,14 @@ func (a apiClient) getPluginsInfo() (*pluginsInfo, error) { return nil, fmt.Errorf("error on creating request : %v", err) } - resp, err := a.doRequestOK(req) - defer closeBody(resp) - if err != nil { - return nil, err - } - var info pluginsInfo - if err = json.NewDecoder(resp.Body).Decode(&info); err != nil { - return nil, fmt.Errorf("error on decoding response from %s : %v", req.URL, err) + if err := web.DoHTTP(a.httpClient).RequestJSON(req, &info); err != nil { + return nil, fmt.Errorf("error on decoding request : %v", err) } return &info, nil } -func (a apiClient) doRequestOK(req *http.Request) (*http.Response, error) { - resp, err := a.httpClient.Do(req) - if err != nil { - return nil, fmt.Errorf("error on request: %v", err) - } - - if resp.StatusCode != http.StatusOK { - return resp, fmt.Errorf("%s returned HTTP status %d", req.URL, resp.StatusCode) - } - return resp, nil -} - func (a apiClient) createRequest(urlPath string) (*http.Request, error) { req := a.request.Copy() u, err := url.Parse(req.URL) @@ -92,10 +72,3 @@ func (a apiClient) createRequest(urlPath string) (*http.Request, error) { req.URL = u.String() return web.NewHTTPRequest(req) } - -func closeBody(resp *http.Response) { - if resp != nil && resp.Body != nil { - _, _ = io.Copy(io.Discard, resp.Body) - _ = resp.Body.Close() - } -} diff --git a/src/go/plugin/go.d/modules/fluentd/fluentd.go b/src/go/plugin/go.d/modules/fluentd/fluentd.go index 467edaac..548015e2 100644 --- a/src/go/plugin/go.d/modules/fluentd/fluentd.go +++ b/src/go/plugin/go.d/modules/fluentd/fluentd.go @@ -5,10 +5,12 @@ package fluentd import ( _ "embed" "errors" + "fmt" "time" + "github.com/netdata/netdata/go/plugins/pkg/matcher" "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module" - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher" + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt" "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web" ) @@ -26,12 +28,12 @@ func init() { func New() *Fluentd { return &Fluentd{ Config: Config{ - HTTP: web.HTTP{ - Request: web.Request{ + HTTPConfig: web.HTTPConfig{ + RequestConfig: web.RequestConfig{ URL: "http://127.0.0.1:24220", }, - Client: web.Client{ - Timeout: web.Duration(time.Second), + ClientConfig: web.ClientConfig{ + Timeout: confopt.Duration(time.Second), }, }}, activePlugins: make(map[string]bool), @@ -40,9 +42,9 @@ func New() *Fluentd { } type Config struct { - UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"` - web.HTTP `yaml:",inline" json:""` - PermitPlugin string `yaml:"permit_plugin_id,omitempty" json:"permit_plugin_id"` + UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"` + web.HTTPConfig `yaml:",inline" json:""` + PermitPlugin string `yaml:"permit_plugin_id,omitempty" json:"permit_plugin_id"` } type Fluentd struct { @@ -63,21 +65,18 @@ func (f *Fluentd) Configuration() any { func (f *Fluentd) Init() error { if err := f.validateConfig(); err != nil { - f.Error(err) - return err + return fmt.Errorf("invalid config: %v", err) } pm, err := f.initPermitPluginMatcher() if err != nil { - f.Error(err) - return err + return fmt.Errorf("init permit_plugin_id: %v", err) } f.permitPlugin = pm client, err := f.initApiClient() if err != nil { - f.Error(err) - return err + return fmt.Errorf("init api client: %v", err) } f.apiClient = client @@ -90,7 +89,6 @@ func (f *Fluentd) Init() error { func (f *Fluentd) Check() error { mx, err := f.collect() if err != nil { - f.Error(err) return err } if len(mx) == 0 { diff --git a/src/go/plugin/go.d/modules/fluentd/init.go b/src/go/plugin/go.d/modules/fluentd/init.go index 6ee71c0a..2e3d5326 100644 --- a/src/go/plugin/go.d/modules/fluentd/init.go +++ b/src/go/plugin/go.d/modules/fluentd/init.go @@ -5,7 +5,7 @@ package fluentd import ( "errors" - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher" + "github.com/netdata/netdata/go/plugins/pkg/matcher" "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web" ) @@ -26,10 +26,10 @@ func (f *Fluentd) initPermitPluginMatcher() (matcher.Matcher, error) { } func (f *Fluentd) initApiClient() (*apiClient, error) { - client, err := web.NewHTTPClient(f.Client) + client, err := web.NewHTTPClient(f.ClientConfig) if err != nil { return nil, err } - return newAPIClient(client, f.Request), nil + return newAPIClient(client, f.RequestConfig), nil } diff --git a/src/go/plugin/go.d/modules/fluentd/integrations/fluentd.md b/src/go/plugin/go.d/modules/fluentd/integrations/fluentd.md index b4740a77..fbcea02c 100644 --- a/src/go/plugin/go.d/modules/fluentd/integrations/fluentd.md +++ b/src/go/plugin/go.d/modules/fluentd/integrations/fluentd.md @@ -92,8 +92,8 @@ To enable monitor agent, follow the [official documentation](https://docs.fluent The configuration file name for this integration is `go.d/fluentd.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 |