mirror of
https://github.com/goharbor/harbor
synced 2025-04-15 17:26:33 +00:00
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:
parent
7a8a8fa104
commit
7b4c4b76e7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user