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

Add external labels support #43

Merged
merged 1 commit into from
Dec 10, 2018
Merged

Add external labels support #43

merged 1 commit into from
Dec 10, 2018

Conversation

gouthamve
Copy link
Member

Just to trigger build

@gouthamve
Copy link
Member Author

Well, it seems to work xD

@@ -100,6 +105,11 @@ func (c *Client) run() {
case <-c.quit:
return
case e := <-c.entries:
// Add any external labels if they exist.
if len(c.externalLabels) > 0 {
e.labels = e.labels.Merge(c.externalLabels)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the external labels override the current labels if any overlap. What should be semantics here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gouthamve gouthamve changed the title WIP: Add external labels support Add external labels support Dec 6, 2018
@gouthamve gouthamve requested a review from tomwilkie December 6, 2018 11:46
if _, ok := e.labels[ln]; !ok {
e.labels[ln] = lv
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're mutating a map you don't own here. Its probably safe, but better to use the addLabelsMiddleware: https://github.com/grafana/loki/blob/master/pkg/promtail/types.go#L35

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially used labels.Merge but that would mean allocating a new map every single time. Not sure we want that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, the semantics don't match. In Prometheus, if one of the labelsnames in external labels is already present, it is not overwritten...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want that?

For now performance isn't our main concern, correctness is.

Further, the semantics don't match.

Lets fix that in the middleware then.

@gouthamve gouthamve force-pushed the promtail-ext-lbl branch 3 times, most recently from d881fd0 to ec009f3 Compare December 7, 2018 13:44
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
@@ -168,6 +173,10 @@ func (c *Client) Stop() {

// Handle implement EntryHandler; adds a new line to the next batch; send is async.
func (c *Client) Handle(ls model.LabelSet, t time.Time, s string) error {
if len(c.externalLabels) > 0 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in the client and did not make it a middleware because it is the client's job to add the external-labels (as we put external labels in the client config). I think it makes sense to keep it here, rather than wrap in the next layer.

@tomwilkie tomwilkie merged commit f2de97c into master Dec 10, 2018
@tomwilkie tomwilkie deleted the promtail-ext-lbl branch December 10, 2018 17:05
periklis added a commit to periklis/loki that referenced this pull request Dec 6, 2021
periklis added a commit to periklis/loki that referenced this pull request Sep 16, 2022
Update from upstream repository
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

Successfully merging this pull request may close these issues.

2 participants