summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/scaleio
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/plugin/go.d/modules/scaleio')
-rw-r--r--src/go/plugin/go.d/modules/scaleio/client/client.go37
-rw-r--r--src/go/plugin/go.d/modules/scaleio/client/client_test.go4
-rw-r--r--src/go/plugin/go.d/modules/scaleio/integrations/dell_emc_scaleio.md4
-rw-r--r--src/go/plugin/go.d/modules/scaleio/scaleio.go24
-rw-r--r--src/go/plugin/go.d/modules/scaleio/scaleio_test.go25
5 files changed, 37 insertions, 57 deletions
diff --git a/src/go/plugin/go.d/modules/scaleio/client/client.go b/src/go/plugin/go.d/modules/scaleio/client/client.go
index 698b2d17..cc07580b 100644
--- a/src/go/plugin/go.d/modules/scaleio/client/client.go
+++ b/src/go/plugin/go.d/modules/scaleio/client/client.go
@@ -74,7 +74,7 @@ Relationships:
*/
// New creates new ScaleIO client.
-func New(client web.Client, request web.Request) (*Client, error) {
+func New(client web.ClientConfig, request web.RequestConfig) (*Client, error) {
httpClient, err := web.NewHTTPClient(client)
if err != nil {
return nil, err
@@ -88,7 +88,7 @@ func New(client web.Client, request web.Request) (*Client, error) {
// Client represents ScaleIO client.
type Client struct {
- Request web.Request
+ Request web.RequestConfig
httpClient *http.Client
token *token
}
@@ -105,7 +105,7 @@ func (c *Client) Login() error {
}
req := c.createLoginRequest()
resp, err := c.doOK(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
if err != nil {
return err
}
@@ -128,7 +128,7 @@ func (c *Client) Logout() error {
c.token.unset()
resp, err := c.do(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
return err
}
@@ -136,7 +136,7 @@ func (c *Client) Logout() error {
func (c *Client) APIVersion() (Version, error) {
req := c.createAPIVersionRequest()
resp, err := c.doOK(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
if err != nil {
return Version{}, err
}
@@ -160,7 +160,7 @@ func (c *Client) Instances() (Instances, error) {
return instances, err
}
-func (c *Client) createLoginRequest() web.Request {
+func (c *Client) createLoginRequest() web.RequestConfig {
req := c.Request.Copy()
u, _ := url.Parse(req.URL)
u.Path = path.Join(u.Path, "/api/login")
@@ -168,7 +168,7 @@ func (c *Client) createLoginRequest() web.Request {
return req
}
-func (c *Client) createLogoutRequest() web.Request {
+func (c *Client) createLogoutRequest() web.RequestConfig {
req := c.Request.Copy()
u, _ := url.Parse(req.URL)
u.Path = path.Join(u.Path, "/api/logout")
@@ -177,7 +177,7 @@ func (c *Client) createLogoutRequest() web.Request {
return req
}
-func (c *Client) createAPIVersionRequest() web.Request {
+func (c *Client) createAPIVersionRequest() web.RequestConfig {
req := c.Request.Copy()
u, _ := url.Parse(req.URL)
u.Path = path.Join(u.Path, "/api/version")
@@ -186,7 +186,7 @@ func (c *Client) createAPIVersionRequest() web.Request {
return req
}
-func (c *Client) createSelectedStatisticsRequest(query []byte) web.Request {
+func (c *Client) createSelectedStatisticsRequest(query []byte) web.RequestConfig {
req := c.Request.Copy()
u, _ := url.Parse(req.URL)
u.Path = path.Join(u.Path, "/api/instances/querySelectedStatistics")
@@ -200,7 +200,7 @@ func (c *Client) createSelectedStatisticsRequest(query []byte) web.Request {
return req
}
-func (c *Client) createInstancesRequest() web.Request {
+func (c *Client) createInstancesRequest() web.RequestConfig {
req := c.Request.Copy()
u, _ := url.Parse(req.URL)
u.Path = path.Join(u.Path, "/api/instances")
@@ -209,7 +209,7 @@ func (c *Client) createInstancesRequest() web.Request {
return req
}
-func (c *Client) do(req web.Request) (*http.Response, error) {
+func (c *Client) do(req web.RequestConfig) (*http.Response, error) {
httpReq, err := web.NewHTTPRequest(req)
if err != nil {
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) {
return c.httpClient.Do(httpReq)
}
-func (c *Client) doOK(req web.Request) (*http.Response, error) {
+func (c *Client) doOK(req web.RequestConfig) (*http.Response, error) {
resp, err := c.do(req)
if err != nil {
return nil, err
@@ -228,7 +228,7 @@ func (c *Client) doOK(req web.Request) (*http.Response, error) {
return resp, err
}
-func (c *Client) doOKWithRetry(req web.Request) (*http.Response, error) {
+func (c *Client) doOKWithRetry(req web.RequestConfig) (*http.Response, error) {
resp, err := c.do(req)
if err != nil {
return nil, err
@@ -246,22 +246,15 @@ func (c *Client) doOKWithRetry(req web.Request) (*http.Response, error) {
return resp, err
}
-func (c *Client) doJSONWithRetry(dst interface{}, req web.Request) error {
+func (c *Client) doJSONWithRetry(dst any, req web.RequestConfig) error {
resp, err := c.doOKWithRetry(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
if err != nil {
return err
}
return json.NewDecoder(resp.Body).Decode(dst)
}
-func closeBody(resp *http.Response) {
- if resp != nil && resp.Body != nil {
- _, _ = io.Copy(io.Discard, resp.Body)
- _ = resp.Body.Close()
- }
-}
-
func checkStatusCode(resp *http.Response) error {
// For all 4xx and 5xx return codes, the body may contain an apiError
// instance with more specifics about the failure.
diff --git a/src/go/plugin/go.d/modules/scaleio/client/client_test.go b/src/go/plugin/go.d/modules/scaleio/client/client_test.go
index 02e1988b..c8da45fd 100644
--- a/src/go/plugin/go.d/modules/scaleio/client/client_test.go
+++ b/src/go/plugin/go.d/modules/scaleio/client/client_test.go
@@ -13,7 +13,7 @@ import (
)
func TestNew(t *testing.T) {
- _, err := New(web.Client{}, web.Request{})
+ _, err := New(web.ClientConfig{}, web.RequestConfig{})
assert.NoError(t, err)
}
@@ -110,7 +110,7 @@ func prepareSrvClient(t *testing.T) (*httptest.Server, *Client) {
Instances: testInstances,
Statistics: testStatistics,
})
- client, err := New(web.Client{}, web.Request{
+ client, err := New(web.ClientConfig{}, web.RequestConfig{
URL: srv.URL,
Username: testUser,
Password: testPassword,
diff --git a/src/go/plugin/go.d/modules/scaleio/integrations/dell_emc_scaleio.md b/src/go/plugin/go.d/modules/scaleio/integrations/dell_emc_scaleio.md
index 36d02252..bee56ca2 100644
--- a/src/go/plugin/go.d/modules/scaleio/integrations/dell_emc_scaleio.md
+++ b/src/go/plugin/go.d/modules/scaleio/integrations/dell_emc_scaleio.md
@@ -143,8 +143,8 @@ No action required.
The configuration file name for this integration is `go.d/scaleio.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/scaleio/scaleio.go b/src/go/plugin/go.d/modules/scaleio/scaleio.go
index d32ccbff..98bc110c 100644
--- a/src/go/plugin/go.d/modules/scaleio/scaleio.go
+++ b/src/go/plugin/go.d/modules/scaleio/scaleio.go
@@ -5,10 +5,12 @@ package scaleio
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/modules/scaleio/client"
+ "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() *ScaleIO {
return &ScaleIO{
Config: Config{
- HTTP: web.HTTP{
- Request: web.Request{
+ HTTPConfig: web.HTTPConfig{
+ RequestConfig: web.RequestConfig{
URL: "https://127.0.0.1",
},
- Client: web.Client{
- Timeout: web.Duration(time.Second),
+ ClientConfig: web.ClientConfig{
+ Timeout: confopt.Duration(time.Second),
},
},
},
@@ -41,8 +43,8 @@ func New() *ScaleIO {
}
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 (
@@ -71,14 +73,12 @@ func (s *ScaleIO) Configuration() any {
func (s *ScaleIO) Init() error {
if s.Username == "" || s.Password == "" {
- s.Error("username and password aren't set")
- return errors.New("username and password aren't set")
+ return errors.New("config: username and password aren't set")
}
- c, err := client.New(s.Client, s.Request)
+ c, err := client.New(s.ClientConfig, s.RequestConfig)
if err != nil {
- s.Errorf("error on creating ScaleIO client: %v", err)
- return err
+ return fmt.Errorf("error on creating ScaleIO client: %v", err)
}
s.client = c
@@ -90,12 +90,10 @@ func (s *ScaleIO) Init() error {
func (s *ScaleIO) Check() error {
if err := s.client.Login(); err != nil {
- s.Error(err)
return err
}
mx, err := s.collect()
if err != nil {
- s.Error(err)
return err
}
if len(mx) == 0 {
diff --git a/src/go/plugin/go.d/modules/scaleio/scaleio_test.go b/src/go/plugin/go.d/modules/scaleio/scaleio_test.go
index bb906333..66752ebc 100644
--- a/src/go/plugin/go.d/modules/scaleio/scaleio_test.go
+++ b/src/go/plugin/go.d/modules/scaleio/scaleio_test.go
@@ -53,7 +53,7 @@ func TestScaleIO_Init_ErrorOnCreatingClientWrongTLSCA(t *testing.T) {
job := New()
job.Username = "username"
job.Password = "password"
- job.Client.TLSConfig.TLSCA = "testdata/tls"
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
assert.Error(t, job.Init())
}
@@ -298,9 +298,11 @@ func TestScaleIO_Collect(t *testing.T) {
"system_total_iops_write": 617200,
}
- collected := scaleIO.Collect()
- assert.Equal(t, expected, collected)
- testCharts(t, scaleIO, collected)
+ mx := scaleIO.Collect()
+
+ assert.Equal(t, expected, mx)
+
+ testCharts(t, scaleIO, mx)
}
func TestScaleIO_Collect_ConnectionRefused(t *testing.T) {
@@ -317,7 +319,7 @@ func testCharts(t *testing.T, scaleIO *ScaleIO, collected map[string]int64) {
t.Helper()
ensureStoragePoolChartsAreCreated(t, scaleIO)
ensureSdcChartsAreCreated(t, scaleIO)
- ensureCollectedHasAllChartsDimsVarsIDs(t, scaleIO, collected)
+ module.TestMetricsHasAllChartsDims(t, scaleIO.Charts(), collected)
}
func ensureStoragePoolChartsAreCreated(t *testing.T, scaleIO *ScaleIO) {
@@ -336,19 +338,6 @@ func ensureSdcChartsAreCreated(t *testing.T, scaleIO *ScaleIO) {
}
}
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, scaleIO *ScaleIO, collected map[string]int64) {
- for _, chart := range *scaleIO.Charts() {
- for _, dim := range chart.Dims {
- _, ok := collected[dim.ID]
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
- }
- for _, v := range chart.Vars {
- _, ok := collected[v.ID]
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
- }
- }
-}
-
func prepareSrvMockScaleIO(t *testing.T) (*httptest.Server, *client.MockScaleIOAPIServer, *ScaleIO) {
t.Helper()
const (