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

promtool: fix recording inconsistency due to duplicate labels #6026

Merged
merged 6 commits into from
Sep 20, 2019

Conversation

Harkishen-Singh
Copy link
Contributor

@Harkishen-Singh Harkishen-Singh commented Sep 15, 2019

Signed-off-by: Harkishen-Singh harkishensingh@hotmail.com

Refers #5529. It warns the user from inconsistent data which might occur if more than one labels in the same group are found.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
@Harkishen-Singh
Copy link
Contributor Author

@brian-brazil please have a look

Copy link
Contributor

@brian-brazil brian-brazil left a comment

Choose a reason for hiding this comment

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

This doesn't fix 5529.

@@ -303,9 +304,30 @@ func checkRules(filename string) (int, []error) {
numRules += len(rg.Rules)
}

duplicateLabels := checkDuplicateLabels(rgs.Groups)
if duplicateLabels != 0 {
fmt.Printf("%d duplicate label(s) found. Might cause inconsistency while recording expressions.\n", duplicateLabels)
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be more useful to print the relevant labels. You should also check the metric name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will implement it in the following commit.

@Harkishen-Singh
Copy link
Contributor Author

@brian-brazil implemented the suggestions! please have a look.

var stackLabels []map[string]string
var stackMetrics []string
for _, props := range rule.Rules {
for _, labels := range stackLabels {
Copy link
Contributor

Choose a reason for hiding this comment

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

A map would be more efficient, and easier to understant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

}
stackLabels = append(stackLabels, props.Labels)

for _, mname := range stackMetrics {
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to check the metric names and labels at the same time, not independently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
@Harkishen-Singh
Copy link
Contributor Author

@brian-brazil done! please have a look.

stackDuplicates = append(stackDuplicates, duplicateRules{metric: props.Record, label: props.Labels})
}
}
stack = append(stack, duplicateRules{metric: props.Record, label: props.Labels})
Copy link
Contributor

Choose a reason for hiding this comment

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

Building this up is odd, I'd suggest using an index variable in the for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Copy link
Contributor

Choose a reason for hiding this comment

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

More exactly, get rid of the stack - you don't need it. Nested iteration over the rules will do it.

Copy link
Contributor Author

@Harkishen-Singh Harkishen-Singh Sep 19, 2019

Choose a reason for hiding this comment

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

@brian-brazil, done! please have a look.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
@Harkishen-Singh
Copy link
Contributor Author

@brian-brazil, implemented index values in the necessary for loops. Please have a look.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
@Harkishen-Singh
Copy link
Contributor Author

@brian-brazil , as suggested, I have removed the stack array and implemented the mechanism via nesting of rules! please review.

@brian-brazil brian-brazil merged commit e097c70 into prometheus:master Sep 20, 2019
@brian-brazil
Copy link
Contributor

Thanks!

@krasi-georgiev krasi-georgiev changed the title fix recording inconsistency due to duplicate labels promtool: fix recording inconsistency due to duplicate labels Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants