From 908c6a551f47a132ebb4cc1a0561914c71b13fca Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Mon, 10 Jul 2023 06:02:42 -0600 Subject: [PATCH] fix(inputs.mqtt_consumer): Print warning on no metrics generated (#13574) --- plugins/inputs/mqtt_consumer/mqtt_consumer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/inputs/mqtt_consumer/mqtt_consumer.go b/plugins/inputs/mqtt_consumer/mqtt_consumer.go index 059913542..76c304040 100644 --- a/plugins/inputs/mqtt_consumer/mqtt_consumer.go +++ b/plugins/inputs/mqtt_consumer/mqtt_consumer.go @@ -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() }