fix(internal.ethtool): avoid internal name conflict with aws (#11696)
This commit is contained in:
parent
eabb66f7d7
commit
5f22bd17db
|
|
@ -108,6 +108,10 @@ func (e *Ethtool) normalizeKey(key string) string {
|
||||||
if inStringSlice(e.NormalizeKeys, "underscore") {
|
if inStringSlice(e.NormalizeKeys, "underscore") {
|
||||||
key = strings.ReplaceAll(key, " ", "_")
|
key = strings.ReplaceAll(key, " ", "_")
|
||||||
}
|
}
|
||||||
|
// aws has a conflicting name that needs to be renamed
|
||||||
|
if key == "interface_up" {
|
||||||
|
key = "interface_up_counter"
|
||||||
|
}
|
||||||
|
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,15 @@ func toStringMapInterface(in map[string]uint64) map[string]interface{} {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toStringMapUint(in map[string]interface{}) map[string]uint64 {
|
||||||
|
var m = map[string]uint64{}
|
||||||
|
for k, v := range in {
|
||||||
|
t := v.(uint64)
|
||||||
|
m[k] = t
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func TestGather(t *testing.T) {
|
func TestGather(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -314,15 +323,20 @@ func TestGather(t *testing.T) {
|
||||||
require.Len(t, acc.Metrics, 2)
|
require.Len(t, acc.Metrics, 2)
|
||||||
|
|
||||||
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
||||||
|
expectedFieldsEth1["interface_up_counter"] = expectedFieldsEth1["interface_up"]
|
||||||
|
expectedFieldsEth1["interface_up"] = true
|
||||||
|
|
||||||
expectedTagsEth1 := map[string]string{
|
expectedTagsEth1 := map[string]string{
|
||||||
"interface": "eth1",
|
"interface": "eth1",
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, pluginName, expectedFieldsEth1, expectedTagsEth1)
|
acc.AssertContainsTaggedFields(t, pluginName, expectedFieldsEth1, expectedTagsEth1)
|
||||||
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
||||||
|
expectedFieldsEth2["interface_up_counter"] = expectedFieldsEth2["interface_up"]
|
||||||
|
expectedFieldsEth2["interface_up"] = false
|
||||||
expectedTagsEth2 := map[string]string{
|
expectedTagsEth2 := map[string]string{
|
||||||
"interface": "eth2",
|
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
|
"interface": "eth2",
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, pluginName, expectedFieldsEth2, expectedTagsEth2)
|
acc.AssertContainsTaggedFields(t, pluginName, expectedFieldsEth2, expectedTagsEth2)
|
||||||
}
|
}
|
||||||
|
|
@ -339,6 +353,8 @@ func TestGatherIncludeInterfaces(t *testing.T) {
|
||||||
|
|
||||||
// Should contain eth1
|
// Should contain eth1
|
||||||
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
||||||
|
expectedFieldsEth1["interface_up_counter"] = expectedFieldsEth1["interface_up"]
|
||||||
|
expectedFieldsEth1["interface_up"] = true
|
||||||
expectedTagsEth1 := map[string]string{
|
expectedTagsEth1 := map[string]string{
|
||||||
"interface": "eth1",
|
"interface": "eth1",
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
|
|
@ -347,6 +363,8 @@ func TestGatherIncludeInterfaces(t *testing.T) {
|
||||||
|
|
||||||
// Should not contain eth2
|
// Should not contain eth2
|
||||||
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
||||||
|
expectedFieldsEth2["interface_up_counter"] = expectedFieldsEth2["interface_up"]
|
||||||
|
expectedFieldsEth2["interface_up"] = false
|
||||||
expectedTagsEth2 := map[string]string{
|
expectedTagsEth2 := map[string]string{
|
||||||
"interface": "eth2",
|
"interface": "eth2",
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
|
|
@ -366,6 +384,8 @@ func TestGatherIgnoreInterfaces(t *testing.T) {
|
||||||
|
|
||||||
// Should not contain eth1
|
// Should not contain eth1
|
||||||
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
expectedFieldsEth1 := toStringMapInterface(interfaceMap["eth1"].Stat)
|
||||||
|
expectedFieldsEth1["interface_up_counter"] = expectedFieldsEth1["interface_up"]
|
||||||
|
expectedFieldsEth1["interface_up"] = true
|
||||||
expectedTagsEth1 := map[string]string{
|
expectedTagsEth1 := map[string]string{
|
||||||
"interface": "eth1",
|
"interface": "eth1",
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
|
|
@ -374,6 +394,8 @@ func TestGatherIgnoreInterfaces(t *testing.T) {
|
||||||
|
|
||||||
// Should contain eth2
|
// Should contain eth2
|
||||||
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
expectedFieldsEth2 := toStringMapInterface(interfaceMap["eth2"].Stat)
|
||||||
|
expectedFieldsEth2["interface_up_counter"] = expectedFieldsEth2["interface_up"]
|
||||||
|
expectedFieldsEth2["interface_up"] = false
|
||||||
expectedTagsEth2 := map[string]string{
|
expectedTagsEth2 := map[string]string{
|
||||||
"interface": "eth2",
|
"interface": "eth2",
|
||||||
"driver": "driver1",
|
"driver": "driver1",
|
||||||
|
|
@ -383,93 +405,111 @@ func TestGatherIgnoreInterfaces(t *testing.T) {
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
normalization []string
|
normalization []string
|
||||||
stats map[string]uint64
|
stats map[string]interface{}
|
||||||
expectedFields map[string]uint64
|
expectedFields map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalizedKeys(t *testing.T) {
|
func TestNormalizedKeys(t *testing.T) {
|
||||||
cases := []TestCase{
|
cases := []TestCase{
|
||||||
{
|
{
|
||||||
normalization: []string{"underscore"},
|
normalization: []string{"underscore"},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
"port rx": 1,
|
"port rx": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
},
|
||||||
expectedFields: map[string]uint64{
|
expectedFields: map[string]interface{}{
|
||||||
"port_rx": 1,
|
"port_rx": uint64(1),
|
||||||
"_Port_tx": 0,
|
"_Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
normalization: []string{"underscore", "lower"},
|
normalization: []string{"underscore", "lower"},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
"Port rx": 1,
|
"Port rx": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
},
|
||||||
expectedFields: map[string]uint64{
|
expectedFields: map[string]interface{}{
|
||||||
"port_rx": 1,
|
"port_rx": uint64(1),
|
||||||
"_port_tx": 0,
|
"_port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
normalization: []string{"underscore", "lower", "trim"},
|
normalization: []string{"underscore", "lower", "trim"},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
" Port RX ": 1,
|
" Port RX ": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
|
||||||
expectedFields: map[string]uint64{
|
|
||||||
"port_rx": 1,
|
|
||||||
"port_tx": 0,
|
|
||||||
"interface_up": 0,
|
|
||||||
},
|
},
|
||||||
|
expectedFields: map[string]interface{}{
|
||||||
|
"port_rx": uint64(1),
|
||||||
|
"port_tx": uint64(0),
|
||||||
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
normalization: []string{"underscore", "lower", "snakecase", "trim"},
|
normalization: []string{"underscore", "lower", "snakecase", "trim"},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
" Port RX ": 1,
|
" Port RX ": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
},
|
||||||
expectedFields: map[string]uint64{
|
expectedFields: map[string]interface{}{
|
||||||
"port_rx": 1,
|
"port_rx": uint64(1),
|
||||||
"port_tx": 0,
|
"port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
normalization: []string{"snakecase"},
|
normalization: []string{"snakecase"},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
" PortRX ": 1,
|
" PortRX ": uint64(1),
|
||||||
" PortTX": 0,
|
" PortTX": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
},
|
||||||
expectedFields: map[string]uint64{
|
expectedFields: map[string]interface{}{
|
||||||
"port_rx": 1,
|
"port_rx": uint64(1),
|
||||||
"port_tx": 0,
|
"port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
normalization: []string{},
|
normalization: []string{},
|
||||||
stats: map[string]uint64{
|
stats: map[string]interface{}{
|
||||||
" Port RX ": 1,
|
" Port RX ": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": uint64(0),
|
||||||
},
|
},
|
||||||
expectedFields: map[string]uint64{
|
expectedFields: map[string]interface{}{
|
||||||
" Port RX ": 1,
|
" Port RX ": uint64(1),
|
||||||
" Port_tx": 0,
|
" Port_tx": uint64(0),
|
||||||
"interface_up": 0,
|
"interface_up": true,
|
||||||
|
"interface_up_counter": uint64(0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
normalization: []string{},
|
||||||
|
stats: map[string]interface{}{
|
||||||
|
" Port RX ": uint64(1),
|
||||||
|
" Port_tx": uint64(0),
|
||||||
|
},
|
||||||
|
expectedFields: map[string]interface{}{
|
||||||
|
" Port RX ": uint64(1),
|
||||||
|
" Port_tx": uint64(0),
|
||||||
|
"interface_up": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
eth0 := &InterfaceMock{"eth0", "e1000e", c.stats, false, true}
|
eth0 := &InterfaceMock{"eth0", "e1000e", toStringMapUint(c.stats), false, true}
|
||||||
expectedTags := map[string]string{
|
expectedTags := map[string]string{
|
||||||
"interface": eth0.Name,
|
"interface": eth0.Name,
|
||||||
"driver": eth0.DriverName,
|
"driver": eth0.DriverName,
|
||||||
|
|
@ -492,7 +532,7 @@ func TestNormalizedKeys(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, acc.Metrics, 1)
|
require.Len(t, acc.Metrics, 1)
|
||||||
|
|
||||||
acc.AssertContainsFields(t, pluginName, toStringMapInterface(c.expectedFields))
|
acc.AssertContainsFields(t, pluginName, c.expectedFields)
|
||||||
acc.AssertContainsTaggedFields(t, pluginName, toStringMapInterface(c.expectedFields), expectedTags)
|
acc.AssertContainsTaggedFields(t, pluginName, c.expectedFields, expectedTags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue