diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java index 0fd9e749..d62deb4c 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java @@ -94,7 +94,7 @@ public UpsertedConfig writeConfig( .asRuntimeException(); } } else { - collection.createOrReplace(latestDocKey, latestConfigDocument); + collection.upsert(latestDocKey, latestConfigDocument); } return optionalPreviousConfig diff --git a/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java b/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java index 9fe2c406..d2f97e8c 100644 --- a/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java +++ b/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java @@ -89,7 +89,7 @@ void WriteConfigForCreate() throws IOException { ArgumentCaptor keyCaptor = ArgumentCaptor.forClass(Key.class); ArgumentCaptor documentCaptor = ArgumentCaptor.forClass(Document.class); - verify(collection, times(1)).createOrReplace(keyCaptor.capture(), documentCaptor.capture()); + verify(collection, times(1)).upsert(keyCaptor.capture(), documentCaptor.capture()); Key key = keyCaptor.getValue(); Document document = documentCaptor.getValue(); @@ -129,7 +129,7 @@ void WriteConfigForUpdateWithoutUpsertCondition() throws IOException { ArgumentCaptor keyCaptor = ArgumentCaptor.forClass(Key.class); ArgumentCaptor documentCaptor = ArgumentCaptor.forClass(Document.class); - verify(collection, times(1)).createOrReplace(keyCaptor.capture(), documentCaptor.capture()); + verify(collection, times(1)).upsert(keyCaptor.capture(), documentCaptor.capture()); Key key = keyCaptor.getValue(); Document document = documentCaptor.getValue(); 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()) {