Skip to content

Commit 336f7a9

Browse files
authored
Merge pull request #11 from Acmarr/main
NVSHAS-8057 added unhandled 500 case, verbose logging
2 parents e997201 + 151f9e5 commit 336f7a9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

server/server.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const reportSuffixURL = "/report"
2828
const dataCheckInterval = 1.0
2929

3030
const rpcTimeout = time.Minute * 20
31-
const expirationTime = time.Minute * 60
31+
const expirationTime = time.Minute * 25
3232
const pruneTime = time.Minute * 5
3333

3434
var workloadID Counter
@@ -243,6 +243,10 @@ func processQueue() {
243243
func processScanTask(scanRequest ScanRequest) {
244244
client, err := GetControllerServiceClient(serverConfig.ControllerIP, serverConfig.ControllerPort)
245245
if err != nil {
246+
reportCache.Lock()
247+
report := reportCache.ScanReports[scanRequest.WorkloadID]
248+
report.Status = http.StatusInternalServerError
249+
reportCache.Unlock()
246250
log.WithFields(log.Fields{"error": err}).Error("Error retrieving rpc client")
247251
return
248252
}
@@ -267,7 +271,7 @@ func processScanTask(scanRequest ScanRequest) {
267271
concurrentJobs.Decrement()
268272

269273
reportCache.Lock()
270-
log.WithFields(log.Fields{"workloadId": scanRequest.WorkloadID}).Debug("Scan sent to controller")
274+
log.WithFields(log.Fields{"workloadId": scanRequest.WorkloadID, "artifact": scanRequest.Artifact, "registry": scanRequest.Registry}).Debug("Scan request forwarded to controller")
271275
reportCache.ScanReports[scanRequest.WorkloadID] = convertRPCReportToScanReport(result)
272276
reportCache.Unlock()
273277
}
@@ -382,15 +386,19 @@ func scanResult(w http.ResponseWriter, req *http.Request) {
382386
log.WithFields(log.Fields{"error": err}).Error("json encoder error")
383387
w.WriteHeader(http.StatusInternalServerError)
384388
}
389+
log.WithFields(log.Fields{"id": id}).Debug("Scan report sent to Harbor")
390+
delete(reportCache.ScanReports, id)
391+
case http.StatusInternalServerError:
392+
log.WithFields(log.Fields{"id": id}).Debug("returned http 500 for workload id")
393+
http.Error(w, "NV Internal Server Error", http.StatusInternalServerError)
385394
delete(reportCache.ScanReports, id)
386395
default:
387396
w.Header().Add("Location", req.URL.String())
388397
w.WriteHeader(val.Status)
389398
}
390399
} else {
391400
w.Header().Add("Location", req.URL.String())
392-
w.Header().Add("Refresh-After", "60")
393-
w.WriteHeader(302)
401+
w.WriteHeader(http.StatusNotFound)
394402
}
395403
reportCache.Unlock()
396404
}

0 commit comments

Comments
 (0)