diff --git a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/Action.java b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/Action.java index e98c4de..242cd82 100644 --- a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/Action.java +++ b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/Action.java @@ -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; @@ -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) @@ -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"; } @@ -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 diff --git a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabel.java b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabel.java new file mode 100644 index 0000000..2d52403 --- /dev/null +++ b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabel.java @@ -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 tokenExtractionRules(); +} diff --git a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabelExpression.java b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabelExpression.java deleted file mode 100644 index 9852d6d..0000000 --- a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/DynamicLabelExpression.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.hypertrace.graphql.label.schema.rule; - -import graphql.annotations.annotationTypes.GraphQLField; -import graphql.annotations.annotationTypes.GraphQLName; -import graphql.annotations.annotationTypes.GraphQLNonNull; -import java.util.List; - -@GraphQLName(DynamicLabelExpression.TYPE_NAME) -public interface DynamicLabelExpression { - String TYPE_NAME = "DynamicLabelExpression"; - - String LABEL_EXPRESSION_KEY = "labelExpression"; - String TOKEN_EXTRACTION_RULES_KEY = "tokenExtractionRules"; - - @GraphQLField - @GraphQLName(LABEL_EXPRESSION_KEY) - @GraphQLNonNull - String labelExpression(); - - @GraphQLField - @GraphQLNonNull - @GraphQLName(TOKEN_EXTRACTION_RULES_KEY) - List tokenExtractionRules(); -} diff --git a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/TokenExtractionRule.java b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/TokenExtractionRule.java index 3af675e..ac7b474 100644 --- a/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/TokenExtractionRule.java +++ b/hypertrace-graphql-labels-schema-api/src/main/java/org/hypertrace/graphql/label/schema/rule/TokenExtractionRule.java @@ -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; @@ -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(); diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleRequestConverter.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleRequestConverter.java index 7f5cfb6..09655d3 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleRequestConverter.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleRequestConverter.java @@ -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"); diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleResponseConverter.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleResponseConverter.java index f72dd86..75cad52 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleResponseConverter.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/dao/LabelApplicationRuleResponseConverter.java @@ -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; @@ -119,17 +119,11 @@ private Optional 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(); @@ -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())); } @@ -339,7 +333,7 @@ private static class ConvertedAction implements Action { Operation operation; StaticLabels staticLabels; String dynamicLabelKey; - DynamicLabelExpression dynamicLabelExpression; + DynamicLabel dynamicLabel; ActionType type; } @@ -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 tokenExtractionRules; } diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/deserialization/LabelApplicationRuleDeserializationConfig.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/deserialization/LabelApplicationRuleDeserializationConfig.java index 96a5179..642f6d1 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/deserialization/LabelApplicationRuleDeserializationConfig.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/deserialization/LabelApplicationRuleDeserializationConfig.java @@ -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; @@ -40,8 +40,7 @@ public List 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) @@ -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; @@ -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 tokenExtractionRules;