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

Improve efficiency of repository and integrity meta analysis #846

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@
package org.dependencytrack.event;

import alpine.event.framework.Event;
import com.github.packageurl.PackageURL;
import org.dependencytrack.model.Component;
import org.dependencytrack.proto.repometaanalysis.v1.FetchMeta;

import java.util.UUID;

/**
* Defines an {@link Event} triggered when requesting a component to be analyzed for meta information.
*
* @param purlCoordinates The package URL coordinates of the {@link Component} to analyze
* @param internal Whether the {@link Component} is internal
* @param fetchMeta Whether component hash data or component meta data needs to be fetched from external api
* @param purl The {@link PackageURL} of the {@link Component} to analyze
* @param internal Whether the {@link Component} is internal
*/
public record ComponentRepositoryMetaAnalysisEvent(UUID componentUuid, String purlCoordinates, Boolean internal,
FetchMeta fetchMeta) implements Event {
public record ComponentRepositoryMetaAnalysisEvent(PackageURL purl, Boolean internal) implements Event {

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import org.dependencytrack.tasks.EpssMirrorTask;
import org.dependencytrack.tasks.FortifySscUploadTask;
import org.dependencytrack.tasks.GitHubAdvisoryMirrorTask;
import org.dependencytrack.tasks.IntegrityAnalysisTask;
import org.dependencytrack.tasks.IntegrityMetaInitializerTask;
import org.dependencytrack.tasks.InternalComponentIdentificationTask;
import org.dependencytrack.tasks.KennaSecurityUploadTask;
import org.dependencytrack.tasks.LdapSyncTaskWrapper;
Expand Down Expand Up @@ -113,8 +111,6 @@ public void contextInitialized(final ServletContextEvent event) {
EVENT_SERVICE.subscribe(EpssMirrorEvent.class, EpssMirrorTask.class);
EVENT_SERVICE.subscribe(ComponentPolicyEvaluationEvent.class, PolicyEvaluationTask.class);
EVENT_SERVICE.subscribe(ProjectPolicyEvaluationEvent.class, PolicyEvaluationTask.class);
EVENT_SERVICE.subscribe(IntegrityMetaInitializerEvent.class, IntegrityMetaInitializerTask.class);
EVENT_SERVICE.subscribe(IntegrityAnalysisEvent.class, IntegrityAnalysisTask.class);

// Execute maintenance tasks on the single-threaded event service.
// This way, they are not blocked by, and don't block, actual processing tasks on the main event service.
Expand Down Expand Up @@ -155,8 +151,6 @@ public void contextDestroyed(final ServletContextEvent event) {
EVENT_SERVICE.unsubscribe(NistMirrorTask.class);
EVENT_SERVICE.unsubscribe(EpssMirrorTask.class);
EVENT_SERVICE.unsubscribe(PolicyEvaluationTask.class);
EVENT_SERVICE.unsubscribe(IntegrityMetaInitializerTask.class);
EVENT_SERVICE.unsubscribe(IntegrityAnalysisTask.class);
EVENT_SERVICE.unsubscribe(VulnerabilityPolicyFetchTask.class);
EVENT_SERVICE.shutdown(DRAIN_TIMEOUT_DURATION);

Expand Down

This file was deleted.

This file was deleted.

68 changes: 0 additions & 68 deletions src/main/java/org/dependencytrack/event/PurlMigrator.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.dependencytrack.event.kafka;

import alpine.event.framework.Event;
import com.github.packageurl.MalformedPackageURLException;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent;
Expand Down Expand Up @@ -53,8 +54,8 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import static com.github.packageurl.PackageURLBuilder.aPackageURL;
import static org.apache.commons.lang3.ObjectUtils.requireNonEmpty;

/**
Expand Down Expand Up @@ -131,21 +132,31 @@ static KafkaEvent<ScanKey, ScanCommand> convert(final ComponentVulnerabilityAnal
}

static KafkaEvent<String, AnalysisCommand> convert(final ComponentRepositoryMetaAnalysisEvent event) {
if (event == null || event.purlCoordinates() == null) {
if (event == null || event.purl() == null) {
return null;
}

final String key;
try {
key = aPackageURL()
.withType(event.purl().getType())
.withNamespace(event.purl().getNamespace())
.withName(event.purl().getName())
.build()
.toString();
} catch (MalformedPackageURLException e) {
throw new IllegalStateException("Failed to build PURL coordinates without version", e);
}

final var componentBuilder = org.dependencytrack.proto.repometaanalysis.v1.Component.newBuilder()
.setPurl(event.purlCoordinates());
.setPurl(event.purl().toString());
Optional.ofNullable(event.internal()).ifPresent(componentBuilder::setInternal);
Optional.ofNullable(event.componentUuid()).map(UUID::toString).ifPresent(componentBuilder::setUuid);

final var analysisCommand = AnalysisCommand.newBuilder()
.setComponent(componentBuilder)
.setFetchMeta(event.fetchMeta())
.build();

return new KafkaEvent<>(KafkaTopics.REPO_META_ANALYSIS_COMMAND, event.purlCoordinates(), analysisCommand, null);
return new KafkaEvent<>(KafkaTopics.REPO_META_ANALYSIS_COMMAND, key, analysisCommand, null);
}

static KafkaEvent<String, String> convert(final GitHubAdvisoryMirrorEvent ignored) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading