Fix using empty string as the namespace prefix in azure_monitor output plugin (#8282)
* Fix using empty string as the namespace prefix Fixes #8256 * Test using empty string as the namespace prefix
This commit is contained in:
parent
e3aa6eb577
commit
1696cca283
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/influxdata/telegraf/plugins/inputs/http_listener_v2"
|
||||
"github.com/influxdata/telegraf/plugins/inputs/memcached"
|
||||
"github.com/influxdata/telegraf/plugins/inputs/procstat"
|
||||
"github.com/influxdata/telegraf/plugins/outputs/azure_monitor"
|
||||
httpOut "github.com/influxdata/telegraf/plugins/outputs/http"
|
||||
"github.com/influxdata/telegraf/plugins/parsers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -257,3 +258,23 @@ func TestConfig_BadOrdering(t *testing.T) {
|
|||
require.Error(t, err, "bad ordering")
|
||||
assert.Equal(t, "Error loading config file ./testdata/non_slice_slice.toml: Error parsing http array, line 4: cannot unmarshal TOML array into string (need slice)", err.Error())
|
||||
}
|
||||
|
||||
func TestConfig_AzureMonitorNamespacePrefix(t *testing.T) {
|
||||
// #8256 Cannot use empty string as the namespace prefix
|
||||
c := NewConfig()
|
||||
defaultPrefixConfig := `[[outputs.azure_monitor]]`
|
||||
err := c.LoadConfigData([]byte(defaultPrefixConfig))
|
||||
assert.NoError(t, err)
|
||||
azureMonitor, ok := c.Outputs[0].Output.(*azure_monitor.AzureMonitor)
|
||||
assert.Equal(t, "Telegraf/", azureMonitor.NamespacePrefix)
|
||||
assert.Equal(t, true, ok)
|
||||
|
||||
c = NewConfig()
|
||||
customPrefixConfig := `[[outputs.azure_monitor]]
|
||||
namespace_prefix = ""`
|
||||
err = c.LoadConfigData([]byte(customPrefixConfig))
|
||||
assert.NoError(t, err)
|
||||
azureMonitor, ok = c.Outputs[0].Output.(*azure_monitor.AzureMonitor)
|
||||
assert.Equal(t, "", azureMonitor.NamespacePrefix)
|
||||
assert.Equal(t, true, ok)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,10 +155,6 @@ func (a *AzureMonitor) Connect() error {
|
|||
Timeout: a.Timeout.Duration,
|
||||
}
|
||||
|
||||
if a.NamespacePrefix == "" {
|
||||
a.NamespacePrefix = defaultNamespacePrefix
|
||||
}
|
||||
|
||||
var err error
|
||||
var region string
|
||||
var resourceID string
|
||||
|
|
@ -646,7 +642,8 @@ func (a *AzureMonitor) Reset() {
|
|||
func init() {
|
||||
outputs.Add("azure_monitor", func() telegraf.Output {
|
||||
return &AzureMonitor{
|
||||
timeFunc: time.Now,
|
||||
timeFunc: time.Now,
|
||||
NamespacePrefix: defaultNamespacePrefix,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue