Skip to content
Merged
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
57 changes: 44 additions & 13 deletions go/internal/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ var reconcileSkipSources = []string{
"cve-osv",
}

// reconcileWarningAsInfoSources is a list of source names to log as INFO instead of WARNING during reconciliation.
var reconcileWarningAsInfoSources = []string{
"minimos",
}

func reconcileWarningsAsInfo(source string) bool {
return slices.Contains(reconcileWarningAsInfoSources, source)
}

// ReconcileLeniencyDuration specifies how long of a time difference before it would be considered an outdated record
// This needs to be some time as importer detecting the change to worker importing it is not instant.
const ReconcileLeniencyDuration = time.Hour * 6
Expand Down Expand Up @@ -325,9 +334,15 @@ func checkReconcile(

dbMod, exists := dbRecords[path]
if !exists {
logger.WarnContext(ctx, "Found missing vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path))
if reconcileWarningsAsInfo(recordTemplate.SourceRepository) {
logger.InfoContext(ctx, "Found missing vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path))
} else {
logger.WarnContext(ctx, "Found missing vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path))
}
// Trigger a standard import
recordTemplate.Action = ActionImport
select {
Expand All @@ -351,11 +366,19 @@ func checkReconcile(
}

if modified.After(dbMod.Add(ReconcileLeniencyDuration)) {
logger.WarnContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path),
slog.Time("database_modified", dbMod),
slog.Time("upstream_modified", modified))
if reconcileWarningsAsInfo(recordTemplate.SourceRepository) {
logger.InfoContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path),
slog.Time("database_modified", dbMod),
slog.Time("upstream_modified", modified))
} else {
logger.WarnContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", recordTemplate.SourceRepository),
slog.String("path", path),
slog.Time("database_modified", dbMod),
slog.Time("upstream_modified", modified))
}

// We found that it is outdated, trigger a standard import
recordTemplate.Action = ActionImport
Expand Down Expand Up @@ -600,11 +623,19 @@ func processUpdate(ctx context.Context, config Config, item WorkItem) {
return
}

logger.WarnContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", sourceRepoName),
slog.String("path", sourcePath),
slog.Time("database_modified", dbModified),
slog.Time("upstream_modified", modified))
if reconcileWarningsAsInfo(sourceRepoName) {
logger.InfoContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", sourceRepoName),
slog.String("path", sourcePath),
slog.Time("database_modified", dbModified),
slog.Time("upstream_modified", modified))
} else {
logger.WarnContext(ctx, "Found outdated vulnerability in database during reconcile",
slog.String("source", sourceRepoName),
slog.String("path", sourcePath),
slog.Time("database_modified", dbModified),
slog.Time("upstream_modified", modified))
}
default:
}
}
Expand Down
20 changes: 20 additions & 0 deletions go/internal/importer/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,23 @@ func TestImporterWorker(t *testing.T) {
t.Errorf("Expected path 4.json, got %s", mockPublisher.Messages[3].Attributes["path"])
}
}

func TestReconcileWarningsAsInfo(t *testing.T) {
tests := []struct {
source string
want bool
}{
{"minimos", true},
{"git", false},
{"cve-osv", false},
{"random", false},
}

for _, tt := range tests {
t.Run(tt.source, func(t *testing.T) {
if got := reconcileWarningsAsInfo(tt.source); got != tt.want {
t.Errorf("reconcileWarningsAsInfo(%q) = %v, want %v", tt.source, got, tt.want)
}
})
}
}
Loading