Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(faro/receiver): extra_log_labels with empty value now map to existing value in log line #632

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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
Loading