-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,9 +243,10 @@ public void validateLabelExpression(Action.DynamicLabel dynamicLabel) { | |
.getTokenExtractionRulesList() | ||
.forEach( | ||
tokenExtractionRule -> { | ||
validKeys.add(tokenExtractionRule.getKey()); | ||
if (tokenExtractionRule.hasAlias()) { | ||
validKeys.add(tokenExtractionRule.getAlias()); | ||
} else { | ||
validKeys.add(tokenExtractionRule.getKey()); | ||
} | ||
}); | ||
Pattern pattern = Pattern.compile("\\{(\\\\}|[^}])*}"); | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh, okay |
||
} | ||
} | ||
|
||
private void throwInvalidArgumentException(String description) { | ||
|
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.