Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hypertrace.config.validation.GrpcValidatorUtils.printMessage;
import static org.hypertrace.config.validation.GrpcValidatorUtils.validateNonDefaultPresenceOrThrow;
import static org.hypertrace.config.validation.GrpcValidatorUtils.validateRequestContextOrThrow;
import static org.hypertrace.span.processing.config.service.v1.RuleType.RULE_TYPE_SYSTEM;

import com.google.common.base.Strings;
import com.google.re2j.Pattern;
Expand Down Expand Up @@ -39,6 +40,13 @@ public void validateOrThrow(
public void validateOrThrow(RequestContext requestContext, CreateExcludeSpanRuleRequest request) {
validateRequestContextOrThrow(requestContext);
this.validateData(request.getRuleInfo());
if (RULE_TYPE_SYSTEM.equals(request.getRuleInfo().getType())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add a validation for deleting system rules

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had added the validation for deleting system exclude rules as part of previous PR(#133)

.

throw Status.INVALID_ARGUMENT
.withDescription(
String.format(
"Invalid rule type to create system level rule : %s", request.getRuleInfo()))
.asRuntimeException();
}
}

public void validateOrThrow(RequestContext requestContext, UpdateExcludeSpanRuleRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.hypertrace.span.processing.config.service.validation;

import static org.hypertrace.span.processing.config.service.v1.RuleType.RULE_TYPE_SYSTEM;
import static org.hypertrace.span.processing.config.service.v1.RuleType.RULE_TYPE_USER;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -101,7 +103,21 @@ void validatesExcludeSpanRuleCreateRequest() {
validator.validateOrThrow(
mockRequestContext,
CreateExcludeSpanRuleRequest.newBuilder()
.setRuleInfo(ExcludeSpanRuleInfo.newBuilder().build())
.setRuleInfo(ExcludeSpanRuleInfo.newBuilder().setType(RULE_TYPE_USER).build())
.build()));

assertInvalidArgStatusContaining(
"Invalid rule type to create system level rule",
() ->
validator.validateOrThrow(
mockRequestContext,
CreateExcludeSpanRuleRequest.newBuilder()
.setRuleInfo(
ExcludeSpanRuleInfo.newBuilder()
.setName("name")
.setType(RULE_TYPE_SYSTEM)
.setFilter(buildTestFilter())
.build())
.build()));

assertDoesNotThrow(
Expand All @@ -114,6 +130,7 @@ void validatesExcludeSpanRuleCreateRequest() {
.setName("name")
.setDisabled(true)
.setFilter(buildTestFilter())
.setType(RULE_TYPE_USER)
.build())
.build()));
}
Expand Down