Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/inputs/mqtt_consumer/mqtt_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand Down