feat: add trigger to the metrics of the scan all job (#13838)

Add the trigger to the metrics of the scan all job so that the customer
can know who trigger the latest scan all job.

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2020-12-24 14:30:43 +08:00 committed by GitHub
parent 7a8a8fa104
commit 7b4c4b76e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -3753,3 +3753,10 @@ definitions:
type: boolean
description: A flag indicating job status of scan all.
x-omitempty: false
trigger:
type: string
description: The trigger of the scan all job.
enum:
- Manual
- Schedule
- Event

View File

@ -17,6 +17,7 @@ package handler
import (
"context"
"fmt"
"strings"
"github.com/go-openapi/runtime/middleware"
"github.com/goharbor/harbor/src/controller/scan"
@ -192,18 +193,30 @@ func (s *scanAllAPI) getMetrics(ctx context.Context, trigger ...string) (*models
}
sts := &models.Stats{}
if execution != nil && execution.Metrics != nil {
if execution != nil {
metrics := execution.Metrics
sts.Total = metrics.TaskCount
sts.Completed = metrics.SuccessTaskCount
sts.Metrics = map[string]int64{
"Pending": metrics.PendingTaskCount,
"Running": metrics.RunningTaskCount,
"Success": metrics.SuccessTaskCount,
"Error": metrics.ErrorTaskCount,
"Stopped": metrics.StoppedTaskCount,
}
sts.Ongoing = !job.Status(execution.Status).Final() || sts.Total != sts.Completed
sts.Trigger = strings.Title(strings.ToLower(execution.Trigger))
if execution.Metrics != nil {
sts.Metrics = map[string]int64{
"Pending": metrics.PendingTaskCount,
"Running": metrics.RunningTaskCount,
"Success": metrics.SuccessTaskCount,
"Error": metrics.ErrorTaskCount,
"Stopped": metrics.StoppedTaskCount,
}
} else {
sts.Metrics = map[string]int64{
"Pending": 0,
"Running": 0,
"Success": 0,
"Error": 0,
"Stopped": 0,
}
}
}
return sts, nil