-
Notifications
You must be signed in to change notification settings - Fork 5
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
chore: add regex capture to label application rule #214
Conversation
if (tokenExtractionRule.hasAlias()) { | ||
validKeys.add(tokenExtractionRule.getAlias()); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintentional change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. If alias is provided then alias should be used not key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So, till now we were validating key in case of alias as well, even though it wasn't getting used later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier both alias and key were being used. I will change to use alias if alias is provided.
Please note this expression is not exposed in UI so far, so no one should be using it.
if (tokenExtractionRule.hasAlias()) { | ||
validKeys.add(tokenExtractionRule.getAlias()); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So, till now we were validating key in case of alias as well, even though it wasn't getting used later?
@@ -264,6 +266,15 @@ public void validateLabelExpression(Action.DynamicLabel dynamicLabel) { | |||
private void validateTokenExtractionRule( | |||
Action.DynamicLabel.TokenExtractionRule tokenExtractionRule) { | |||
validateNonDefaultPresenceOrThrow(tokenExtractionRule, tokenExtractionRule.KEY_FIELD_NUMBER); | |||
if (tokenExtractionRule.hasRegexCapture()) { | |||
try { | |||
Pattern.compile(tokenExtractionRule.getRegexCapture()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have a validator somewhere that validates a number of capture groups - and we should be using re2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh we are :) I forget they use identical names to make it drop in. Anyway, RegexValidator.validateCaptureGroupCount
is what I was referring to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -264,6 +265,9 @@ public void validateLabelExpression(Action.DynamicLabel dynamicLabel) { | |||
private void validateTokenExtractionRule( | |||
Action.DynamicLabel.TokenExtractionRule tokenExtractionRule) { | |||
validateNonDefaultPresenceOrThrow(tokenExtractionRule, tokenExtractionRule.KEY_FIELD_NUMBER); | |||
if (tokenExtractionRule.hasRegexCapture()) { | |||
RegexValidator.validateCaptureGroupCount(tokenExtractionRule.getRegexCapture(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we restricting only to one capture group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need a single value, we can use value only from one group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was thinking of allowing users to use the values of each group accordingly if they want to like we have in Naming rules. for example: if the attribute value like: domain.sub-domain1.sub-domain2
and we want to extract: domain:sub-domain2
for label, then we need to support multiple capture groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd create create two rules with one capture group each.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that would lead to two different labels, right? If we want both of of them in a single label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - a dynamic label defines tokens and an expression that indicates how to combine them - this PR is adding a new way to extract a token:
message DynamicLabel {
string label_expression = 1; // expression to combine tokens to generate label, example "${deployment}_${version}"
repeated TokenExtractionRule token_extraction_rules = 2;
message TokenExtractionRule {
string key = 1;
optional string json_path = 2;
optional string alias = 3;
optional string regex_capture = 4;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay
Defined regex capture to perform operation on attribute value like substring etc.