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

Remove ReporterInput.resolutionProvider #8026

Merged
merged 10 commits into from
Jan 9, 2024

Conversation

fviernau
Copy link
Member

@fviernau fviernau commented Dec 12, 2023

As of the addition of OrtResult.resolvedConfiguration, the ORT result is self-contained WRT to package configurations,
resolutions and curations. So, in theory the OrtResult can be passed to each respective Reporter without
any accompanying provider, e.g. ResolutionProvider, CurationProvider as you name it. This would be less complicated to handle: e.g. make the ReporterCommand first include all the data in OrtResult and then pass around the OrtResult to the reporters.

If you look at the functions OrtResult.getOpenIssues() or OrtResult.getResolutions(), these consider only resolutions from the repository configuration, but not the ones from the resolved configuration. So, the result of these functions can normally only be used by further processing it with some matching against data from a ResolutionProvider. This inconvenience would be removed if just all data was included in OrtResult and actually also used by its member functions.

This PR implements this only for the resolution provider.
An analog PR should be done for package configurations, which would allow to implement filtering issues by affectedPath / path excludes within OrtResult.getIssues().

Part of #7921.

@fviernau fviernau requested a review from a team as a code owner December 12, 2023 14:52
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (86be29e) 67.08% compared to head (ab50952) 67.08%.
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8026   +/-   ##
=========================================
  Coverage     67.08%   67.08%           
  Complexity     2054     2054           
=========================================
  Files           357      357           
  Lines         17121    17121           
  Branches       2457     2457           
=========================================
  Hits          11486    11486           
  Misses         4613     4613           
  Partials       1022     1022           
Flag Coverage Δ
funTest-non-docker 34.10% <ø> (ø)
test 36.76% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch 6 times, most recently from 3e3979a to 967a269 Compare December 13, 2023 09:08
@@ -103,7 +103,7 @@ internal class RemoveEntriesCommand : CliktCommand(
}

val ruleViolationResolutions = ortResult.getRuleViolations().let { ruleViolations ->
ortResult.getResolutions().ruleViolations.filter { resolution ->
ortResult.getRepositoryConfigResolutions().ruleViolations.filter { resolution ->
Copy link
Member

Choose a reason for hiding this comment

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

Commit message: Typo in "cofigurations".

but not the ones from the resolved configuration

I might be mistaken, but aren't resolutions from the repository configuration also baked into the resolved configuration?

If so, the quoted sentence should probably say "but not the other ones ...".

And if not, is it a mistake that resolutions from the repository configuration are not part of the resolved configuration?

Copy link
Member Author

Choose a reason for hiding this comment

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

I might be mistaken, but aren't resolutions from the repository configuration also baked into the resolved configuration?

Yes, that's true.

Copy link
Member

Choose a reason for hiding this comment

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

Commit message: Typo in "cofigurations".

Typo is still there.

model/src/main/kotlin/OrtResult.kt Outdated Show resolved Hide resolved
model/src/main/kotlin/OrtResult.kt Show resolved Hide resolved
*/
@JsonIgnore
fun getResolutions(): Resolutions =
getRepositoryConfigResolutions().merge(resolvedConfiguration.resolutions.orEmpty())
Copy link
Member

Choose a reason for hiding this comment

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

What now confuses me here is: If as discussed here resolutions from the repository config are already part of the resolved configuration, why do they need to be merged here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided for this, as not all stages have the resolutions in the resolved configuration, e.g. like the analyzer.

Copy link
Member

Choose a reason for hiding this comment

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

Does merge deduplicate resolutions?

IIRC only resolutions that actually match anything are added to the resolved configuration. Merging resolutions from the repository config would add those that don't match anything.

I decided for this, as not all stages have the resolutions in the resolved configuration, e.g. like the analyzer.

IMO if resolutions have not been resolved, it's fine to ignore those from the repository configuration. Because using them but ignoring those from the resolutions file is also inconsistent with what later steps that properly resolve resolutions will see.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO if resolutions have not been resolved, it's fine to ignore those from the repository configuration.

I've changed it accordingly.

@@ -103,7 +103,7 @@ internal class RemoveEntriesCommand : CliktCommand(
}

val ruleViolationResolutions = ortResult.getRuleViolations().let { ruleViolations ->
ortResult.getResolutions().ruleViolations.filter { resolution ->
ortResult.getRepositoryConfigResolutions().ruleViolations.filter { resolution ->
Copy link
Member

Choose a reason for hiding this comment

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

Commit message: Typo in "cofigurations".

Typo is still there.

*/
@JsonIgnore
fun getResolutions(): Resolutions =
getRepositoryConfigResolutions().merge(resolvedConfiguration.resolutions.orEmpty())
Copy link
Member

Choose a reason for hiding this comment

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

Does merge deduplicate resolutions?

IIRC only resolutions that actually match anything are added to the resolved configuration. Merging resolutions from the repository config would add those that don't match anything.

I decided for this, as not all stages have the resolutions in the resolved configuration, e.g. like the analyzer.

IMO if resolutions have not been resolved, it's fine to ignore those from the repository configuration. Because using them but ignoring those from the resolutions file is also inconsistent with what later steps that properly resolve resolutions will see.

@@ -272,7 +272,7 @@ data class OrtResult(
.mapNotNull { (id, issues) -> issues.takeUnless { isExcluded(id) } }
.flatten()
.filter { issue ->
issue.severity >= minSeverity && getRepositoryConfigResolutions().issues.none { it.matches(issue) }
issue.severity >= minSeverity && getResolutions().issues.none { it.matches(issue) }
Copy link
Member

Choose a reason for hiding this comment

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

Function docs need to be adapted.

Copy link
Member

Choose a reason for hiding this comment

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

Commit message: Typo in StatisticsCalculator

@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch 5 times, most recently from 0cdf172 to 2ee3109 Compare December 19, 2023 07:59
ortResult.getVulnerabilities(omitExcluded = true).values.flatten()
.filterNot { resolutionProvider.isResolved(it) }.size
private fun getOpenVulnerabilities(ortResult: OrtResult): Int =
ortResult.getVulnerabilities(omitExcluded = true).values.flatten().size
Copy link
Member

Choose a reason for hiding this comment

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

This needs to also pass omitResolved = true now in exchange for dropping .filterNot { resolutionProvider.isResolved(it) }.

): IssueStatistics {
val openIssues = ortResult.getOpenIssues(Severity.HINT).filterNot { resolutionProvider.isResolved(it) }
private fun getOpenIssues(ortResult: OrtResult, ortConfig: OrtConfiguration): IssueStatistics {
val openIssues = ortResult.getOpenIssues(Severity.HINT)
Copy link
Member

Choose a reason for hiding this comment

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

Note (to myself as well): The signature of getOpenIssues() is a bit inconsistent with getRuleViolations() and getVulnerabilities() in that it offers no omitResolved parameter, but always filters for unresolved issues.

As such, the .filterNot { resolutionProvider.isResolved(it) } call could have been dropped without a change of functionality independently of this commit / PR. Maybe this should be clarified in the commit message. Or do we even take the chance and align the API as part of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

As such, the .filterNot { resolutionProvider.isResolved(it) } call could have been dropped without a change of functionality independently of this commit / PR.

Can you help understanding why it would not change functionality?

Copy link
Member

Choose a reason for hiding this comment

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

getOpenIssues() (as opposed to getIssues()) is implemented like this:

fun getOpenIssues(minSeverity: Severity = Severity.WARNING) =
getIssues()
.mapNotNull { (id, issues) -> issues.takeUnless { isExcluded(id) } }
.flatten()
.filter { issue ->
issue.severity >= minSeverity && getResolutions().issues.none { it.matches(issue) }
}

so the getResolutions().issues.none { it.matches(issue) } part already only keeps issues for which no resolution matches. Which means the .filterNot { resolutionProvider.isResolved(it) } never was necessary here, if I'm not mistaken.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

As such, the .filterNot { resolutionProvider.isResolved(it) } call could have been dropped without a change of functionality independently of this commit / PR. Maybe this should be clarified in the commit message. Or do we even take the chance and align the API as part of this PR?

However, this comment assumes that OrtResult contains all resolutions. This wasn't true until my recent changed which changed the reporter command to ensure that. And that change was a preparation for this commit, so to me it makes sense to remove it in this commit. Does this make sense to you now as well ?


/**
* Return a list of [RuleViolation]s for which no [RuleViolationResolution] is provided.
*/
@Suppress("UNUSED") // This function is used in the templates.
fun filterForUnresolvedRuleViolations(ruleViolation: List<RuleViolation>): List<RuleViolation> =
ruleViolation.filterNot { input.resolutionProvider.isResolved(it) }
ruleViolation.filterNot { input.ortResult.isResolved(it) }
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether we should instead simply drop these functions and tell reporter authors to call getRuleViolations(omitResolved = true). Similar below.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would be a breaking change, as we basically don't know who is making use of these.
I strongly prefer to, if at all, do this out of scope of this PR in a separate dedicated PR later on.

@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch 2 times, most recently from 2023082 to d3d7a18 Compare December 19, 2023 11:39
@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch from d3d7a18 to 5784097 Compare December 20, 2023 11:34
@fviernau fviernau enabled auto-merge (rebase) December 20, 2023 11:56
@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch 3 times, most recently from 1299d6c to ee38e1e Compare December 27, 2023 08:46
@fviernau fviernau force-pushed the reporter-remove-resolution-provider branch from ee38e1e to 5bb980e Compare January 2, 2024 17:49
@sschuberth sschuberth force-pushed the reporter-remove-resolution-provider branch from 5bb980e to 8d4859a Compare January 8, 2024 17:38
sschuberth and others added 5 commits January 8, 2024 18:39
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
The reporter command has been changed to ensure that all resolutions
are included in the `OrtResult` before passing it around to the
reporters. Reflect that also in this test asset. This was left-over by
10c0362.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
Align all `reporter-test-input.yml` files to again have the same
contents.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
Prepare for the removal of `ReporterInput.resolutionProvider`. The
change is non-functional because the reporter command ensures that
all relevant resolutions are contained in the `OrtResult`.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
Prepare for the removal of `ReporterInput.resolutionProvider`. The
change is non-functional because the reporter command ensures that
all relevant resolutions are contained in the `OrtResult`.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
@sschuberth sschuberth force-pushed the reporter-remove-resolution-provider branch 2 times, most recently from 7390bf5 to 9877fb9 Compare January 8, 2024 20:33
sschuberth
sschuberth previously approved these changes Jan 8, 2024
fviernau and others added 5 commits January 8, 2024 21:42
Prepare for the removal of `ReporterInput.resolutionProvider`. The
change is non-functional because the reporter command ensures that
all relevant resolutions are contained in the `OrtResult`.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
Prepare for the removal of `ReporterInput.resolutionProvider`. The
change is non-functional because the reporter command ensures that
all relevant resolutions are contained in the `OrtResult`.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The reporter command ensures that all resolutions are contained in the
ORT result. So, the resolution provider is not necessary anymore.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
As `OrtResult` meanwhile has all the functions of `ResolutionProvider`,
make it implement that interface to document that.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
@sschuberth sschuberth dismissed mnonnenmacher’s stale review January 8, 2024 20:42

Comments were addressed.

@sschuberth sschuberth enabled auto-merge (rebase) January 8, 2024 20:43
@sschuberth sschuberth merged commit e1c0651 into main Jan 9, 2024
22 checks passed
@sschuberth sschuberth deleted the reporter-remove-resolution-provider branch January 9, 2024 07:34
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