Skip to content

Conversation

@SrikarMannepalli
Copy link
Contributor

@SrikarMannepalli SrikarMannepalli commented Aug 30, 2022

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:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@github-actions

This comment has been minimized.

@codecov
Copy link

codecov bot commented Aug 30, 2022

Codecov Report

Merging #133 (f6e9eaf) into main (10eec87) will increase coverage by 0.38%.
The diff coverage is 88.70%.

❗ Current head f6e9eaf differs from pull request most recent head a92dd92. Consider uploading reports for the commit a92dd92 to get more accurate results

@@             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     
Flag Coverage Δ
integration 85.06% <88.70%> (+0.38%) ⬆️
unit 84.18% <88.70%> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ig/service/SpanProcessingConfigServiceFactory.java 0.00% <0.00%> (ø)
...onfig/service/SpanProcessingConfigServiceImpl.java 85.52% <91.22%> (+5.16%) ⬆️
...fig/service/SpanProcessingConfigServiceModule.java 72.72% <100.00%> (+6.06%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Contributor

@skjindal93 skjindal93 left a 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

Comment on lines 83 to 89
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);
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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?

Comment on lines 110 to 135
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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

ExcludeSpanRule existingRule =
this.excludeSpanRulesConfigStore
.getData(requestContext, updateExcludeSpanRule.getId())
.or(() -> getSystemLevelExcludeSpanRule(updateExcludeSpanRule.getId()))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

}

private List<ExcludeSpanRuleDetails> reorderExcludeSpanRules(
List<ExcludeSpanRuleDetails> userExcludeSpanRules,
Copy link
Contributor

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

Copy link
Contributor Author

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?

@github-actions

This comment has been minimized.

@SrikarMannepalli SrikarMannepalli merged commit f786710 into main Sep 2, 2022
@SrikarMannepalli SrikarMannepalli deleted the system-level-exclusion-rules branch September 2, 2022 09:12
@github-actions
Copy link

github-actions bot commented Sep 2, 2022

Unit Test Results

  25 files  ±0    25 suites  ±0   46s ⏱️ -2s
105 tests ±0  105 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit f786710. ± Comparison against base commit 10eec87.

@SrikarMannepalli SrikarMannepalli changed the title feat(system-level-exclusion-rules): system level exclude span rules feat(system-exclude-span-rules): system level exclude span rules Sep 5, 2022
@SrikarMannepalli SrikarMannepalli changed the title feat(system-exclude-span-rules): system level exclude span rules feat(system-exclude-span-rules): system exclude span rules Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants