Skip to content

Commit

Permalink
chore: minor changes to dynamic label part of label application rule
Browse files Browse the repository at this point in the history
  • Loading branch information
saxenakshitiz committed Jun 11, 2024
1 parent 3697588 commit cbaf8be
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
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
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:
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(
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

0 comments on commit cbaf8be

Please sign in to comment.