summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/riakkv
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/plugin/go.d/modules/riakkv')
-rw-r--r--src/go/plugin/go.d/modules/riakkv/collect.go37
-rw-r--r--src/go/plugin/go.d/modules/riakkv/integrations/riak_kv.md4
-rw-r--r--src/go/plugin/go.d/modules/riakkv/riakkv.go23
-rw-r--r--src/go/plugin/go.d/modules/riakkv/riakkv_test.go4
4 files changed, 22 insertions, 46 deletions
diff --git a/src/go/plugin/go.d/modules/riakkv/collect.go b/src/go/plugin/go.d/modules/riakkv/collect.go
index 0b3be943..d44655da 100644
--- a/src/go/plugin/go.d/modules/riakkv/collect.go
+++ b/src/go/plugin/go.d/modules/riakkv/collect.go
@@ -3,10 +3,7 @@
package riakkv
import (
- "encoding/json"
"errors"
- "fmt"
- "io"
"net/http"
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
@@ -31,44 +28,24 @@ func (r *RiakKv) collect() (map[string]int64, error) {
}
func (r *RiakKv) getStats() (*riakStats, error) {
- req, err := web.NewHTTPRequest(r.Request)
+ req, err := web.NewHTTPRequest(r.RequestConfig)
if err != nil {
return nil, err
}
var stats riakStats
- if err := r.doOKDecode(req, &stats); err != nil {
+ if err := r.client().RequestJSON(req, &stats); err != nil {
return nil, err
}
return &stats, nil
}
-func (r *RiakKv) doOKDecode(req *http.Request, in interface{}) error {
- resp, err := r.httpClient.Do(req)
- if err != nil {
- return fmt.Errorf("error on HTTP request '%s': %v", req.URL, err)
- }
- defer closeBody(resp)
-
- if resp.StatusCode != http.StatusOK {
- msg := fmt.Sprintf("'%s' returned HTTP status code: %d", req.URL, resp.StatusCode)
+func (r *RiakKv) client() *web.Client {
+ return web.DoHTTP(r.httpClient).OnNokCode(func(resp *http.Response) (bool, error) {
if resp.StatusCode == http.StatusNotFound {
- msg = fmt.Sprintf("%s (riak_kv_stat is not enabled)", msg)
+ return false, errors.New("riak_kv_stat is not enabled)")
}
- return errors.New(msg)
- }
-
- if err := json.NewDecoder(resp.Body).Decode(in); err != nil {
- return fmt.Errorf("error on decoding response from '%s': %v", req.URL, err)
- }
-
- return nil
-}
-
-func closeBody(resp *http.Response) {
- if resp != nil && resp.Body != nil {
- _, _ = io.Copy(io.Discard, resp.Body)
- _ = resp.Body.Close()
- }
+ return false, nil
+ })
}
diff --git a/src/go/plugin/go.d/modules/riakkv/integrations/riak_kv.md b/src/go/plugin/go.d/modules/riakkv/integrations/riak_kv.md
index 87273627..09f1352a 100644
--- a/src/go/plugin/go.d/modules/riakkv/integrations/riak_kv.md
+++ b/src/go/plugin/go.d/modules/riakkv/integrations/riak_kv.md
@@ -118,8 +118,8 @@ See the RiakKV [configuration reference](https://docs.riak.com/riak/kv/2.2.3/dev
The configuration file name for this integration is `go.d/riakkv.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/riakkv/riakkv.go b/src/go/plugin/go.d/modules/riakkv/riakkv.go
index 64aeda1c..d8b68427 100644
--- a/src/go/plugin/go.d/modules/riakkv/riakkv.go
+++ b/src/go/plugin/go.d/modules/riakkv/riakkv.go
@@ -5,11 +5,13 @@ package riakkv
import (
_ "embed"
"errors"
+ "fmt"
"net/http"
"sync"
"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/web"
)
@@ -33,13 +35,13 @@ func init() {
func New() *RiakKv {
return &RiakKv{
Config: Config{
- HTTP: web.HTTP{
- Request: web.Request{
+ HTTPConfig: web.HTTPConfig{
+ RequestConfig: web.RequestConfig{
// https://docs.riak.com/riak/kv/2.2.3/developing/api/http/status.1.html
URL: "http://127.0.0.1:8098/stats",
},
- Client: web.Client{
- Timeout: web.Duration(time.Second),
+ ClientConfig: web.ClientConfig{
+ Timeout: confopt.Duration(time.Second),
},
},
},
@@ -49,8 +51,8 @@ func New() *RiakKv {
}
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 RiakKv struct {
@@ -69,14 +71,12 @@ func (r *RiakKv) Configuration() any {
func (r *RiakKv) Init() error {
if r.URL == "" {
- r.Errorf("url required but not set")
- return errors.New("url not set")
+ return errors.New("config: url not set")
}
- httpClient, err := web.NewHTTPClient(r.Client)
+ httpClient, err := web.NewHTTPClient(r.ClientConfig)
if err != nil {
- r.Errorf("init HTTP client: %v", err)
- return err
+ return fmt.Errorf("init HTTP client: %v", err)
}
r.httpClient = httpClient
@@ -89,7 +89,6 @@ func (r *RiakKv) Init() error {
func (r *RiakKv) Check() error {
mx, err := r.collect()
if err != nil {
- r.Error(err)
return err
}
if len(mx) == 0 {
diff --git a/src/go/plugin/go.d/modules/riakkv/riakkv_test.go b/src/go/plugin/go.d/modules/riakkv/riakkv_test.go
index de4e2409..1b9ccf88 100644
--- a/src/go/plugin/go.d/modules/riakkv/riakkv_test.go
+++ b/src/go/plugin/go.d/modules/riakkv/riakkv_test.go
@@ -49,8 +49,8 @@ func TestRiakKv_Init(t *testing.T) {
"fail when URL not set": {
wantFail: true,
config: Config{
- HTTP: web.HTTP{
- Request: web.Request{URL: ""},
+ HTTPConfig: web.HTTPConfig{
+ RequestConfig: web.RequestConfig{URL: ""},
},
},
},