From f8f8bff5dbb3d549f7e0c9ddfeacc04aea7e958c Mon Sep 17 00:00:00 2001 From: Aditya C S Date: Fri, 13 Sep 2019 16:26:54 +0530 Subject: [PATCH] Allow filename as source to add custom label from __path__ --- pkg/logentry/stages/regex.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/logentry/stages/regex.go b/pkg/logentry/stages/regex.go index 6b9b0dfc8c447..80e6ed8e8cb50 100644 --- a/pkg/logentry/stages/regex.go +++ b/pkg/logentry/stages/regex.go @@ -89,22 +89,30 @@ func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interfa input := entry if r.cfg.Source != nil { - if _, ok := extracted[*r.cfg.Source]; !ok { - if Debug { - level.Debug(r.logger).Log("msg", "source does not exist in the set of extracted values", "source", *r.cfg.Source) + if _, ok := extracted[*r.cfg.Source]; ok { + value, err := getString(extracted[*r.cfg.Source]) + if err != nil { + if Debug { + level.Debug(r.logger).Log("msg", "failed to convert source value to string", "source", *r.cfg.Source, "err", err, "type", reflect.TypeOf(extracted[*r.cfg.Source]).String()) + } + return } - return - } - - value, err := getString(extracted[*r.cfg.Source]) - if err != nil { + input = &value + } else if _, ok := labels[model.LabelName(*r.cfg.Source)]; ok { + value, err := getString(labels[model.LabelName(*r.cfg.Source)]) + if err != nil { + if Debug { + level.Debug(r.logger).Log("msg", "failed to convert source value to string", "source", *r.cfg.Source, "err", err, "type", reflect.TypeOf(extracted[*r.cfg.Source]).String()) + } + return + } + input = &value + } else { if Debug { - level.Debug(r.logger).Log("msg", "failed to convert source value to string", "source", *r.cfg.Source, "err", err, "type", reflect.TypeOf(extracted[*r.cfg.Source]).String()) + level.Debug(r.logger).Log("msg", "source does not exist in the set of extracted values", "source", *r.cfg.Source) } return } - - input = &value } if input == nil {