chore: Fix linter findings for `revive:enforce-slice-style` in `plugins/inputs/[a-d]*` and `plugins/common` (#16161)
This commit is contained in:
parent
9565421c15
commit
b4fdd52ff3
|
|
@ -221,7 +221,7 @@ func makeReadResponses(jresponses []jolokiaResponse) []ReadResponse {
|
||||||
rrequest := ReadRequest{
|
rrequest := ReadRequest{
|
||||||
Mbean: jr.Request.Mbean,
|
Mbean: jr.Request.Mbean,
|
||||||
Path: jr.Request.Path,
|
Path: jr.Request.Path,
|
||||||
Attributes: []string{},
|
Attributes: make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
attrValue := jr.Request.Attribute
|
attrValue := jr.Request.Attribute
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ func makeReadRequests(metrics []Metric) []ReadRequest {
|
||||||
if len(metric.Paths) == 0 {
|
if len(metric.Paths) == 0 {
|
||||||
requests = append(requests, ReadRequest{
|
requests = append(requests, ReadRequest{
|
||||||
Mbean: metric.Mbean,
|
Mbean: metric.Mbean,
|
||||||
Attributes: []string{},
|
Attributes: make([]string, 0),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
attributes := make(map[string][]string)
|
attributes := make(map[string][]string)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func TestJolokia2_makeReadRequests(t *testing.T) {
|
||||||
expected: []ReadRequest{
|
expected: []ReadRequest{
|
||||||
{
|
{
|
||||||
Mbean: "test:foo=bar",
|
Mbean: "test:foo=bar",
|
||||||
Attributes: []string{},
|
Attributes: make([]string, 0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
|
|
||||||
|
|
@ -115,13 +115,13 @@ func (m Metric) MatchAttributeAndPath(attribute, innerPath string) bool {
|
||||||
func parseMbeanObjectName(name string) (string, []string) {
|
func parseMbeanObjectName(name string) (string, []string) {
|
||||||
index := strings.Index(name, ":")
|
index := strings.Index(name, ":")
|
||||||
if index == -1 {
|
if index == -1 {
|
||||||
return name, []string{}
|
return name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := name[:index]
|
domain := name[:index]
|
||||||
|
|
||||||
if index+1 > len(name) {
|
if index+1 > len(name) {
|
||||||
return domain, []string{}
|
return domain, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain, strings.Split(name[index+1:], ",")
|
return domain, strings.Split(name[index+1:], ",")
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,6 @@ func TestValidateOPCTags(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t1", "v1"}, {"t3", "v2"}},
|
TagsSlice: [][]string{{"t1", "v1"}, {"t3", "v2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Groups: []NodeGroupSettings{},
|
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
@ -150,7 +149,6 @@ func TestValidateOPCTags(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t1", "bar"}, {"t2", "v2"}},
|
TagsSlice: [][]string{{"t1", "bar"}, {"t2", "v2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Groups: []NodeGroupSettings{},
|
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
@ -158,7 +156,6 @@ func TestValidateOPCTags(t *testing.T) {
|
||||||
"different metric names",
|
"different metric names",
|
||||||
InputClientConfig{
|
InputClientConfig{
|
||||||
MetricName: "mn",
|
MetricName: "mn",
|
||||||
RootNodes: []NodeSettings{},
|
|
||||||
Groups: []NodeGroupSettings{
|
Groups: []NodeGroupSettings{
|
||||||
{
|
{
|
||||||
MetricName: "mn",
|
MetricName: "mn",
|
||||||
|
|
@ -208,7 +205,6 @@ func TestValidateOPCTags(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t1", "v1"}, {"t2", "v2"}},
|
TagsSlice: [][]string{{"t1", "v1"}, {"t2", "v2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Groups: []NodeGroupSettings{},
|
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
@ -239,7 +235,6 @@ func TestNewNodeMetricMappingTags(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "h",
|
Identifier: "h",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
},
|
},
|
||||||
groupTags: map[string]string{},
|
groupTags: map[string]string{},
|
||||||
expectedTags: map[string]string{},
|
expectedTags: map[string]string{},
|
||||||
|
|
@ -265,7 +260,6 @@ func TestNewNodeMetricMappingTags(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "h",
|
Identifier: "h",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
},
|
},
|
||||||
groupTags: map[string]string{"t1": "v1"},
|
groupTags: map[string]string{"t1": "v1"},
|
||||||
expectedTags: map[string]string{"t1": "v1"},
|
expectedTags: map[string]string{"t1": "v1"},
|
||||||
|
|
@ -313,7 +307,6 @@ func TestNewNodeMetricMappingIdStrInstantiated(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "h",
|
Identifier: "h",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "ns=2;s=h", nmm.idStr)
|
require.Equal(t, "ns=2;s=h", nmm.idStr)
|
||||||
|
|
@ -335,7 +328,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -351,7 +343,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -367,7 +358,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "",
|
Namespace: "",
|
||||||
IdentifierType: "s",
|
IdentifierType: "s",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -383,7 +373,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "",
|
IdentifierType: "",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -399,7 +388,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "j",
|
IdentifierType: "j",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -433,7 +421,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: "i",
|
IdentifierType: "i",
|
||||||
Identifier: "hf",
|
Identifier: "hf",
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -461,7 +448,6 @@ func TestValidateNodeToAdd(t *testing.T) {
|
||||||
Namespace: "2",
|
Namespace: "2",
|
||||||
IdentifierType: idT,
|
IdentifierType: idT,
|
||||||
Identifier: idV,
|
Identifier: idV,
|
||||||
TagsSlice: [][]string{},
|
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return nmm
|
return nmm
|
||||||
|
|
@ -499,7 +485,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t1", "v1"}},
|
TagsSlice: [][]string{{"t1", "v1"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Groups: []NodeGroupSettings{},
|
|
||||||
},
|
},
|
||||||
expected: []NodeMetricMapping{
|
expected: []NodeMetricMapping{
|
||||||
{
|
{
|
||||||
|
|
@ -543,7 +528,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t2", "v2"}},
|
TagsSlice: [][]string{{"t2", "v2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TagsSlice: [][]string{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -580,7 +564,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
config: InputClientConfig{
|
config: InputClientConfig{
|
||||||
MetricName: "testmetric",
|
MetricName: "testmetric",
|
||||||
Timestamp: TimestampSourceTelegraf,
|
Timestamp: TimestampSourceTelegraf,
|
||||||
RootNodes: []NodeSettings{},
|
|
||||||
Groups: []NodeGroupSettings{
|
Groups: []NodeGroupSettings{
|
||||||
{
|
{
|
||||||
MetricName: "groupmetric",
|
MetricName: "groupmetric",
|
||||||
|
|
@ -593,7 +576,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
TagsSlice: [][]string{{"t2", "v2"}},
|
TagsSlice: [][]string{{"t2", "v2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TagsSlice: [][]string{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -618,7 +600,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
config: InputClientConfig{
|
config: InputClientConfig{
|
||||||
MetricName: "testmetric",
|
MetricName: "testmetric",
|
||||||
Timestamp: TimestampSourceTelegraf,
|
Timestamp: TimestampSourceTelegraf,
|
||||||
RootNodes: []NodeSettings{},
|
|
||||||
Groups: []NodeGroupSettings{
|
Groups: []NodeGroupSettings{
|
||||||
{
|
{
|
||||||
MetricName: "groupmetric",
|
MetricName: "groupmetric",
|
||||||
|
|
@ -632,7 +613,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
DefaultTags: map[string]string{"t3": "v3"},
|
DefaultTags: map[string]string{"t3": "v3"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TagsSlice: [][]string{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -668,7 +648,6 @@ func TestInitNodeMetricMapping(t *testing.T) {
|
||||||
DefaultTags: map[string]string{"t3": "v3"},
|
DefaultTags: map[string]string{"t3": "v3"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Groups: []NodeGroupSettings{},
|
|
||||||
},
|
},
|
||||||
expected: []NodeMetricMapping{
|
expected: []NodeMetricMapping{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -151,16 +151,15 @@ func pemBlockForKey(priv interface{}) (*pem.Block, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OpcUAClient) generateClientOpts(endpoints []*ua.EndpointDescription) ([]opcua.Option, error) {
|
func (o *OpcUAClient) generateClientOpts(endpoints []*ua.EndpointDescription) ([]opcua.Option, error) {
|
||||||
opts := []opcua.Option{}
|
|
||||||
appuri := "urn:telegraf:gopcua:client"
|
appuri := "urn:telegraf:gopcua:client"
|
||||||
appname := "Telegraf"
|
appname := "Telegraf"
|
||||||
|
|
||||||
// ApplicationURI is automatically read from the cert so is not required if a cert if provided
|
// ApplicationURI is automatically read from the cert so is not required if a cert if provided
|
||||||
opts = append(opts,
|
opts := []opcua.Option{
|
||||||
opcua.ApplicationURI(appuri),
|
opcua.ApplicationURI(appuri),
|
||||||
opcua.ApplicationName(appname),
|
opcua.ApplicationName(appname),
|
||||||
opcua.RequestTimeout(time.Duration(o.Config.RequestTimeout)),
|
opcua.RequestTimeout(time.Duration(o.Config.RequestTimeout)),
|
||||||
)
|
}
|
||||||
|
|
||||||
if o.Config.SessionTimeout != 0 {
|
if o.Config.SessionTimeout != 0 {
|
||||||
opts = append(opts, opcua.SessionTimeout(time.Duration(o.Config.SessionTimeout)))
|
opts = append(opts, opcua.SessionTimeout(time.Duration(o.Config.SessionTimeout)))
|
||||||
|
|
|
||||||
|
|
@ -153,17 +153,17 @@ func DefaultImportedPlugins() config {
|
||||||
}
|
}
|
||||||
for name := range inputs.Inputs {
|
for name := range inputs.Inputs {
|
||||||
log.Println("No config found. Loading default config for plugin", name)
|
log.Println("No config found. Loading default config for plugin", name)
|
||||||
conf.Inputs[name] = []toml.Primitive{}
|
conf.Inputs[name] = make([]toml.Primitive, 0)
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
for name := range processors.Processors {
|
for name := range processors.Processors {
|
||||||
log.Println("No config found. Loading default config for plugin", name)
|
log.Println("No config found. Loading default config for plugin", name)
|
||||||
conf.Processors[name] = []toml.Primitive{}
|
conf.Processors[name] = make([]toml.Primitive, 0)
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
for name := range outputs.Outputs {
|
for name := range outputs.Outputs {
|
||||||
log.Println("No config found. Loading default config for plugin", name)
|
log.Println("No config found. Loading default config for plugin", name)
|
||||||
conf.Outputs[name] = []toml.Primitive{}
|
conf.Outputs[name] = make([]toml.Primitive, 0)
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func (s *Common) GetState() interface{} {
|
||||||
// Return the actual byte-type instead of nil allowing the persister
|
// Return the actual byte-type instead of nil allowing the persister
|
||||||
// to guess instantiate variable of the appropriate type
|
// to guess instantiate variable of the appropriate type
|
||||||
if s.state == nil {
|
if s.state == nil {
|
||||||
return []byte{}
|
return make([]byte, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the starlark dict into a golang dictionary for serialization
|
// Convert the starlark dict into a golang dictionary for serialization
|
||||||
|
|
@ -65,7 +65,7 @@ func (s *Common) GetState() interface{} {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := gob.NewEncoder(&buf).Encode(state); err != nil {
|
if err := gob.NewEncoder(&buf).Encode(state); err != nil {
|
||||||
s.Log.Errorf("encoding state failed: %v", err)
|
s.Log.Errorf("encoding state failed: %v", err)
|
||||||
return []byte{}
|
return make([]byte, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,7 @@ func Ciphers() (secure, insecure []string) {
|
||||||
// ParseCiphers returns a `[]uint16` by received `[]string` key that represents ciphers from crypto/tls.
|
// ParseCiphers returns a `[]uint16` by received `[]string` key that represents ciphers from crypto/tls.
|
||||||
// If some of ciphers in received list doesn't exists ParseCiphers returns nil with error
|
// If some of ciphers in received list doesn't exists ParseCiphers returns nil with error
|
||||||
func ParseCiphers(ciphers []string) ([]uint16, error) {
|
func ParseCiphers(ciphers []string) ([]uint16, error) {
|
||||||
suites := []uint16{}
|
suites := make([]uint16, 0)
|
||||||
|
|
||||||
added := make(map[uint16]bool, len(ciphers))
|
added := make(map[uint16]bool, len(ciphers))
|
||||||
for _, c := range ciphers {
|
for _, c := range ciphers {
|
||||||
// Handle meta-keywords
|
// Handle meta-keywords
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func (s *AliyunCMS) Init() error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metric.dimensionsUdObj = make(map[string]string)
|
metric.dimensionsUdObj = make(map[string]string)
|
||||||
metric.dimensionsUdArr = []map[string]string{}
|
metric.dimensionsUdArr = make([]map[string]string, 0)
|
||||||
|
|
||||||
// first try to unmarshal as an object
|
// first try to unmarshal as an object
|
||||||
if err := json.Unmarshal([]byte(metric.Dimensions), &metric.dimensionsUdObj); err == nil {
|
if err := json.Unmarshal([]byte(metric.Dimensions), &metric.dimensionsUdObj); err == nil {
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,7 @@ func TestPluginMetricsInitialize(t *testing.T) {
|
||||||
accessKeySecret: "dummy",
|
accessKeySecret: "dummy",
|
||||||
metrics: []*metric{
|
metrics: []*metric{
|
||||||
{
|
{
|
||||||
MetricNames: []string{},
|
Dimensions: `{"instanceId": "i-abcdefgh123456"}`,
|
||||||
Dimensions: `{"instanceId": "i-abcdefgh123456"}`,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -263,8 +262,7 @@ func TestPluginMetricsInitialize(t *testing.T) {
|
||||||
accessKeySecret: "dummy",
|
accessKeySecret: "dummy",
|
||||||
metrics: []*metric{
|
metrics: []*metric{
|
||||||
{
|
{
|
||||||
MetricNames: []string{},
|
Dimensions: `[{"instanceId": "p-example"},{"instanceId": "q-example"}]`,
|
||||||
Dimensions: `[{"instanceId": "p-example"},{"instanceId": "q-example"}]`,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -277,8 +275,7 @@ func TestPluginMetricsInitialize(t *testing.T) {
|
||||||
expectedErrorString: `cannot parse dimensions (neither obj, nor array) "[": unexpected end of JSON input`,
|
expectedErrorString: `cannot parse dimensions (neither obj, nor array) "[": unexpected end of JSON input`,
|
||||||
metrics: []*metric{
|
metrics: []*metric{
|
||||||
{
|
{
|
||||||
MetricNames: []string{},
|
Dimensions: `[`,
|
||||||
Dimensions: `[`,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -344,8 +341,7 @@ func TestGatherMetric(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
metric := &metric{
|
metric := &metric{
|
||||||
MetricNames: []string{},
|
Dimensions: `"instanceId": "i-abcdefgh123456"`,
|
||||||
Dimensions: `"instanceId": "i-abcdefgh123456"`,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
@ -375,8 +371,7 @@ func TestGatherMetric(t *testing.T) {
|
||||||
|
|
||||||
func TestGather(t *testing.T) {
|
func TestGather(t *testing.T) {
|
||||||
m := &metric{
|
m := &metric{
|
||||||
MetricNames: []string{},
|
Dimensions: `{"instanceId": "i-abcdefgh123456"}`,
|
||||||
Dimensions: `{"instanceId": "i-abcdefgh123456"}`,
|
|
||||||
}
|
}
|
||||||
plugin := &AliyunCMS{
|
plugin := &AliyunCMS{
|
||||||
AccessKeyID: "my_access_key_id",
|
AccessKeyID: "my_access_key_id",
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ func (rsmi *ROCmSMI) pollROCmSMI() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func genTagsFields(gpus map[string]gpu, system map[string]sysInfo) []metric {
|
func genTagsFields(gpus map[string]gpu, system map[string]sysInfo) []metric {
|
||||||
metrics := []metric{}
|
metrics := make([]metric, 0, len(gpus))
|
||||||
for cardID := range gpus {
|
for cardID := range gpus {
|
||||||
if strings.Contains(cardID, "card") {
|
if strings.Contains(cardID, "card") {
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
|
|
|
||||||
|
|
@ -923,7 +923,7 @@ func TestGather_Success(t *testing.T) {
|
||||||
|
|
||||||
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
||||||
am.SubscriptionID,
|
am.SubscriptionID,
|
||||||
receiver.NewTargets(resourceTargets, []*receiver.ResourceGroupTarget{}, []*receiver.Resource{}),
|
receiver.NewTargets(resourceTargets, nil, nil),
|
||||||
azureClients,
|
azureClients,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -1010,7 +1010,7 @@ func TestGather_China_Success(t *testing.T) {
|
||||||
|
|
||||||
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
||||||
am.SubscriptionID,
|
am.SubscriptionID,
|
||||||
receiver.NewTargets(resourceTargets, []*receiver.ResourceGroupTarget{}, []*receiver.Resource{}),
|
receiver.NewTargets(resourceTargets, nil, nil),
|
||||||
azureClients,
|
azureClients,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -1043,7 +1043,7 @@ func TestGather_Government_Success(t *testing.T) {
|
||||||
|
|
||||||
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
||||||
am.SubscriptionID,
|
am.SubscriptionID,
|
||||||
receiver.NewTargets(resourceTargets, []*receiver.ResourceGroupTarget{}, []*receiver.Resource{}),
|
receiver.NewTargets(resourceTargets, nil, nil),
|
||||||
azureClients,
|
azureClients,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -1076,7 +1076,7 @@ func TestGather_Public_Success(t *testing.T) {
|
||||||
|
|
||||||
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
am.receiver, err = receiver.NewAzureMonitorMetricsReceiver(
|
||||||
am.SubscriptionID,
|
am.SubscriptionID,
|
||||||
receiver.NewTargets(resourceTargets, []*receiver.ResourceGroupTarget{}, []*receiver.Resource{}),
|
receiver.NewTargets(resourceTargets, nil, nil),
|
||||||
azureClients,
|
azureClients,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,11 @@ func TestBeanstalkd(t *testing.T) {
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "All tubes stats",
|
name: "All tubes stats",
|
||||||
tubesConfig: []string{},
|
|
||||||
expectedTubes: []tubeStats{
|
expectedTubes: []tubeStats{
|
||||||
{name: "default", fields: defaultTubeFields},
|
{name: "default", fields: defaultTubeFields},
|
||||||
{name: "test", fields: testTubeFields},
|
{name: "test", fields: testTubeFields},
|
||||||
},
|
},
|
||||||
notExpectedTubes: []tubeStats{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Specified tubes stats",
|
name: "Specified tubes stats",
|
||||||
|
|
@ -45,9 +43,8 @@ func TestBeanstalkd(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Unknown tube stats",
|
name: "Unknown tube stats",
|
||||||
tubesConfig: []string{"unknown"},
|
tubesConfig: []string{"unknown"},
|
||||||
expectedTubes: []tubeStats{},
|
|
||||||
notExpectedTubes: []tubeStats{
|
notExpectedTubes: []tubeStats{
|
||||||
{name: "default", fields: defaultTubeFields},
|
{name: "default", fields: defaultTubeFields},
|
||||||
{name: "test", fields: testTubeFields},
|
{name: "test", fields: testTubeFields},
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ var perfDump = func(binary string, socket *socket) (string, error) {
|
||||||
var findSockets = func(c *Ceph) ([]*socket, error) {
|
var findSockets = func(c *Ceph) ([]*socket, error) {
|
||||||
listing, err := os.ReadDir(c.SocketDir)
|
listing, err := os.ReadDir(c.SocketDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []*socket{}, fmt.Errorf("failed to read socket directory %q: %w", c.SocketDir, err)
|
return nil, fmt.Errorf("failed to read socket directory %q: %w", c.SocketDir, err)
|
||||||
}
|
}
|
||||||
sockets := make([]*socket, 0, len(listing))
|
sockets := make([]*socket, 0, len(listing))
|
||||||
for _, info := range listing {
|
for _, info := range listing {
|
||||||
|
|
@ -714,7 +714,7 @@ type osdPoolStats []struct {
|
||||||
|
|
||||||
// decodeOsdPoolStats decodes the output of 'ceph osd pool stats'
|
// decodeOsdPoolStats decodes the output of 'ceph osd pool stats'
|
||||||
func decodeOsdPoolStats(acc telegraf.Accumulator, input string) error {
|
func decodeOsdPoolStats(acc telegraf.Accumulator, input string) error {
|
||||||
data := osdPoolStats{}
|
data := make(osdPoolStats, 0)
|
||||||
if err := json.Unmarshal([]byte(input), &data); err != nil {
|
if err := json.Unmarshal([]byte(input), &data); err != nil {
|
||||||
return fmt.Errorf("failed to parse json: %q: %w", input, err)
|
return fmt.Errorf("failed to parse json: %q: %w", input, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ func TestClusterIncludeExcludeFilter(t *testing.T) {
|
||||||
ch.ClusterInclude = []string{"cluster"}
|
ch.ClusterInclude = []string{"cluster"}
|
||||||
require.Equal(t, "WHERE cluster IN ('cluster') OR cluster NOT IN ('test_cluster')", ch.clusterIncludeExcludeFilter())
|
require.Equal(t, "WHERE cluster IN ('cluster') OR cluster NOT IN ('test_cluster')", ch.clusterIncludeExcludeFilter())
|
||||||
|
|
||||||
ch.ClusterExclude = []string{}
|
ch.ClusterExclude = make([]string, 0)
|
||||||
ch.ClusterInclude = []string{"cluster1", "cluster2"}
|
ch.ClusterInclude = []string{"cluster1", "cluster2"}
|
||||||
require.Equal(t, "WHERE cluster IN ('cluster1', 'cluster2')", ch.clusterIncludeExcludeFilter())
|
require.Equal(t, "WHERE cluster IN ('cluster1', 'cluster2')", ch.clusterIncludeExcludeFilter())
|
||||||
|
|
||||||
ch.ClusterExclude = []string{"cluster1", "cluster2"}
|
ch.ClusterExclude = []string{"cluster1", "cluster2"}
|
||||||
ch.ClusterInclude = []string{}
|
ch.ClusterInclude = make([]string, 0)
|
||||||
require.Equal(t, "WHERE cluster NOT IN ('cluster1', 'cluster2')", ch.clusterIncludeExcludeFilter())
|
require.Equal(t, "WHERE cluster NOT IN ('cluster1', 'cluster2')", ch.clusterIncludeExcludeFilter())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -623,7 +623,7 @@ func TestWrongJSONMarshalling(t *testing.T) {
|
||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
// wrong data section json
|
// wrong data section json
|
||||||
err := enc.Encode(result{
|
err := enc.Encode(result{
|
||||||
Data: []struct{}{},
|
Data: make([]struct{}, 0),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
|
||||||
|
|
@ -236,12 +236,12 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) {
|
||||||
return c.metricCache.metrics, nil
|
return c.metricCache.metrics, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fMetrics := []filteredMetric{}
|
fMetrics := make([]filteredMetric, 0)
|
||||||
|
|
||||||
// check for provided metric filter
|
// check for provided metric filter
|
||||||
if c.Metrics != nil {
|
if c.Metrics != nil {
|
||||||
for _, m := range c.Metrics {
|
for _, m := range c.Metrics {
|
||||||
metrics := []types.Metric{}
|
metrics := make([]types.Metric, 0)
|
||||||
var accounts []string
|
var accounts []string
|
||||||
if !hasWildcard(m.Dimensions) {
|
if !hasWildcard(m.Dimensions) {
|
||||||
dimensions := make([]types.Dimension, 0, len(m.Dimensions))
|
dimensions := make([]types.Dimension, 0, len(m.Dimensions))
|
||||||
|
|
@ -321,11 +321,11 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) {
|
||||||
|
|
||||||
// fetchNamespaceMetrics retrieves available metrics for a given CloudWatch namespace.
|
// fetchNamespaceMetrics retrieves available metrics for a given CloudWatch namespace.
|
||||||
func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, []string) {
|
func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, []string) {
|
||||||
metrics := []types.Metric{}
|
metrics := make([]types.Metric, 0)
|
||||||
var accounts []string
|
var accounts []string
|
||||||
for _, namespace := range c.Namespaces {
|
for _, namespace := range c.Namespaces {
|
||||||
params := &cloudwatch.ListMetricsInput{
|
params := &cloudwatch.ListMetricsInput{
|
||||||
Dimensions: []types.DimensionFilter{},
|
Dimensions: make([]types.DimensionFilter, 0),
|
||||||
Namespace: aws.String(namespace),
|
Namespace: aws.String(namespace),
|
||||||
IncludeLinkedAccounts: &c.IncludeLinkedAccounts,
|
IncludeLinkedAccounts: &c.IncludeLinkedAccounts,
|
||||||
}
|
}
|
||||||
|
|
@ -434,7 +434,7 @@ func (c *CloudWatch) getDataQueries(filteredMetrics []filteredMetric) map[string
|
||||||
func (c *CloudWatch) gatherMetrics(
|
func (c *CloudWatch) gatherMetrics(
|
||||||
params *cloudwatch.GetMetricDataInput,
|
params *cloudwatch.GetMetricDataInput,
|
||||||
) ([]types.MetricDataResult, error) {
|
) ([]types.MetricDataResult, error) {
|
||||||
results := []types.MetricDataResult{}
|
results := make([]types.MetricDataResult, 0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
resp, err := c.client.GetMetricData(context.Background(), params)
|
resp, err := c.client.GetMetricData(context.Background(), params)
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ func (m *mockSelectMetricsCloudWatchClient) ListMetrics(
|
||||||
_ *cloudwatch.ListMetricsInput,
|
_ *cloudwatch.ListMetricsInput,
|
||||||
_ ...func(*cloudwatch.Options),
|
_ ...func(*cloudwatch.Options),
|
||||||
) (*cloudwatch.ListMetricsOutput, error) {
|
) (*cloudwatch.ListMetricsOutput, error) {
|
||||||
metrics := []types.Metric{}
|
metrics := make([]types.Metric, 0)
|
||||||
// 4 metrics are available
|
// 4 metrics are available
|
||||||
metricNames := []string{"Latency", "RequestCount", "HealthyHostCount", "UnHealthyHostCount"}
|
metricNames := []string{"Latency", "RequestCount", "HealthyHostCount", "UnHealthyHostCount"}
|
||||||
// for 3 ELBs
|
// for 3 ELBs
|
||||||
|
|
@ -493,7 +493,7 @@ func TestGenerateStatisticsInputParamsFiltered(t *testing.T) {
|
||||||
|
|
||||||
func TestMetricsCacheTimeout(t *testing.T) {
|
func TestMetricsCacheTimeout(t *testing.T) {
|
||||||
cache := &metricCache{
|
cache := &metricCache{
|
||||||
metrics: []filteredMetric{},
|
metrics: make([]filteredMetric, 0),
|
||||||
built: time.Now(),
|
built: time.Now(),
|
||||||
ttl: time.Minute,
|
ttl: time.Minute,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func (*Couchbase) SampleConfig() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cb *Couchbase) Init() error {
|
func (cb *Couchbase) Init() error {
|
||||||
f, err := filter.NewIncludeExcludeFilter(cb.BucketStatsIncluded, []string{})
|
f, err := filter.NewIncludeExcludeFilter(cb.BucketStatsIncluded, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ func (s *subscription) createRequest(id string) subscriptionRequest {
|
||||||
|
|
||||||
// addressList lists all configured node addresses
|
// addressList lists all configured node addresses
|
||||||
func (s *subscription) addressList() []string {
|
func (s *subscription) addressList() []string {
|
||||||
addressList := []string{}
|
addressList := make([]string, 0)
|
||||||
for _, node := range s.Nodes {
|
for _, node := range s.Nodes {
|
||||||
addressList = append(addressList, node.Address)
|
addressList = append(addressList, node.Address)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,10 +212,8 @@ func (c *clusterClient) getSummary(ctx context.Context) (*summary, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clusterClient) getContainers(ctx context.Context, node string) ([]container, error) {
|
func (c *clusterClient) getContainers(ctx context.Context, node string) ([]container, error) {
|
||||||
list := []string{}
|
list := make([]string, 0)
|
||||||
|
err := c.doGet(ctx, c.toURL(fmt.Sprintf("/system/v1/agent/%s/metrics/v0/containers", node)), &list)
|
||||||
path := fmt.Sprintf("/system/v1/agent/%s/metrics/v0/containers", node)
|
|
||||||
err := c.doGet(ctx, c.toURL(path), &list)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func TestGetSummary(t *testing.T) {
|
||||||
name: "No nodes",
|
name: "No nodes",
|
||||||
responseCode: http.StatusOK,
|
responseCode: http.StatusOK,
|
||||||
responseBody: `{"cluster": "a", "slaves": []}`,
|
responseBody: `{"cluster": "a", "slaves": []}`,
|
||||||
expectedValue: &summary{Cluster: "a", Slaves: []slave{}},
|
expectedValue: &summary{Cluster: "a", Slaves: make([]slave, 0)},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,6 @@ func TestGatherFilterNode(t *testing.T) {
|
||||||
GetSummaryF: func() (*summary, error) {
|
GetSummaryF: func() (*summary, error) {
|
||||||
return &summary{
|
return &summary{
|
||||||
Cluster: "a",
|
Cluster: "a",
|
||||||
Slaves: []slave{},
|
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -391,7 +390,7 @@ func TestGatherFilterNode(t *testing.T) {
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
GetContainersF: func() ([]container, error) {
|
GetContainersF: func() ([]container, error) {
|
||||||
return []container{}, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
GetNodeMetricsF: func() (*metrics, error) {
|
GetNodeMetricsF: func() (*metrics, error) {
|
||||||
return &metrics{
|
return &metrics{
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ func dmSetupStatus() ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if string(out) == "No devices found\n" {
|
if string(out) == "No devices found\n" {
|
||||||
return []string{}, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
outString := strings.TrimRight(string(out), "\n")
|
outString := strings.TrimRight(string(out), "\n")
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ func TestNoDevicesOutput(t *testing.T) {
|
||||||
var plugin = &DMCache{
|
var plugin = &DMCache{
|
||||||
PerDevice: true,
|
PerDevice: true,
|
||||||
getCurrentStatus: func() ([]string, error) {
|
getCurrentStatus: func() ([]string, error) {
|
||||||
return []string{}, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func (d *Docker) Init() error {
|
||||||
if choice.Contains("cpu", d.TotalInclude) {
|
if choice.Contains("cpu", d.TotalInclude) {
|
||||||
d.TotalInclude = []string{"cpu"}
|
d.TotalInclude = []string{"cpu"}
|
||||||
} else {
|
} else {
|
||||||
d.TotalInclude = []string{}
|
d.TotalInclude = make([]string, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -484,8 +484,6 @@ func TestContainerLabels(t *testing.T) {
|
||||||
container: genContainerLabeled(map[string]string{
|
container: genContainerLabeled(map[string]string{
|
||||||
"a": "x",
|
"a": "x",
|
||||||
}),
|
}),
|
||||||
include: []string{},
|
|
||||||
exclude: []string{},
|
|
||||||
expected: map[string]string{
|
expected: map[string]string{
|
||||||
"a": "x",
|
"a": "x",
|
||||||
},
|
},
|
||||||
|
|
@ -497,7 +495,6 @@ func TestContainerLabels(t *testing.T) {
|
||||||
"b": "y",
|
"b": "y",
|
||||||
}),
|
}),
|
||||||
include: []string{"a"},
|
include: []string{"a"},
|
||||||
exclude: []string{},
|
|
||||||
expected: map[string]string{
|
expected: map[string]string{
|
||||||
"a": "x",
|
"a": "x",
|
||||||
},
|
},
|
||||||
|
|
@ -508,7 +505,6 @@ func TestContainerLabels(t *testing.T) {
|
||||||
"a": "x",
|
"a": "x",
|
||||||
"b": "y",
|
"b": "y",
|
||||||
}),
|
}),
|
||||||
include: []string{},
|
|
||||||
exclude: []string{"b"},
|
exclude: []string{"b"},
|
||||||
expected: map[string]string{
|
expected: map[string]string{
|
||||||
"a": "x",
|
"a": "x",
|
||||||
|
|
@ -522,7 +518,6 @@ func TestContainerLabels(t *testing.T) {
|
||||||
"bb": "z",
|
"bb": "z",
|
||||||
}),
|
}),
|
||||||
include: []string{"a*"},
|
include: []string{"a*"},
|
||||||
exclude: []string{},
|
|
||||||
expected: map[string]string{
|
expected: map[string]string{
|
||||||
"aa": "x",
|
"aa": "x",
|
||||||
"ab": "y",
|
"ab": "y",
|
||||||
|
|
@ -535,7 +530,6 @@ func TestContainerLabels(t *testing.T) {
|
||||||
"ab": "y",
|
"ab": "y",
|
||||||
"bb": "z",
|
"bb": "z",
|
||||||
}),
|
}),
|
||||||
include: []string{},
|
|
||||||
exclude: []string{"a*"},
|
exclude: []string{"a*"},
|
||||||
expected: map[string]string{
|
expected: map[string]string{
|
||||||
"bb": "z",
|
"bb": "z",
|
||||||
|
|
@ -616,51 +610,42 @@ func TestContainerNames(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty filters matches all",
|
name: "Empty filters matches all",
|
||||||
include: []string{},
|
|
||||||
exclude: []string{},
|
|
||||||
expected: []string{"etcd", "etcd2", "acme", "acme-test", "foo"},
|
expected: []string{"etcd", "etcd2", "acme", "acme-test", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Match all containers",
|
name: "Match all containers",
|
||||||
include: []string{"*"},
|
include: []string{"*"},
|
||||||
exclude: []string{},
|
|
||||||
expected: []string{"etcd", "etcd2", "acme", "acme-test", "foo"},
|
expected: []string{"etcd", "etcd2", "acme", "acme-test", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Include prefix match",
|
name: "Include prefix match",
|
||||||
include: []string{"etc*"},
|
include: []string{"etc*"},
|
||||||
exclude: []string{},
|
|
||||||
expected: []string{"etcd", "etcd2"},
|
expected: []string{"etcd", "etcd2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exact match",
|
name: "Exact match",
|
||||||
include: []string{"etcd"},
|
include: []string{"etcd"},
|
||||||
exclude: []string{},
|
|
||||||
expected: []string{"etcd"},
|
expected: []string{"etcd"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Star matches zero length",
|
name: "Star matches zero length",
|
||||||
include: []string{"etcd2*"},
|
include: []string{"etcd2*"},
|
||||||
exclude: []string{},
|
|
||||||
expected: []string{"etcd2"},
|
expected: []string{"etcd2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude matches all",
|
name: "Exclude matches all",
|
||||||
include: []string{},
|
|
||||||
exclude: []string{"etc*"},
|
exclude: []string{"etc*"},
|
||||||
expected: []string{"acme", "acme-test", "foo"},
|
expected: []string{"acme", "acme-test", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude single",
|
name: "Exclude single",
|
||||||
include: []string{},
|
|
||||||
exclude: []string{"etcd"},
|
exclude: []string{"etcd"},
|
||||||
expected: []string{"etcd2", "acme", "acme-test", "foo"},
|
expected: []string{"etcd2", "acme", "acme-test", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude all",
|
name: "Exclude all",
|
||||||
include: []string{"*"},
|
include: []string{"*"},
|
||||||
exclude: []string{"*"},
|
exclude: []string{"*"},
|
||||||
expected: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude item matching include",
|
name: "Exclude item matching include",
|
||||||
|
|
@ -721,7 +706,7 @@ func TestContainerNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterMetrics(metrics []telegraf.Metric, f func(telegraf.Metric) bool) []telegraf.Metric {
|
func filterMetrics(metrics []telegraf.Metric, f func(telegraf.Metric) bool) []telegraf.Metric {
|
||||||
results := []telegraf.Metric{}
|
results := make([]telegraf.Metric, 0, len(metrics))
|
||||||
for _, m := range metrics {
|
for _, m := range metrics {
|
||||||
if f(m) {
|
if f(m) {
|
||||||
results = append(results, m)
|
results = append(results, m)
|
||||||
|
|
@ -1406,7 +1391,6 @@ func Test_parseContainerStatsPerDeviceAndTotal(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
stat: stats,
|
stat: stats,
|
||||||
perDeviceInclude: containerMetricClasses,
|
perDeviceInclude: containerMetricClasses,
|
||||||
totalInclude: []string{},
|
|
||||||
},
|
},
|
||||||
expected: []telegraf.Metric{
|
expected: []telegraf.Metric{
|
||||||
metricCPU0, metricCPU1,
|
metricCPU0, metricCPU1,
|
||||||
|
|
@ -1417,20 +1401,16 @@ func Test_parseContainerStatsPerDeviceAndTotal(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "Total metrics enabled",
|
name: "Total metrics enabled",
|
||||||
args: args{
|
args: args{
|
||||||
stat: stats,
|
stat: stats,
|
||||||
perDeviceInclude: []string{},
|
totalInclude: containerMetricClasses,
|
||||||
totalInclude: containerMetricClasses,
|
|
||||||
},
|
},
|
||||||
expected: []telegraf.Metric{metricCPUTotal, metricNetworkTotal, metricBlkioTotal},
|
expected: []telegraf.Metric{metricCPUTotal, metricNetworkTotal, metricBlkioTotal},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Per device and total metrics disabled",
|
name: "Per device and total metrics disabled",
|
||||||
args: args{
|
args: args{
|
||||||
stat: stats,
|
stat: stats,
|
||||||
perDeviceInclude: []string{},
|
|
||||||
totalInclude: []string{},
|
|
||||||
},
|
},
|
||||||
expected: []telegraf.Metric{},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1468,52 +1448,46 @@ func TestDocker_Init(t *testing.T) {
|
||||||
wantTotalInclude []string
|
wantTotalInclude []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"Unsupported perdevice_include setting",
|
name: "Unsupported perdevice_include setting",
|
||||||
fields{
|
fields: fields{
|
||||||
PerDevice: false,
|
PerDevice: false,
|
||||||
PerDeviceInclude: []string{"nonExistentClass"},
|
PerDeviceInclude: []string{"nonExistentClass"},
|
||||||
Total: false,
|
Total: false,
|
||||||
TotalInclude: []string{"cpu"},
|
TotalInclude: []string{"cpu"},
|
||||||
},
|
},
|
||||||
true,
|
wantErr: true,
|
||||||
[]string{},
|
|
||||||
[]string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Unsupported total_include setting",
|
name: "Unsupported total_include setting",
|
||||||
fields{
|
fields: fields{
|
||||||
PerDevice: false,
|
PerDevice: false,
|
||||||
PerDeviceInclude: []string{"cpu"},
|
PerDeviceInclude: []string{"cpu"},
|
||||||
Total: false,
|
Total: false,
|
||||||
TotalInclude: []string{"nonExistentClass"},
|
TotalInclude: []string{"nonExistentClass"},
|
||||||
},
|
},
|
||||||
true,
|
wantErr: true,
|
||||||
[]string{},
|
|
||||||
[]string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PerDevice true adds network and blkio",
|
name: "PerDevice true adds network and blkio",
|
||||||
fields{
|
fields: fields{
|
||||||
PerDevice: true,
|
PerDevice: true,
|
||||||
PerDeviceInclude: []string{"cpu"},
|
PerDeviceInclude: []string{"cpu"},
|
||||||
Total: true,
|
Total: true,
|
||||||
TotalInclude: []string{"cpu"},
|
TotalInclude: []string{"cpu"},
|
||||||
},
|
},
|
||||||
false,
|
wantPerDeviceInclude: []string{"cpu", "network", "blkio"},
|
||||||
[]string{"cpu", "network", "blkio"},
|
wantTotalInclude: []string{"cpu"},
|
||||||
[]string{"cpu"},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Total false removes network and blkio",
|
name: "Total false removes network and blkio",
|
||||||
fields{
|
fields: fields{
|
||||||
PerDevice: false,
|
PerDevice: false,
|
||||||
PerDeviceInclude: []string{"cpu"},
|
PerDeviceInclude: []string{"cpu"},
|
||||||
Total: false,
|
Total: false,
|
||||||
TotalInclude: []string{"cpu", "network", "blkio"},
|
TotalInclude: []string{"cpu", "network", "blkio"},
|
||||||
},
|
},
|
||||||
false,
|
wantPerDeviceInclude: []string{"cpu"},
|
||||||
[]string{"cpu"},
|
wantTotalInclude: []string{"cpu"},
|
||||||
[]string{"cpu"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
@ -1552,8 +1526,7 @@ func TestDockerGatherDiskUsage(t *testing.T) {
|
||||||
|
|
||||||
require.NoError(t, acc.GatherError(d.Gather))
|
require.NoError(t, acc.GatherError(d.Gather))
|
||||||
|
|
||||||
duOpts := types.DiskUsageOptions{Types: []types.DiskUsageObject{}}
|
d.gatherDiskUsage(&acc, types.DiskUsageOptions{})
|
||||||
d.gatherDiskUsage(&acc, duOpts)
|
|
||||||
|
|
||||||
acc.AssertContainsTaggedFields(t,
|
acc.AssertContainsTaggedFields(t,
|
||||||
"docker_disk_usage",
|
"docker_disk_usage",
|
||||||
|
|
|
||||||
|
|
@ -40,15 +40,15 @@ var info = system.Info{
|
||||||
IndexConfigs: map[string]*registry.IndexInfo{
|
IndexConfigs: map[string]*registry.IndexInfo{
|
||||||
"docker.io": {
|
"docker.io": {
|
||||||
Name: "docker.io",
|
Name: "docker.io",
|
||||||
Mirrors: []string{},
|
Mirrors: make([]string, 0),
|
||||||
Official: true,
|
Official: true,
|
||||||
Secure: true,
|
Secure: true,
|
||||||
},
|
},
|
||||||
}, InsecureRegistryCIDRs: []*registry.NetIPNet{{IP: []byte{127, 0, 0, 0}, Mask: []byte{255, 0, 0, 0}}}, Mirrors: []string{}},
|
}, InsecureRegistryCIDRs: []*registry.NetIPNet{{IP: []byte{127, 0, 0, 0}, Mask: []byte{255, 0, 0, 0}}}, Mirrors: make([]string, 0)},
|
||||||
OperatingSystem: "Linux Mint LMDE (containerized)",
|
OperatingSystem: "Linux Mint LMDE (containerized)",
|
||||||
BridgeNfIptables: true,
|
BridgeNfIptables: true,
|
||||||
HTTPSProxy: "",
|
HTTPSProxy: "",
|
||||||
Labels: []string{},
|
Labels: make([]string, 0),
|
||||||
MemoryLimit: false,
|
MemoryLimit: false,
|
||||||
DriverStatus: [][2]string{
|
DriverStatus: [][2]string{
|
||||||
{"Pool Name", "docker-8:1-1182287-pool"},
|
{"Pool Name", "docker-8:1-1182287-pool"},
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,9 @@ func Test_Init(t *testing.T) {
|
||||||
t.Run("when device_types and additional_commands are empty, then error should be returned", func(t *testing.T) {
|
t.Run("when device_types and additional_commands are empty, then error should be returned", func(t *testing.T) {
|
||||||
pathToSocket, _ := createSocketForTest(t, "")
|
pathToSocket, _ := createSocketForTest(t, "")
|
||||||
dpdk := Dpdk{
|
dpdk := Dpdk{
|
||||||
SocketPath: pathToSocket,
|
SocketPath: pathToSocket,
|
||||||
DeviceTypes: []string{},
|
DeviceTypes: make([]string, 0),
|
||||||
AdditionalCommands: []string{},
|
Log: testutil.Logger{},
|
||||||
Log: testutil.Logger{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dpdk.Init()
|
err := dpdk.Init()
|
||||||
|
|
@ -481,10 +480,6 @@ func Test_getCommandsAndParamsCombinations(t *testing.T) {
|
||||||
|
|
||||||
dpdk.DeviceTypes = []string{"ethdev"}
|
dpdk.DeviceTypes = []string{"ethdev"}
|
||||||
dpdk.ethdevCommands = []string{"/ethdev/stats", "/ethdev/xstats"}
|
dpdk.ethdevCommands = []string{"/ethdev/stats", "/ethdev/xstats"}
|
||||||
var err error
|
|
||||||
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile([]string{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
dpdk.AdditionalCommands = []string{}
|
|
||||||
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
||||||
|
|
||||||
require.ElementsMatch(t, commands, expectedCommands)
|
require.ElementsMatch(t, commands, expectedCommands)
|
||||||
|
|
@ -500,7 +495,6 @@ func Test_getCommandsAndParamsCombinations(t *testing.T) {
|
||||||
|
|
||||||
dpdk.DeviceTypes = []string{"rawdev"}
|
dpdk.DeviceTypes = []string{"rawdev"}
|
||||||
dpdk.rawdevCommands = []string{"/rawdev/xstats"}
|
dpdk.rawdevCommands = []string{"/rawdev/xstats"}
|
||||||
dpdk.AdditionalCommands = []string{}
|
|
||||||
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
||||||
|
|
||||||
require.ElementsMatch(t, commands, expectedCommands)
|
require.ElementsMatch(t, commands, expectedCommands)
|
||||||
|
|
@ -519,7 +513,6 @@ func Test_getCommandsAndParamsCombinations(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile([]string{"/ethdev/xstats"})
|
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile([]string{"/ethdev/xstats"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dpdk.AdditionalCommands = []string{}
|
|
||||||
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
||||||
|
|
||||||
require.ElementsMatch(t, commands, expectedCommands)
|
require.ElementsMatch(t, commands, expectedCommands)
|
||||||
|
|
@ -533,10 +526,6 @@ func Test_getCommandsAndParamsCombinations(t *testing.T) {
|
||||||
|
|
||||||
dpdk.DeviceTypes = []string{"ethdev"}
|
dpdk.DeviceTypes = []string{"ethdev"}
|
||||||
dpdk.ethdevCommands = []string{"/ethdev/stats", "/ethdev/xstats"}
|
dpdk.ethdevCommands = []string{"/ethdev/stats", "/ethdev/xstats"}
|
||||||
var err error
|
|
||||||
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile([]string{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
dpdk.AdditionalCommands = []string{}
|
|
||||||
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
commands := dpdk.gatherCommands(mockAcc, dpdk.connectors[0])
|
||||||
|
|
||||||
require.Empty(t, commands)
|
require.Empty(t, commands)
|
||||||
|
|
@ -607,7 +596,7 @@ func Test_Gather(t *testing.T) {
|
||||||
mockAcc := &testutil.Accumulator{}
|
mockAcc := &testutil.Accumulator{}
|
||||||
dpdk := Dpdk{
|
dpdk := Dpdk{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
PluginOptions: []string{},
|
PluginOptions: make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, dpdk.Init())
|
require.NoError(t, dpdk.Init())
|
||||||
|
|
@ -621,7 +610,6 @@ func Test_Gather(t *testing.T) {
|
||||||
mockAcc := &testutil.Accumulator{}
|
mockAcc := &testutil.Accumulator{}
|
||||||
dpdk := Dpdk{
|
dpdk := Dpdk{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
PluginOptions: []string{},
|
|
||||||
UnreachableSocketBehavior: unreachableSocketBehaviorIgnore,
|
UnreachableSocketBehavior: unreachableSocketBehaviorIgnore,
|
||||||
}
|
}
|
||||||
require.NoError(t, dpdk.Init())
|
require.NoError(t, dpdk.Init())
|
||||||
|
|
@ -769,7 +757,6 @@ func Test_Gather(t *testing.T) {
|
||||||
MaxOutputLen: 1024,
|
MaxOutputLen: 1024,
|
||||||
}
|
}
|
||||||
mockConn, dpdk, mockAcc := prepareEnvironmentWithInitializedMessage(testInitMessage)
|
mockConn, dpdk, mockAcc := prepareEnvironmentWithInitializedMessage(testInitMessage)
|
||||||
dpdk.MetadataFields = []string{}
|
|
||||||
defer mockConn.AssertExpectations(t)
|
defer mockConn.AssertExpectations(t)
|
||||||
dpdk.AdditionalCommands = []string{"/endpoint1"}
|
dpdk.AdditionalCommands = []string{"/endpoint1"}
|
||||||
simulateResponse(mockConn, `{"/endpoint1":"myvalue"}`, nil)
|
simulateResponse(mockConn, `{"/endpoint1":"myvalue"}`, nil)
|
||||||
|
|
@ -801,7 +788,6 @@ func Test_Gather(t *testing.T) {
|
||||||
func Test_Gather_MultiSocket(t *testing.T) {
|
func Test_Gather_MultiSocket(t *testing.T) {
|
||||||
t.Run("Test Gather without Metadata Fields", func(t *testing.T) {
|
t.Run("Test Gather without Metadata Fields", func(t *testing.T) {
|
||||||
mockConns, dpdk, mockAcc := prepareEnvironmentWithMultiSockets()
|
mockConns, dpdk, mockAcc := prepareEnvironmentWithMultiSockets()
|
||||||
dpdk.MetadataFields = []string{}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, mockConn := range mockConns {
|
for _, mockConn := range mockConns {
|
||||||
mockConn.AssertExpectations(t)
|
mockConn.AssertExpectations(t)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue