mapper: Make sure we have a logger before backtracking check

The FSM backtracking detection issues a log line. Make sure there is a
non-nil logger before doing that.

Avoids the crash in prometheus/graphite_exporter#197.

Signed-off-by: Matthias Rampke <matthias@prometheus.io>
This commit is contained in:
Matthias Rampke 2022-07-29 11:46:57 +00:00
parent c2505cf91e
commit bc43c5606d
No known key found for this signature in database
GPG key ID: F9AFF7F67ACE10BA

View file

@ -233,6 +233,10 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.Logger == nil {
m.Logger = log.NewNopLogger()
}
m.Defaults = n.Defaults
m.Mappings = n.Mappings
@ -259,10 +263,6 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
m.MappingsCount.Set(float64(len(n.Mappings)))
}
if m.Logger == nil {
m.Logger = log.NewNopLogger()
}
return nil
}