feat(common.shim): Enable metric tracking within external plugins (#15636)

This commit is contained in:
Ottmar Friedrich von Wimmelwaldi 2024-08-06 08:11:29 +02:00 committed by GitHub
parent d160276552
commit fbac735052
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -87,6 +87,9 @@ Metric Tracking provides a system to be notified when metrics have been
successfully written to their outputs or otherwise discarded. This allows
inputs to be created that function as reliable queue consumers.
Please note that this process applies only to internal plugins. For external
plugins, the metrics are acknowledged regardless of the actual output.
To get started with metric tracking begin by calling `WithTracking` on the
[telegraf.Accumulator][]. Add metrics using the `AddTrackingMetricGroup`
function on the returned [telegraf.TrackingAccumulator][] and store the

View File

@ -34,6 +34,9 @@ before telling the metric source that the message was read. If Telegraf were to
stop or the system running Telegraf to crash, this allows the messages that
were not completely delivered to an output to get re-read at a later date.
Please note that this process applies only to internal plugins. For external
plugins, the metrics are acknowledged regardless of the actual output.
### Undelivered Messages
When an input uses tracking metrics, an additional setting,

View File

@ -115,13 +115,16 @@ func (s *Shim) writeProcessedMetrics() error {
}
b, err := serializer.Serialize(m)
if err != nil {
m.Reject()
return fmt.Errorf("failed to serialize metric: %w", err)
}
// Write this to stdout
_, err = fmt.Fprint(s.stdout, string(b))
if err != nil {
m.Drop()
return fmt.Errorf("failed to write metric: %w", err)
}
m.Accept()
}
}
}