Skip to content

Add "last analysis" timestamp to project responses #4620

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

Closed
2 tasks done
stohrendorf opened this issue Feb 6, 2025 · 3 comments · Fixed by #4642
Closed
2 tasks done

Add "last analysis" timestamp to project responses #4620

stohrendorf opened this issue Feb 6, 2025 · 3 comments · Fixed by #4642
Labels
enhancement New feature or request good first issue Good for newcomers p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort
Milestone

Comments

@stohrendorf
Copy link
Contributor

stohrendorf commented Feb 6, 2025

Current Behavior

There is no information anywhere when the last analysis cycle was done on a project.

Proposed Behavior

Add a field like "lastAnalysis" that contains the timestamp of the last vulnerability analysis of a project, similar to "lastBomImport". Apart for an optimization opportunity for automation leveraging DT, this could also help answer questions like "why is vulnerability X not associated with project Y" by comparing the vulnerability publication/update timestamp to the analysis timestamp within the UI.

NOTE: This is rather-low priority for me, it's not inhibiting anything. It would just be nice to have.

Checklist

@stohrendorf stohrendorf added the enhancement New feature or request label Feb 6, 2025
@nscuro nscuro added p2 Non-critical bugs, and features that help organizations to identify and reduce risk good first issue Good for newcomers size/S Small effort labels Feb 6, 2025
@stohrendorf
Copy link
Contributor Author

I'm thinking about trying to implement this myself. I had a look at the code, and I think I know how to expand the DB model, but I don't know where to actually add saving the timestamp, or where to add it to the response. If you could point me to what to do, or show me a PR where something similar was done, I'd be thankful.

@nscuro
Copy link
Member

nscuro commented Feb 8, 2025

I just refactored the relevant location. Updating the "last analyzed" timestamp for a project could happen here:

private void analyzeProject(
final QueryManager qm,
final Project project,
final VulnerabilityAnalysisLevel analysisLevel) {
final ReentrantLock projectLock = getLockForProjectAndNamespace(project, getClass().getSimpleName());
try {
try {
final boolean lockAcquired = projectLock.tryLock(5, TimeUnit.MINUTES);
if (!lockAcquired) {
LOGGER.warn("Failed to acquire lock after 5min; Skipping analysis");
return;
}
} catch (InterruptedException e) {
LOGGER.warn("Interrupted while waiting for lock; Not performing analysis", e);
Thread.currentThread().interrupt();
return;
}
List<Component> components = fetchNextComponentBatch(qm, project, null);
if (components.isEmpty()) {
LOGGER.info("Project does not have any components; Nothing to analyze");
return;
}
while (!components.isEmpty()) {
if (Thread.currentThread().isInterrupted()) {
LOGGER.info("Interrupted before all components could be analyzed");
break;
}
analyzeComponents(qm, components, analysisLevel);
if (analysisLevel == VulnerabilityAnalysisLevel.PERIODIC_ANALYSIS) {
try {
performPolicyEvaluation(project, components);
} catch (RuntimeException e) {
LOGGER.warn("Policy evaluation against %d components failed".formatted(
components.size()), e);
}
}
qm.getPersistenceManager().evictAll(false, Component.class);
components = fetchNextComponentBatch(qm, project, components.getLast().getId());
}
} finally {
projectLock.unlock();
}
}

Note that vulnerability analysis is only one type of analysis, so we need to be explicit about that when it comes to naming fields / columns.

stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Feb 10, 2025
stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Feb 10, 2025
stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Feb 12, 2025
stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Mar 10, 2025
@nscuro nscuro added this to the 4.13 milestone Mar 10, 2025
stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Mar 11, 2025
stohrendorf added a commit to stohrendorf/dependency-track that referenced this issue Mar 11, 2025
nscuro added a commit that referenced this issue Mar 11, 2025
#4620 add "lastVulnerabilityAnalysis" to project
nscuro added a commit to nscuro/dependency-track-frontend that referenced this issue Apr 6, 2025
The timestamp field was added to the project model in DependencyTrack/dependency-track#4620.

Signed-off-by: nscuro <[email protected]>
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants