fix(serializers.template): Unwrap metrics if required (#15740)

This commit is contained in:
Sebastian Rothbucher 2024-08-14 15:48:44 +02:00 committed by GitHub
parent fc198910cf
commit 371b9887fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -39,9 +39,13 @@ func (s *Serializer) Init() error {
} }
func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error) { func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error) {
m, ok := metric.(telegraf.TemplateMetric) metricPlain := metric
if wm, ok := metric.(telegraf.UnwrappableMetric); ok {
metricPlain = wm.Unwrap()
}
m, ok := metricPlain.(telegraf.TemplateMetric)
if !ok { if !ok {
s.Log.Errorf("metric of type %T is not a template metric", metric) s.Log.Errorf("metric of type %T is not a template metric", metricPlain)
return nil, nil return nil, nil
} }
var b bytes.Buffer var b bytes.Buffer