-
Notifications
You must be signed in to change notification settings - Fork 7
feat(system-exclude-span-rules): system exclude span rules #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## main #133 +/- ##
============================================
+ Coverage 84.67% 85.06% +0.38%
- Complexity 437 453 +16
============================================
Files 47 47
Lines 2160 2216 +56
Branches 82 90 +8
============================================
+ Hits 1829 1885 +56
+ Misses 276 273 -3
- Partials 55 58 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
skjindal93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add validation for not allowing updates for system level rules, apart from the disabled flag?
We should also add validation in delete. Deletion of system rules shouldn't be allowed. We can have this check within the delete API impl
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
| if (config.hasPath(SPAN_PROCESSING_CONFIG_SERVICE)) { | ||
| Config spanProcessingConfig = config.getConfig(SPAN_PROCESSING_CONFIG_SERVICE); | ||
| if (spanProcessingConfig.hasPath(SYSTEM_LEVEL_EXCLUDE_SPAN_RULES)) { | ||
| systemLevelExcludeSpanRuleObjectList = | ||
| spanProcessingConfig.getObjectList(SYSTEM_LEVEL_EXCLUDE_SPAN_RULES); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the configs to a separate config class? Or, may be to a separate method. Would prefer a separate config class, if it isn't much refactor
We can also directly define the default exclusion rules config as span.processing.config.service.system.exclude.span.rules, to avoid multiple if block nesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added separate methods for reading configs and conversion for now.
I am thinking of taking up a total refactor(config class, separate manager for exclude rules) separately. What do you suggest?
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
| Map<String, ExcludeSpanRuleDetails> tenantLevelExcludeSpanRulesToIdMap = | ||
| buildTenantLevelExcludeSpanRulesToIdMap(excludeSpanRules); | ||
|
|
||
| // all the tenant level configs except for the overridden system level ones | ||
| List<ExcludeSpanRuleDetails> filteredTenantLevelExcludeSpanRules = | ||
| excludeSpanRules.stream() | ||
| .filter( | ||
| excludeSpanRule -> | ||
| !systemLevelExcludeSpanRulesToIdMap.containsKey( | ||
| excludeSpanRule.getRule().getId())) | ||
| .collect(Collectors.toUnmodifiableList()); | ||
|
|
||
| // all the system level configs, replaced by the overridden configs in case of overrides | ||
| List<ExcludeSpanRuleDetails> filteredSystemLevelExcludeSpanRules = | ||
| systemLevelExcludeSpanRules.stream() | ||
| .map( | ||
| excludeSpanRule -> | ||
| tenantLevelExcludeSpanRulesToIdMap.containsKey(excludeSpanRule.getId()) | ||
| ? tenantLevelExcludeSpanRulesToIdMap.get(excludeSpanRule.getId()) | ||
| : ExcludeSpanRuleDetails.newBuilder().setRule(excludeSpanRule).build()) | ||
| .collect(Collectors.toUnmodifiableList()); | ||
|
|
||
| responseObserver.onNext( | ||
| GetAllExcludeSpanRulesResponse.newBuilder() | ||
| .addAllRuleDetails(excludeSpanRulesConfigStore.getAllData(requestContext)) | ||
| .addAllRuleDetails(filteredTenantLevelExcludeSpanRules) | ||
| .addAllRuleDetails(filteredSystemLevelExcludeSpanRules) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks complex. I don't think there was a need to filter out overrides from persisted exclude span rules. We could have actually just sent out the entire persisted exclude span rules + non overriden system exclude rules
Something like this
Set<String> userExcludeSpanRuleIds = excludeSpanRules.stream()
.map(excludeSpanRule -> excludeSpanRule.getRule().getId()).collect(
Collectors.toUnmodifiableSet());
// all the system level configs, replaced by the overridden configs in case of overrides
List<ExcludeSpanRule> nonOverridenExcludeSpanRules =
systemLevelExcludeSpanRules.stream()
.filter(
systemExcludeRule -> !userExcludeSpanRuleIds.contains(systemExcludeRule.getId()))
.collect(Collectors.toUnmodifiableList());
And, we can then convert the nonOverridenExcludeSpanRules to List<ExcludeSpanRuleDetails> while sending it in the response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had taken this route so as to ensure that the system exclude rules(overridden or not) would end up in the bottom and the UI wouldn't have to worry about the ordering.
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Outdated
Show resolved
Hide resolved
| ExcludeSpanRule existingRule = | ||
| this.excludeSpanRulesConfigStore | ||
| .getData(requestContext, updateExcludeSpanRule.getId()) | ||
| .or(() -> getSystemLevelExcludeSpanRule(updateExcludeSpanRule.getId())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we taking care of the fact, if a customer disables the system exclude rule, we need to store is as disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is handled in building updated rule part on L189. The new rule would be built from the existing system exclude rule and the update exclude rule, and upserted.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
...main/java/org/hypertrace/span/processing/config/service/SpanProcessingConfigServiceImpl.java
Show resolved
Hide resolved
| } | ||
|
|
||
| private List<ExcludeSpanRuleDetails> reorderExcludeSpanRules( | ||
| List<ExcludeSpanRuleDetails> userExcludeSpanRules, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we convert list into a map, then we can directly use Maps.difference(userExcludeSpanRuleIdToRuleMap, systemExcludeSpanRuleIdToRuleMap). You can use
entriesInCommon for overriden rules
entriesOnLeft for only user rules
entriesOnRight for only system rules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we would not be able to retain order among rules within the same groups right?🤔 Am I missing something?
Description
This PR adds support for defining system level exclude span rules and overriding(enabling/disabling) them at a tenant level.
Testing
Added new unit tests for all new code, and ran all the existing unit tests.
Checklist: