-
Notifications
You must be signed in to change notification settings - Fork 14
US66693: Refactor policy evaluation decision caching to allow eviction of keys #115
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,14 +107,21 @@ public PolicyEvaluationResult evalPolicy(final PolicyEvaluationRequestV1 request | |
| // Fixing policy evaluation order so we could build a cache key. | ||
| PolicyEvaluationRequestCacheKey key; | ||
| if (policySetsEvaluationOrder.isEmpty()) { | ||
| key = new Builder().zoneId(zone.getName()).policySetIds( | ||
| Stream.of(filteredPolicySets.iterator().next().getName()) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new))).request(request).build(); | ||
| key = new Builder().zoneId(zone.getName()) | ||
| .policySetIds(Stream.of(filteredPolicySets.iterator().next().getName()) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new))) | ||
| .request(request).build(); | ||
| } else { | ||
| key = new Builder().zoneId(zone.getName()).request(request).build(); | ||
| } | ||
|
|
||
| PolicyEvaluationResult result = this.cache.get(key); | ||
| PolicyEvaluationResult result = null; | ||
| try { | ||
| result = this.cache.get(key); | ||
| } catch (Exception e) { | ||
| LOGGER.error(String.format("Unable to get cache key '%s'", key), e); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a unit test that policy evaluation returns expected result if cache get or set fails
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| if (null == result) { | ||
| result = new PolicyEvaluationResult(Effect.NOT_APPLICABLE); | ||
|
|
||
|
|
@@ -141,7 +148,12 @@ public PolicyEvaluationResult evalPolicy(final PolicyEvaluationRequestV1 request | |
|
|
||
| LOGGER.info("Processed Policy Evaluation for: " + "resourceUri='{}', subjectIdentifier='{}', action='{}'," | ||
| + " result='{}'", uri, subjectIdentifier, action, result.getEffect()); | ||
| this.cache.set(key, result); | ||
| try { | ||
| this.cache.set(key, result); | ||
| } catch (Exception e) { | ||
| LOGGER.error(String.format("Unable to set cache key '%s' to value '%s' due to exception", key, result), | ||
| e); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
@@ -152,7 +164,8 @@ LinkedHashSet<PolicySet> filterPolicySetsByPriority(final String subjectIdentifi | |
|
|
||
| if (policySetsEvaluationOrder.isEmpty()) { | ||
| if (allPolicySets.size() > 1) { | ||
| LOGGER.error("Found more than one policy set during policy evaluation and " | ||
| LOGGER.error( | ||
| "Found more than one policy set during policy evaluation and " | ||
| + "no evaluation order is provided. subjectIdentifier='{}', resourceURI='{}'", | ||
| subjectIdentifier, uri); | ||
| throw new IllegalArgumentException("More than one policy set exists for this zone. " | ||
|
|
@@ -192,9 +205,6 @@ private PolicyEvaluationResult evalPolicySet(final PolicySet policySet, final St | |
|
|
||
| Effect effect = Effect.NOT_APPLICABLE; | ||
| Set<String> resolvedResourceUris = matchResult.getResolvedResourceUris(); | ||
| if (null == resolvedResourceUris) { | ||
| resolvedResourceUris = new HashSet<>(); | ||
| } | ||
| resolvedResourceUris.add(resourceURI); | ||
|
|
||
| Set<Attribute> resourceAttributes = Collections.emptySet(); | ||
|
|
@@ -264,8 +274,8 @@ boolean evaluateConditions(final Set<Attribute> subjectAttributes, final Set<Att | |
|
|
||
| debugAttributes(subjectAttributes, resourceAttributes); | ||
|
|
||
| Map<String, Object> attributeBindingsMap = this | ||
| .getAttributeBindingsMap(subjectAttributes, resourceAttributes, resourceURI, resourceURITemplate); | ||
| Map<String, Object> attributeBindingsMap = this.getAttributeBindingsMap(subjectAttributes, resourceAttributes, | ||
| resourceURI, resourceURITemplate); | ||
|
|
||
| boolean result = true; | ||
| for (int i = 0; i < validatedConditionScripts.size(); i++) { | ||
|
|
||
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.
Should we set an expiration timeout on the key similar to what's done in line #89? The same comment applies to set function above. Timeout is only set on the key for eval result and not for any other.
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.
Timeout should not be set for anything other then Policy Evaluation. This is because we would then be unnecessarily reevaluating requests when entities have no changed.