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

Feature request for Loki sink: Use event values as labels #185

Open
bbreijer opened this issue May 28, 2024 · 2 comments
Open

Feature request for Loki sink: Use event values as labels #185

bbreijer opened this issue May 28, 2024 · 2 comments

Comments

@bbreijer
Copy link

currently it is only possible to use event values (like namespace) in the layout of a Loki body, it would be very nice to be able to use the event data (link kind, namespace, etc.) in the streamLabels.

I am not familiar with Go, nor do i know how to test this, therefore i did not make a PR.

But looking at the code:
Might this be the addition we are looking for?

In pkg/sinks/loki.go, change:

	eventBody, err := serializeEventWithLayout(l.cfg.Layout, ev)
	if err != nil {
		return err
	}
	timestamp := generateTimestamp()
	a := LokiMsg{
		Streams: []promtailStream{{
			Stream: l.cfg.StreamLabels,
			Values: [][]string{{timestamp, string(eventBody)}},
		}},
	}

into

	eventBody, err := serializeEventWithLayout(l.cfg.Layout, ev)
	if err != nil {
		return err
	}
	streamLabels, err := serializeEventWithLayout(l.cfg.StreamLabels, ev)
	if err != nil {
		return err
	}
	timestamp := generateTimestamp()
	a := LokiMsg{
		Streams: []promtailStream{{
			Stream: string(streamLabels),
			Values: [][]string{{timestamp, string(eventBody)}},
		}},
	}

Could you consider this improvement?

@mi-fabien-cayre
Copy link

Would be useful for sure

@mi-fabien-cayre
Copy link

Wrote a PR including some tests (I also need this feature to be added)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants