Skip to content

Commit

Permalink
Merge branch 'main' into sanket/addConfigMetricReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket-mundra committed Aug 30, 2024
2 parents de0352b + aec20fe commit 50de7d4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public UpsertedConfig writeConfig(
.asRuntimeException();
}
} else {
collection.createOrReplace(latestDocKey, latestConfigDocument);
collection.upsert(latestDocKey, latestConfigDocument);
}

return optionalPreviousConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void WriteConfigForCreate() throws IOException {

ArgumentCaptor<Key> keyCaptor = ArgumentCaptor.forClass(Key.class);
ArgumentCaptor<Document> 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();
Expand Down Expand Up @@ -129,7 +129,7 @@ void WriteConfigForUpdateWithoutUpsertCondition() throws IOException {

ArgumentCaptor<Key> keyCaptor = ArgumentCaptor.forClass(Key.class);
ArgumentCaptor<Document> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,18 +17,24 @@
public class SpanFilterMatcher {

public boolean matchesEnvironment(SpanFilter spanFilter, Optional<String> environment) {
if (spanFilter.hasUnarySpanFilter()) {
return true;
}
if (spanFilter.hasRelationalSpanFilter()) {
return matchesEnvironment(spanFilter.getRelationalSpanFilter(), environment);
} else {
if (spanFilter
.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()
Expand All @@ -38,18 +45,24 @@ public boolean matchesEnvironment(SpanFilter spanFilter, Optional<String> enviro
}

public boolean matchesServiceName(SpanFilter spanFilter, String serviceName) {
if (spanFilter.hasUnarySpanFilter()) {
return true;
}
if (spanFilter.hasRelationalSpanFilter()) {
return matchesServiceName(spanFilter.getRelationalSpanFilter(), serviceName);
} else {
if (spanFilter
.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()
Expand All @@ -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<String> environment) {
if (environment.isEmpty()) {
Expand Down

0 comments on commit 50de7d4

Please sign in to comment.