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

Fixes #25092: Refactor CachedReportingService to make persistance simpler #5757

Conversation

fanf
Copy link
Member

@fanf fanf commented Jul 1, 2024

https://issues.rudder.io/issues/25092

So, it seems that a lot of things are going on here, but that's not so much:

This commit splits the big CachedReportingServiceImpl into four parts:

  • a dumb NodeStatusReportRepository that only store/retrieve NodeStatusReports. Also add a simple
    implementation in memory. Latter, we will be able to persist in a psql backend storage
  • a new extremely simple ReportingService using previous NodeStatusReportRepository. With that and the availability of PolicyType, it's now apparent that that service is just syntaxic sugor on top of filtering NodeStatusReports.
  • a ComputeNodeStatusReportService that get the logic with the queue but change nothing in it for now. It updates NodeStatusReportRepository with its updates. Latter on, we will be able to add a check on expiration based on node parameter about how long to keep expired compliance.
  • a FindNewNodeStatusReports that only has the logic to retrieve information for new NodeStatusReports
    in base from expected reports and run. The fact that it is now independant from RepositoryService method signature allows to show that RuleId, DirectiveId and PolicyType paramters are never used in it. We will be able to simplify it even further more latter on (his only job should be to retieve RunAndConfigInfo, and let ComputeNodeStatusReportService do the computing).

For now, we keep the same init logic than we had before the refactoring: there's a bootstrap action that expires all node compliance, so they are all computed back which now init the in-memory NodeStatusReportRepository. Of course once we have that in base, we will get it from there, only asking for the missing nodes if any.

Then, the commit adapt signatures where ReportingService was used.

It alos remove ReportingServiceTest which was only comments (very useful) ; and adapt CachedReportingServiceTest to show that things still work when splitted in several pieces. One value change in that test because we don't exactly have the same call chain: now, the call to trigger a computation is explicit, and the chain is smarter on what should be updated (following https://issues.rudder.io/issues/24652 / #5737)

All in all, the new code is much, much simpler and get ride of a lot of oranically-grown-not-refactored code ; and it will be rather easy to add the missing parts for persisting and not expiring compliance.

@fanf fanf requested a review from clarktsiory July 1, 2024 20:51
…parts

Split the big CachedReportingServiceImpl into three parts:
- a dumb NodeStatusReportRepository that only store/retrieve NodeStatusReports. Also add a simple
  implementation in memory. Latter, we will be able to persist in a psql backend storage
- a ComputeNodeStatusReportService that get the logic with the queue
- a FindNewNodeStatusReports that only has the logic to retrieve information for new NodeStatusReports
  in base from expected reports and run.

Also, use that last one in CachedReportingServiceImpl - it should change nothing.
Next part is to remove ReportingServiceImpl and replace it everywhere with one of the three new services.
@fanf fanf force-pushed the arch_25092/refactor_cachedreportingservice_to_make_persistance_simpler branch from 083cfbb to 61ee463 Compare July 4, 2024 13:59
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

LGTM ! Nice and clear refactoring

@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit ec7e22b into Normation:master Jul 4, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants