fix(inputs.mqtt_consumer): Print warning on no metrics generated (#13574)

This commit is contained in:
Joshua Powers 2023-07-10 06:02:42 -06:00 committed by GitHub
parent c28df89c8e
commit 908c6a551f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,8 @@ import (
//go:embed sample.conf
var sampleConfig string
var once sync.Once
var (
// 30 Seconds is the default used by paho.mqtt.golang
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())
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 {
msg.Ack()
}