Skip to content

Commit

Permalink
Allow filename as source to add custom label from __path__
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed Sep 18, 2019
1 parent 4763785 commit f8f8bff
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pkg/logentry/stages/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f8f8bff

Please sign in to comment.