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

Allow filtering metrics using labels #77

Merged
merged 5 commits into from
Jun 20, 2018

Conversation

pierresouchay
Copy link
Contributor

@pierresouchay pierresouchay commented May 2, 2018

This will allow for a more elegant solution to
hashicorp/consul#4042

TODO:

  • Add unit tests

This will allow for a more elegant solution to
hashicorp/consul#4042
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

This looks great to me!

I have a couple of super nitpicky -comment only change requests but i think they are important enough to warrant actually requesting the change 😄 .

I'd like someone else familiar with the code base to review too. I'll try to get that organised 🔜 .

metrics.go Outdated
@@ -146,20 +172,54 @@ func (m *Metrics) UpdateFilter(allow, block []string) {
}
}

// labelIsAllowed return true if a label has to be included
Copy link
Member

Choose a reason for hiding this comment

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

nitpick "should be included" rather than "has to be included" seems to describe the intention better.

Also, can we document that this must only be called internally by a method that holds m.filterLock in at least Read mode? It is as far as I can see now but it's good to document preconditions like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE in next patch

metrics.go Outdated
}

// filterLabels return only allowed labels
func (m *Metrics) filterLabels(labels []Label) []Label {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about requiring caller holds lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE in next patch

start.go Outdated
filter *iradix.Tree
allowedLabels map[string]int
blockedLabels map[string]int
filterLock sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I'd comment that all of filter, allowedLabels, blockedLabels are protected by filterLock as that's not implied by the name (no need to rename IMO just worth clarifying).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE in next patch

@pierresouchay
Copy link
Contributor Author

@banks Suggestion to go forward with thoses patches ?

Kind Regards

@banks
Copy link
Member

banks commented May 24, 2018

I think @kyhavlov had some suggestions he was going to make here.

We’ve had a busy couple of weeks but I’ll ping him today to take a look.

@pierresouchay
Copy link
Contributor Author

Hello @kyhavlov, @banks ,

Could someone have a look, so I can continue on hashicorp/consul#4042 ?

Kind regards

@iksaif
Copy link

iksaif commented Jun 4, 2018

Looks good to me 👍

@kyhavlov
Copy link
Contributor

kyhavlov commented Jun 4, 2018

Hey @pierresouchay sorry for the delayed response. I think the idea behind this seems sound, but it feels weird to be blocking labels globally by name without it being attached to series name at all. Do you think it makes sense to make the label filters specific to a given series name for more fine-grained blocking?

@pierresouchay
Copy link
Contributor Author

@kyhavlov Well for our use-case (aka adding labels in Consul everywhere), it will be more pain than ease, on a API point of view, it make more sense.

What would you like me to do ?

  • Regex based ? (In that case, it probably means that all calls with pay the price for matching regex)
  • prefix ? (I that case the patch will be quite invasive since I will have to change all radix based structures)

Tell me what you want in that case.

Kind regards

Copy link
Contributor

@kyhavlov kyhavlov left a comment

Choose a reason for hiding this comment

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

I talked about this a little more with @banks and we agreed it should be ok to merge as-is so long as we document the feature as a "global label filter" and make sure its function is clear. I had a couple really minor comments, and other than that it looks good 👍

start.go Outdated
@@ -23,17 +23,21 @@ type Config struct {

AllowedPrefixes []string // A list of metric prefixes to allow, with '.' as the separator
BlockedPrefixes []string // A list of metric prefixes to block, with '.' as the separator
AllowedLabels []string // A list of metric labels to allow, with '.' as the separator
BlockedLabels []string // A list of metric prefixes to block, with '.' as the separator
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be A list of metric labels...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

start.go Outdated
lastNumGC uint32
sink MetricSink
filter *iradix.Tree
allowedLabels map[string]int
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nitpick, but this could be map[string]bool or map[string]struct{} when it's just being used as a set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

@pierresouchay
Copy link
Contributor Author

@kyhavlov Thank you for the review, PR updated with requested fixes

@pierresouchay
Copy link
Contributor Author

Hello @kyhavlov @banks ,

I made the fixes, would you consider merging it so I can go forward on hashicorp/consul#4042 ?

Thanks a lot

Kind regards

Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

Sorry @pierresouchay for the death march this turned into.

I think I now have access to merge this, but just noted that the suggestion for documenting the globalness of label filtering wasn't done yet. I think this is a reasonable trade off for not actually implementing something more complex for now.

I don't think there are any actual docs other than Godoc to update so just the comment on the method.

Thanks for persevering here!

m.UpdateFilterAndLabels(allow, block, m.AllowedLabels, m.BlockedLabels)
}

// UpdateFilterAndLabels overwrites the existing filter with the given rules.
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this doc comment explicit what the behaviour of label filter is? i.g. apply globally to all metrics and apply orthogonally to the allow/block prefixes. I'd also include the use-case for them (globally configuring whether potentially high-cardinality metrics are included) to make it obvious why they work like this.

I think that satisfied the last point Kyle mentioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@banks DONE: I added more text in README.md as well

Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

Awesome!

@banks banks merged commit 58588f4 into hashicorp:master Jun 20, 2018
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.

4 participants