Skip to content

Commit

Permalink
fix(faro/receiver): extra_log_labels with empty value now map to exis…
Browse files Browse the repository at this point in the history
…ting value in log line (#632)

Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber authored Apr 26, 2024
1 parent 148f6a3 commit 09da4b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Main (unreleased)

- In `mimir.rules.kubernetes`, fix an issue where unrecoverable errors from the Mimir API were retried. (@56quarters)

- Flow: Fix an issue where `faro.receiver`'s `extra_log_labels` with empty value don't
map existing value in log line. (@hainenber)

### Other changes

- Update `alloy-mixin` to use more specific alert group names (for example,
Expand Down
20 changes: 17 additions & 3 deletions internal/component/faro/receiver/exporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package receiver
import (
"context"
"errors"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -158,7 +159,7 @@ func (exp *logsExporter) sendKeyValsToLogsPipeline(ctx context.Context, kv *payl
}

ent := loki.Entry{
Labels: exp.labelSet(),
Labels: exp.labelSet(kv),
Entry: logproto.Entry{
Timestamp: time.Now(),
Line: string(line),
Expand All @@ -180,10 +181,23 @@ func (exp *logsExporter) sendKeyValsToLogsPipeline(ctx context.Context, kv *payl
return nil
}

func (exp *logsExporter) labelSet() model.LabelSet {
func (exp *logsExporter) labelSet(kv *payload.KeyVal) model.LabelSet {
exp.labelsMut.RLock()
defer exp.labelsMut.RUnlock()
return exp.labels

// Attach extra label to log lines
set := make(model.LabelSet, len(exp.labels))
for k, v := range exp.labels {
if len(v) > 0 {
set[k] = v
} else {
if val, ok := kv.Get(string(k)); ok {
set[k] = model.LabelValue(fmt.Sprint(val))
}
}
}

return set
}

func (exp *logsExporter) SetLabels(newLabels map[string]string) {
Expand Down
6 changes: 4 additions & 2 deletions internal/component/faro/receiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func Test(t *testing.T) {
go func() {
err := ctrl.Run(ctx, Arguments{
LogLabels: map[string]string{
"foo": "bar",
"foo": "bar",
"kind": "",
},

Server: ServerArguments{
Expand Down Expand Up @@ -100,7 +101,8 @@ func Test(t *testing.T) {

expect := loki.Entry{
Labels: model.LabelSet{
"foo": model.LabelValue("bar"),
"foo": model.LabelValue("bar"),
"kind": model.LabelValue("log"),
},
Entry: logproto.Entry{
Line: `timestamp="2021-01-01 00:00:00 +0000 UTC" kind=log message="hello, world" level=info context_env=dev traceID=0 spanID=0 browser_mobile=false`,
Expand Down

0 comments on commit 09da4b3

Please sign in to comment.