Skip to content
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

fix: Add separate settings for parties cache, don't cache invalid response from Altinn 2 #1194

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

elsand
Copy link
Collaborator

@elsand elsand commented Sep 25, 2024

Description

Currently, if the user is missing a profile in Altinn 2, the reportee list returned from all auth/am APIs are empty. This is an error condition, so we treat it as such and don't cache the empty response.

Also, this introduces a separate cache setting for parties, as this does not have the cardinality issues as the PDP cache, allowing us to utilize memory cache for this.

Related Issue(s)

  • N/A

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Summary by CodeRabbit

  • New Features

    • Enhanced caching mechanism for authorized parties, improving performance and response times.
    • Introduced a new exception handling mechanism for upstream service errors.
  • Bug Fixes

    • Improved error handling in the UpstreamServiceException class to allow custom messages.
  • Documentation

    • Updated configuration parameters for caching authorized parties to ensure clarity on retention and timeout settings.

@elsand elsand requested a review from a team as a code owner September 25, 2024 12:24
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications primarily focused on enhancing caching mechanisms and error handling within the AltinnAuthorizationClient class and related components. A new cache for authorized parties has been added, separating it from the existing dialog details authorization cache. Additionally, the UpstreamServiceException class has been updated to include a new constructor for custom messages. Furthermore, the InfrastructureExtensions class has been modified to configure caching parameters for authorized parties, specifying durations and timeouts for cache behavior.

Changes

Files Change Summary
src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs Introduced _partiesCache for authorized parties, replaced _cache with _pdpCache, updated relevant methods, and added exception handling in PerformAuthorizedPartiesRequest.
src/Digdir.Domain.Dialogporten.Infrastructure/Common/Exceptions/UpstreamServiceException.cs Added a constructor for custom messages and updated the existing constructor signature.
src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs Added new cache configuration for AuthorizedPartiesResult in AddInfrastructure method with specified durations and timeouts.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 4b8cd92 and 7ee6bcc.

📒 Files selected for processing (3)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs (6 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Common/Exceptions/UpstreamServiceException.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs (1 hunks)
🔇 Additional comments not posted (6)
src/Digdir.Domain.Dialogporten.Infrastructure/Common/Exceptions/UpstreamServiceException.cs (1)

4-8: LGTM! Well-structured exception class with improved flexibility.

The changes to the UpstreamServiceException class are well-implemented and provide several benefits:

  1. The explicit class definition with braces improves readability.
  2. The addition of a new constructor taking a string message increases flexibility in creating exceptions.
  3. The internal sealed modifier appropriately restricts the class's accessibility and prevents unintended inheritance.
  4. Implementing IUpstreamServiceError provides a clear contract for upstream service errors.

These modifications enhance the exception handling capabilities while maintaining good coding practices.

src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs (5)

22-23: Separation of caches enhances modularity

Introducing separate cache variables _pdpCache and _partiesCache improves the separation of concerns, allowing for independent caching strategies for PDP and authorized parties data.


60-60: Correct use of _pdpCache for dialog authorization

The GetDialogDetailsAuthorization method now appropriately uses _pdpCache to cache dialog details authorization requests. This ensures that PDP-related caching is consistent and isolated.


78-78: Consistent caching in search authorization

The method GetAuthorizedResourcesForSearch correctly utilizes _pdpCache, maintaining consistency in caching PDP requests across different methods.


86-86: Proper caching of authorized parties

Using _partiesCache in GetAuthorizedParties separates the caching of authorized parties from PDP caching. This aligns with the PR objective to introduce distinct cache settings for parties.


124-128: Exception handling for empty authorized parties response

Throwing an UpstreamServiceException when authorizedPartiesDto is null or empty effectively handles cases where users lack an Altinn profile. This change ensures that such scenarios are flagged as errors rather than caching and potentially misrepresenting empty data.

Copy link

sonarcloud bot commented Sep 27, 2024

@elsand elsand merged commit dbb79dc into main Oct 1, 2024
21 checks passed
@elsand elsand deleted the fix/dont-cache-invalid-parties-response branch October 1, 2024 13:49
arealmaas pushed a commit that referenced this pull request Oct 2, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.20.1](v1.20.0...v1.20.1)
(2024-10-02)


### Bug Fixes

* Add separate settings for parties cache, don't cache invalid response
from Altinn 2
([#1194](#1194))
([dbb79dc](dbb79dc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
arealmaas pushed a commit that referenced this pull request Oct 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.20.1](v1.20.0...v1.20.1)
(2024-10-02)


### Bug Fixes

* Add separate settings for parties cache, don't cache invalid response
from Altinn 2
([#1194](#1194))
([dbb79dc](dbb79dc))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants