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 a limits config option to allow for dropping of the cluster label #1726

Merged
merged 5 commits into from
Dec 3, 2019
Merged

Add a limits config option to allow for dropping of the cluster label #1726

merged 5 commits into from
Dec 3, 2019

Conversation

cstyan
Copy link
Contributor

@cstyan cstyan commented Oct 9, 2019

Fixes #1724

Adds an optional flag per user to drop the cluster label, in addition to dropping the replica label, when ingesting HA samples. Should only be used if that user has their own set of more than two labels that they use to uniquely identify Prometheus replicas.

There's a bit of a refactor here as well:

  • I noticed that in the config the ordering of the values was cluster label then replica label, but in RegisterFlags the order is replica then cluster. I moved them around in RegisterFlags to match the order in the struct.
  • distributor.Push was getting pretty long, I moved the internals of the validation loop into a function validateSeries. This also had the side effect of making that portion of the code testable. I've only added tests for the label removal bits. I assume the actual validation functions ValidateLabels and ValidateSamples are tested already.
  • renamed removeReplicaLabel -> removeLabel, it wasn't doing anything replica label specific anyways

Signed-off-by: Callum Styan callumstyan@gmail.com
cc @tomwilkie @gouthamve

@bboreham
Copy link
Contributor

I find it easier to review PRs like this when you split the pure-refactoring part from the behaviour-changing part, into separate commits. Otherwise I have to figure out your intention on every line and that takes longer.

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

I believe the code works, but I found it confusing. Probably I don't understand the overall design.

Given that "ha-tracker.drop-cluster-label" doesn't seem to be tied to HA, could the feature be done as a general label-removal mechanism? This would give us a portion of #771.

@@ -144,11 +144,13 @@ prefix these flags with `distributor.ha-tracker.`

### HA Tracker

HA tracking has two of it's own flags:
HA tracking has three of it's own flags:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
HA tracking has three of it's own flags:
HA tracking has three of its own flags:

pkg/distributor/distributor.go Outdated Show resolved Hide resolved
pkg/util/validation/limits.go Outdated Show resolved Hide resolved
// Remove the replica label from a slice of LabelPairs if it exists.
func removeReplicaLabel(replica string, labels *[]client.LabelAdapter) {
// Remove the label labelname from a slice of LabelPairs if it exists.
func removeLabel(labelName string, labels *[]client.LabelAdapter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is very similar to labelPairs.removeBlanks(), so they could be merged.
This one preserves order, which I don't think is necessary.
It might be a good idea to comment why this code does it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have a look at the labelsPairs function in the morning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

labelPairs is nested within the ingester package. If we're going to merge the two functions should that exist in a new package under util?

And the reason for preserving order is only that I've generally seen that be the case within Prometheus itself. For example within remote write, when processing a sample through external labelse and relabel rules, we preserve the sorted order of the labels.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
testability.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
in Distributor.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
@cstyan
Copy link
Contributor Author

cstyan commented Oct 18, 2019

@bboreham thanks for the review! I've split out the refactoring into another commit. I also changed the validateSeries function to no longer require the error pointer argument in addition to returning an error.

@bboreham
Copy link
Contributor

Given that it isn't tied to HA, could the feature be done as a general label-removal mechanism? This would give us a portion of #771.

@cstyan
Copy link
Contributor Author

cstyan commented Oct 18, 2019

I moved the cluster label dropping inside the check for removeReplica, which is tied to HA. I can move that back out and turn the label removal into a more general non-HA dependent thing, maybe in another PR? if you'd like.

@bboreham
Copy link
Contributor

Given that it doesn't cost me anything, yes I would prefer a generic "for tenant X, everywhere you see label Y, drop it".

@nbellowe
Copy link

@cstyan Any updates with this PR? Its much appreciated, we're waiting on this to enable HA writing to cortex.

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

getting close

docs/arguments.md Outdated Show resolved Hide resolved
pkg/util/validation/limits.go Show resolved Hide resolved
specific.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -280,6 +281,48 @@ func (d *Distributor) checkSample(ctx context.Context, userID, cluster, replica
return true, nil
}

// Validates a single series from a write request. Will remove HA labels if necessary.
// Takes a pointer for a partial error so that we can get partial errors, errors during validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the comment to remove the reference to the pointer?

// HAClusterLabel returns the cluster label to look for when deciding whether to accept a sample from a Prometheus HA replica.
func (o *Overrides) HAClusterLabel(userID string) string {
return o.overridesManager.GetLimits(userID).(*Limits).HAClusterLabel
// DropLabels returns whether the cluster label should be dropped when ingesting HA samples for the user.
Copy link
Contributor

Choose a reason for hiding this comment

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

Returns the list of labels to be dropped?

if removeReplica {
removeLabel(d.limits.HAReplicaLabel(userID), &ts.Labels)
}
for _, s := range d.limits.DropLabels(userID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

s is a weird variable name in this instance, maybe call it label/labelName?

pkg/distributor/distributor.go Show resolved Hide resolved
empty labels after dropping labels

Signed-off-by: Callum Styan <callumstyan@gmail.com>
@gouthamve gouthamve merged commit 08ddf88 into cortexproject:master Dec 3, 2019
@nbellowe
Copy link

nbellowe commented Dec 5, 2019

Thank you @cstyan!

bboreham added a commit that referenced this pull request Dec 5, 2019
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.

Add ability to drop cluster label after dedupe
4 participants