fix(inputs.mqtt_consumer): Print warning on no metrics generated (#13574)
This commit is contained in:
parent
c28df89c8e
commit
908c6a551f
|
|
@ -24,6 +24,8 @@ import (
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// 30 Seconds is the default used by paho.mqtt.golang
|
// 30 Seconds is the default used by paho.mqtt.golang
|
||||||
defaultConnectionTimeout = config.Duration(30 * time.Second)
|
defaultConnectionTimeout = config.Duration(30 * time.Second)
|
||||||
|
|
@ -262,6 +264,13 @@ func (m *MQTTConsumer) onMessage(_ mqtt.Client, msg mqtt.Message) {
|
||||||
|
|
||||||
metrics, err := m.parser.Parse(msg.Payload())
|
metrics, err := m.parser.Parse(msg.Payload())
|
||||||
if err != nil || len(metrics) == 0 {
|
if err != nil || len(metrics) == 0 {
|
||||||
|
if len(metrics) == 0 {
|
||||||
|
once.Do(func() {
|
||||||
|
const msg = "No metrics were created from a message. Verify your parser settings. This message is only printed once."
|
||||||
|
m.Log.Debug(msg)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if m.PersistentSession {
|
if m.PersistentSession {
|
||||||
msg.Ack()
|
msg.Ack()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue