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

chore: minor changes to dynamic label part of label application rule #234

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface Action {
String OPERATION_KEY = "operation";
String STATIC_LABELS = "staticLabels";
String DYNAMIC_LABEL_KEY_KEY = "dynamicLabelKey";
String DYNAMIC_LABEL_EXPRESSION_KEY = "dynamicLabelExpression";
String DYNAMIC_LABEL_KEY = "dynamicLabel";
String ACTION_TYPE_KEY = "type";

@GraphQLName(Operation.TYPE_NAME)
Expand Down Expand Up @@ -53,8 +53,8 @@ enum ActionType {

@GraphQLField
@Nullable
@GraphQLName(DYNAMIC_LABEL_EXPRESSION_KEY)
DynamicLabelExpression dynamicLabelExpression();
@GraphQLName(DYNAMIC_LABEL_KEY)
DynamicLabel dynamicLabel();

@GraphQLField
@GraphQLNonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import graphql.annotations.annotationTypes.GraphQLNonNull;
import java.util.List;

@GraphQLName(DynamicLabelExpression.TYPE_NAME)
public interface DynamicLabelExpression {
String TYPE_NAME = "DynamicLabelExpression";
@GraphQLName(DynamicLabel.TYPE_NAME)
public interface DynamicLabel {
String TYPE_NAME = "DynamicLabel";

String LABEL_EXPRESSION_KEY = "labelExpression";
String EXPRESSION_KEY = "expression";
String TOKEN_EXTRACTION_RULES_KEY = "tokenExtractionRules";

@GraphQLField
@GraphQLName(LABEL_EXPRESSION_KEY)
@GraphQLName(EXPRESSION_KEY)
@GraphQLNonNull
Copy link
Contributor

Choose a reason for hiding this comment

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

All new fields should include @GraphQlDescription - these relatively convoluted APIs would be a great spot for them too, since we can include an example of the type of syntax expected here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

String labelExpression();
String expression();

@GraphQLField
@GraphQLNonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ private Action convertLabelAction(org.hypertrace.graphql.label.schema.rule.Actio
return actionBuilder
.setDynamicLabelExpression(
Action.DynamicLabel.newBuilder()
.setLabelExpression(action.dynamicLabelExpression().labelExpression())
.setLabelExpression(action.dynamicLabel().expression())
.addAllTokenExtractionRules(
convertTokenExtractionRules(
action.dynamicLabelExpression().tokenExtractionRules())))
convertTokenExtractionRules(action.dynamicLabel().tokenExtractionRules())))
.build();
default:
throw new IllegalArgumentException("Unsupported action value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.extern.slf4j.Slf4j;
import org.hypertrace.graphql.label.schema.rule.Action;
import org.hypertrace.graphql.label.schema.rule.Condition;
import org.hypertrace.graphql.label.schema.rule.DynamicLabelExpression;
import org.hypertrace.graphql.label.schema.rule.DynamicLabel;
import org.hypertrace.graphql.label.schema.rule.LabelApplicationRule;
import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleData;
import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleResultSet;
Expand Down Expand Up @@ -119,7 +119,7 @@ private Optional<Action> convertAction(
null,
Action.ActionType.DYNAMIC_LABEL_KEY));
case DYNAMIC_LABEL_EXPRESSION:
aaron-steinfeld marked this conversation as resolved.
Show resolved Hide resolved
DynamicLabelExpression dynamicLabelExpression =
DynamicLabel dynamicLabel =
convertDynamicLabelExpression(action.getDynamicLabelExpression());
return operation.map(
op ->
Expand All @@ -128,7 +128,7 @@ private Optional<Action> convertAction(
op,
null,
null,
dynamicLabelExpression,
dynamicLabel,
Action.ActionType.DYNAMIC_LABEL_EXPRESSION));
default:
log.error("Unrecognized Value type in Action {}", action.getValueCase().name());
Expand All @@ -143,11 +143,11 @@ private StaticLabels convertStaticLabels(
return new ConvertedStaticLabels(staticLabels.getIdsList());
}

private DynamicLabelExpression convertDynamicLabelExpression(
private DynamicLabel convertDynamicLabelExpression(
saxenakshitiz marked this conversation as resolved.
Show resolved Hide resolved
org.hypertrace.label.application.rule.config.service.v1.LabelApplicationRuleData.Action
.DynamicLabel
dynamicLabel) {
return new ConvertedDynamicLabelExpression(
return new ConvertedDynamicLabel(
dynamicLabel.getLabelExpression(),
convertTokenExtractionRules(dynamicLabel.getTokenExtractionRulesList()));
}
Expand Down Expand Up @@ -339,7 +339,7 @@ private static class ConvertedAction implements Action {
Operation operation;
StaticLabels staticLabels;
String dynamicLabelKey;
DynamicLabelExpression dynamicLabelExpression;
DynamicLabel dynamicLabel;
ActionType type;
}

Expand All @@ -351,8 +351,8 @@ private static class ConvertedStaticLabels implements StaticLabels {

@Value
@Accessors(fluent = true)
private static class ConvertedDynamicLabelExpression implements DynamicLabelExpression {
String labelExpression;
private static class ConvertedDynamicLabel implements DynamicLabel {
String expression;
List<TokenExtractionRule> tokenExtractionRules;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.hypertrace.core.graphql.deserialization.ArgumentDeserializationConfig;
import org.hypertrace.graphql.label.schema.rule.Action;
import org.hypertrace.graphql.label.schema.rule.Condition;
import org.hypertrace.graphql.label.schema.rule.DynamicLabelExpression;
import org.hypertrace.graphql.label.schema.rule.DynamicLabel;
import org.hypertrace.graphql.label.schema.rule.LabelApplicationRule;
import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleData;
import org.hypertrace.graphql.label.schema.rule.LeafCondition;
Expand Down Expand Up @@ -40,8 +40,7 @@ public List<Module> jacksonModules() {
LabelApplicationRuleData.class, LabelApplicationRuleDataArgument.class)
.addAbstractTypeMapping(Action.class, ActionArgument.class)
.addAbstractTypeMapping(StaticLabels.class, StaticLabelsArgument.class)
.addAbstractTypeMapping(
DynamicLabelExpression.class, DynamicLabelExpressionArgument.class)
.addAbstractTypeMapping(DynamicLabel.class, DynamicLabelArgument.class)
.addAbstractTypeMapping(TokenExtractionRule.class, TokenExtractionRuleArgument.class)
.addAbstractTypeMapping(Condition.class, ConditionArgument.class)
.addAbstractTypeMapping(LeafCondition.class, LeafConditionArgument.class)
Expand Down Expand Up @@ -97,8 +96,8 @@ private static class ActionArgument implements Action {
@JsonProperty(DYNAMIC_LABEL_KEY_KEY)
String dynamicLabelKey;

@JsonProperty(DYNAMIC_LABEL_EXPRESSION_KEY)
DynamicLabelExpression dynamicLabelExpression;
@JsonProperty(DYNAMIC_LABEL_KEY)
DynamicLabel dynamicLabel;

@JsonProperty(ACTION_TYPE_KEY)
ActionType type;
Expand All @@ -115,9 +114,9 @@ private static class StaticLabelsArgument implements StaticLabels {
@Value
@Accessors(fluent = true)
@NoArgsConstructor(force = true)
private static class DynamicLabelExpressionArgument implements DynamicLabelExpression {
@JsonProperty(LABEL_EXPRESSION_KEY)
String labelExpression;
private static class DynamicLabelArgument implements DynamicLabel {
@JsonProperty(EXPRESSION_KEY)
String expression;

@JsonProperty(TOKEN_EXTRACTION_RULES_KEY)
List<TokenExtractionRule> tokenExtractionRules;
Expand Down
Loading