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 #20310: Method getByRulesCompliance used by API is highly inefficient #4017
Fixes #20310: Method getByRulesCompliance used by API is highly inefficient #4017
Conversation
This PR is not finished, but so far:
|
PR updated with a new commit |
This PR changes what is returned: Rules not applied on anything don't show up in the resulting list - i'm unsure whether it's good or not, at least for me it seems to be a change that make sense (no compliance is not 0 compliance) API calls to compliance/rules go from 17s to 14s with 4950 nodes (include js serialization) |
PR updated with a new commit |
actually, we should not change the list of rules returns, as it is used in 7.0 for rule pages |
PR updated with a new commit |
@@ -98,7 +97,12 @@ class ComplianceApi( | |||
|
|||
(for { | |||
level <- restExtractor.extractComplianceLevel(req.params) | |||
rules <- complianceService.getRulesCompliance() | |||
computeLevel <- Full(if(version.value <= 6) { | |||
None |
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 be Some(10) (or Some(value expected for api versio 6 )
But Version 6 is not supported anymore with we just may want to remove them (need to check though), but i think 6.1 is 7 minimal api version
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.
a few line below you can use compluteLevel insted of level.getOrElse(10)
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.
Also this fails if level is not defined, if defined and version > 6 we should default to default vlaue (10)
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.
Ok I misread i haven't seen the Full, nevermind this is ok !
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.
level is an option that appears only later, so I'd like to keep the semantic of "not defined" , thus an None
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.
Yes i just misread and haven't seen it was in a Full and thought the None could break the computation, but it's not the case at all
PR updated with a new commit |
for { | ||
groupLib <- nodeGroupRepo.getFullGroupLibrary().toBox | ||
directivelib <- directiveRepo.getFullDirectiveLibrary().toBox | ||
t2 = System.currentTimeMillis() | ||
_ = logger.trace(s"getByRulesCompliance - getFullGroupLibrary in ${t2 - t1} ms") |
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.
~400ms
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.
timings for 4950 nodes, with API answering in 1.2s
nodeInfos <- nodeInfoService.getAll() | ||
t4 = System.currentTimeMillis() | ||
_ = logger.trace(s"getByRulesCompliance - nodeInfoService.getAll() in ${t4 - t3} ms") |
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.
~ 8ms
) | ||
} yield { | ||
t6 = System.currentTimeMillis() | ||
_ = logger.trace(s"getByRulesCompliance - findRuleNodeStatusReports in ${t6 - t5} ms") |
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.
~ 170ms
} | ||
val reportsByRule = reportsByNode.flatMap { case(_, status) => status.reports }.groupBy( _.ruleId) | ||
val t7 = System.currentTimeMillis() | ||
logger.trace(s"getByRulesCompliance - group reports by rules in ${t7 - t6} ms") |
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.
~150 ms
(initializedCompliances ++ nonEmptyRules).values.toSeq | ||
} | ||
val t8 = System.currentTimeMillis() | ||
logger.trace(s"getByRulesCompliance - Compute non empty rules in ${t8 - t7} ms") |
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.
~120ms
} | ||
|
||
val t9 = System.currentTimeMillis() | ||
logger.trace(s"getByRulesCompliance - Compute ${initializedCompliances.size} empty rules in ${t9 - t8} ms") |
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.
~ 60ms
This PR is not mergeable to upper versions. |
OK, squash merging this PR |
9 similar comments
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
OK, squash merging this PR |
# This is the 1st commit message: Fixes #20310: Method getByRulesCompliance used by API is highly inefficient # The commit message #2 will be skipped: # fixup! Fixes #20310: Method getByRulesCompliance used by API is highly inefficient # # Fixes #20310: Method getByRulesCompliance used by API is highly inefficient
cc7c9a2
to
d6cb387
Compare
OK, merging this PR |
OK, merging this PR |
https://issues.rudder.io/issues/20310