diff --git a/span-processing-config-service-impl/src/main/java/org/hypertrace/span/processing/config/service/validation/SpanProcessingConfigRequestValidator.java b/span-processing-config-service-impl/src/main/java/org/hypertrace/span/processing/config/service/validation/SpanProcessingConfigRequestValidator.java index 23e7aafc..330a689a 100644 --- a/span-processing-config-service-impl/src/main/java/org/hypertrace/span/processing/config/service/validation/SpanProcessingConfigRequestValidator.java +++ b/span-processing-config-service-impl/src/main/java/org/hypertrace/span/processing/config/service/validation/SpanProcessingConfigRequestValidator.java @@ -18,6 +18,8 @@ import org.hypertrace.span.processing.config.service.v1.RelationalSpanFilterExpression; import org.hypertrace.span.processing.config.service.v1.SpanFilter; import org.hypertrace.span.processing.config.service.v1.SpanFilterValue; +import org.hypertrace.span.processing.config.service.v1.UnarySpanFilterExpression; +import org.hypertrace.span.processing.config.service.v1.UnarySpanFilterExpression.LeftOperandCase; import org.hypertrace.span.processing.config.service.v1.UpdateExcludeSpanRule; import org.hypertrace.span.processing.config.service.v1.UpdateExcludeSpanRuleRequest; @@ -70,6 +72,9 @@ private void validateSpanFilter(SpanFilter filter) { case RELATIONAL_SPAN_FILTER: validateRelationalSpanFilter(filter); break; + case UNARY_SPAN_FILTER: + validateUnarySpanFilter(filter); + break; default: throw Status.INVALID_ARGUMENT .withDescription("Unexpected filter case: " + printMessage(filter)) @@ -96,6 +101,19 @@ private void validateRelationalSpanFilter(SpanFilter filter) { } } + private void validateUnarySpanFilter(SpanFilter filter) { + validateNonDefaultPresenceOrThrow( + filter.getUnarySpanFilter(), UnarySpanFilterExpression.OPERATOR_FIELD_NUMBER); + + final LeftOperandCase leftOperandCase = filter.getUnarySpanFilter().getLeftOperandCase(); + if (LeftOperandCase.FIELD.equals(leftOperandCase)) { + throw Status.INVALID_ARGUMENT + .withDescription( + "Unary operator is not supported on Field operand: " + printMessage(filter)) + .asRuntimeException(); + } + } + private void validateRegex(String regex) { try { Pattern.compile(regex); diff --git a/span-processing-utils/src/main/java/org/hypertrace/config/span/processing/utils/SpanFilterMatcher.java b/span-processing-utils/src/main/java/org/hypertrace/config/span/processing/utils/SpanFilterMatcher.java index c3bfe9f5..85ba1347 100644 --- a/span-processing-utils/src/main/java/org/hypertrace/config/span/processing/utils/SpanFilterMatcher.java +++ b/span-processing-utils/src/main/java/org/hypertrace/config/span/processing/utils/SpanFilterMatcher.java @@ -7,6 +7,7 @@ import org.hypertrace.span.processing.config.service.v1.Field; import org.hypertrace.span.processing.config.service.v1.ListValue; import org.hypertrace.span.processing.config.service.v1.LogicalOperator; +import org.hypertrace.span.processing.config.service.v1.LogicalSpanFilterExpression; import org.hypertrace.span.processing.config.service.v1.RelationalOperator; import org.hypertrace.span.processing.config.service.v1.RelationalSpanFilterExpression; import org.hypertrace.span.processing.config.service.v1.SpanFilter; @@ -16,6 +17,9 @@ public class SpanFilterMatcher { public boolean matchesEnvironment(SpanFilter spanFilter, Optional environment) { + if (spanFilter.hasUnarySpanFilter()) { + return true; + } if (spanFilter.hasRelationalSpanFilter()) { return matchesEnvironment(spanFilter.getRelationalSpanFilter(), environment); } else { @@ -23,11 +27,14 @@ public boolean matchesEnvironment(SpanFilter spanFilter, Optional enviro .getLogicalSpanFilter() .getOperator() .equals(LogicalOperator.LOGICAL_OPERATOR_AND)) { + if (hasNoRelationalFilters(spanFilter.getLogicalSpanFilter())) { + return true; + } return spanFilter.getLogicalSpanFilter().getOperandsList().stream() .filter(SpanFilter::hasRelationalSpanFilter) .allMatch(filter -> matchesEnvironment(filter.getRelationalSpanFilter(), environment)); } else { - if (spanFilter.getLogicalSpanFilter().getOperandsCount() == 0) { + if (hasNoRelationalFilters(spanFilter.getLogicalSpanFilter())) { return true; } return spanFilter.getLogicalSpanFilter().getOperandsList().stream() @@ -38,6 +45,9 @@ public boolean matchesEnvironment(SpanFilter spanFilter, Optional enviro } public boolean matchesServiceName(SpanFilter spanFilter, String serviceName) { + if (spanFilter.hasUnarySpanFilter()) { + return true; + } if (spanFilter.hasRelationalSpanFilter()) { return matchesServiceName(spanFilter.getRelationalSpanFilter(), serviceName); } else { @@ -45,11 +55,14 @@ public boolean matchesServiceName(SpanFilter spanFilter, String serviceName) { .getLogicalSpanFilter() .getOperator() .equals(LogicalOperator.LOGICAL_OPERATOR_AND)) { + if (hasNoRelationalFilters(spanFilter.getLogicalSpanFilter())) { + return true; + } return spanFilter.getLogicalSpanFilter().getOperandsList().stream() .filter(SpanFilter::hasRelationalSpanFilter) .allMatch(filter -> matchesServiceName(filter.getRelationalSpanFilter(), serviceName)); } else { - if (spanFilter.getLogicalSpanFilter().getOperandsCount() == 0) { + if (hasNoRelationalFilters(spanFilter.getLogicalSpanFilter())) { return true; } return spanFilter.getLogicalSpanFilter().getOperandsList().stream() @@ -59,6 +72,12 @@ public boolean matchesServiceName(SpanFilter spanFilter, String serviceName) { } } + private boolean hasNoRelationalFilters(LogicalSpanFilterExpression logicalSpanFilterExpression) { + return logicalSpanFilterExpression.getOperandsCount() == 0 + || logicalSpanFilterExpression.getOperandsList().stream() + .noneMatch(SpanFilter::hasRelationalSpanFilter); + } + private boolean matchesEnvironment( RelationalSpanFilterExpression relationalSpanFilterExpression, Optional environment) { if (environment.isEmpty()) {