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 authored Jun 12, 2024
1 parent 3697588 commit 3b9a335
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hypertrace.graphql.label.schema.rule;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
Expand All @@ -14,7 +15,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 All @@ -27,7 +28,7 @@ enum Operation {
enum ActionType {
STATIC_LABELS,
DYNAMIC_LABEL_KEY,
DYNAMIC_LABEL_EXPRESSION;
DYNAMIC_LABEL;
private static final String TYPE_NAME = "LabelApplicationActionType";
}

Expand All @@ -52,9 +53,10 @@ enum ActionType {
String dynamicLabelKey();

@GraphQLField
@GraphQLDescription("Definition to generate dynamic labels")
@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
@@ -0,0 +1,29 @@
package org.hypertrace.graphql.label.schema.rule;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
import java.util.List;

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

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

@GraphQLField
@GraphQLDescription(
"Expression definition to generate dynamic labels. Ex: \"${token1}_${token2}\"")
@GraphQLName(EXPRESSION_KEY)
@GraphQLNonNull
String expression();

@GraphQLField
@GraphQLDescription(
"Rules to extract token from attribute values. These values will replace tokens in the expression.")
@GraphQLNonNull
@GraphQLName(TOKEN_EXTRACTION_RULES_KEY)
List<TokenExtractionRule> tokenExtractionRules();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hypertrace.graphql.label.schema.rule;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
Expand All @@ -14,16 +15,20 @@ public interface TokenExtractionRule {
String REGEX_CAPTURE_KEY = "regexCapture";

@GraphQLField
@GraphQLDescription("The attribute key to be used to get value")
@GraphQLName(KEY_NAME)
@GraphQLNonNull
String key();

@GraphQLField
@GraphQLDescription("Optionally define and use alias for the attribute key in the expression")
@GraphQLName(ALIAS_KEY)
@Nullable
String alias();

@GraphQLField
@GraphQLDescription(
"Optionally define regex capture rule to extract token value from the attribute value. It should have only one capture group. Ex: \"(.*)\\..*\"")
@GraphQLName(REGEX_CAPTURE_KEY)
@Nullable
String regexCapture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ private Action convertLabelAction(org.hypertrace.graphql.label.schema.rule.Actio
.build();
case DYNAMIC_LABEL_KEY:
return actionBuilder.setDynamicLabelKey(action.dynamicLabelKey()).build();
case DYNAMIC_LABEL_EXPRESSION:
case DYNAMIC_LABEL:
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,17 +119,11 @@ private Optional<Action> convertAction(
null,
Action.ActionType.DYNAMIC_LABEL_KEY));
case DYNAMIC_LABEL_EXPRESSION:
DynamicLabelExpression dynamicLabelExpression =
convertDynamicLabelExpression(action.getDynamicLabelExpression());
DynamicLabel dynamicLabel = convertDynamicLabel(action.getDynamicLabelExpression());
return operation.map(
op ->
new ConvertedAction(
entityTypes,
op,
null,
null,
dynamicLabelExpression,
Action.ActionType.DYNAMIC_LABEL_EXPRESSION));
entityTypes, op, null, null, dynamicLabel, Action.ActionType.DYNAMIC_LABEL));
default:
log.error("Unrecognized Value type in Action {}", action.getValueCase().name());
return Optional.empty();
Expand All @@ -143,11 +137,11 @@ private StaticLabels convertStaticLabels(
return new ConvertedStaticLabels(staticLabels.getIdsList());
}

private DynamicLabelExpression convertDynamicLabelExpression(
private DynamicLabel convertDynamicLabel(
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 +333,7 @@ private static class ConvertedAction implements Action {
Operation operation;
StaticLabels staticLabels;
String dynamicLabelKey;
DynamicLabelExpression dynamicLabelExpression;
DynamicLabel dynamicLabel;
ActionType type;
}

Expand All @@ -351,8 +345,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 3b9a335

Please sign in to comment.