mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 20:59:10 +01:00
Merge pull request #11368 from heww/fix-ongoing-of-metrics
fix(scan): ongoing is true for schedule scan all only when job is running
This commit is contained in:
commit
c2c9fa28eb
@ -127,7 +127,7 @@ func (sc *ScanAllAPI) getMetrics(kind string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setOngoing(sts, aj.Status)
|
setOngoing(sts, aj.Status, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return empty
|
// Return empty
|
||||||
@ -155,14 +155,18 @@ func isScanEnabled() (bool, error) {
|
|||||||
return len(l) > 0, nil
|
return len(l) > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOngoing(stats *all.Stats, st string) {
|
func setOngoing(stats *all.Stats, jobStatus, jobKind string) {
|
||||||
status := job.PendingStatus
|
status := job.PendingStatus
|
||||||
|
|
||||||
if st == cm.JobFinished {
|
if jobStatus == cm.JobFinished {
|
||||||
status = job.SuccessStatus
|
status = job.SuccessStatus
|
||||||
} else {
|
} else {
|
||||||
status = job.Status(strings.ToTitle(st))
|
status = job.Status(strings.Title(jobStatus))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if jobKind == common_job.JobKindPeriodic {
|
||||||
|
stats.Ongoing = (status == job.RunningStatus) || stats.Total != stats.Completed
|
||||||
|
} else if jobKind == common_job.JobKindGeneric {
|
||||||
stats.Ongoing = !status.Final() || stats.Total != stats.Completed
|
stats.Ongoing = !status.Final() || stats.Total != stats.Completed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -17,6 +17,9 @@ package api
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
common_job "github.com/goharbor/harbor/src/common/job"
|
||||||
|
cm "github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/scan/all"
|
||||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
||||||
sc "github.com/goharbor/harbor/src/pkg/scan/scanner"
|
sc "github.com/goharbor/harbor/src/pkg/scan/scanner"
|
||||||
"github.com/goharbor/harbor/src/testing/apitests/apilib"
|
"github.com/goharbor/harbor/src/testing/apitests/apilib"
|
||||||
@ -80,3 +83,53 @@ func (suite *ScanAllAPITestSuite) TestScanAllGet() {
|
|||||||
require.NoError(suite.T(), err, "Error occurred while get a scan all job")
|
require.NoError(suite.T(), err, "Error occurred while get a scan all job")
|
||||||
suite.Equal(200, code, "Get scan all status should be 200")
|
suite.Equal(200, code, "Get scan all status should be 200")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ScanAllAPITestSuite) TestSetOngoing() {
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobPending, common_job.JobKindPeriodic)
|
||||||
|
suite.False(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobRunning, common_job.JobKindPeriodic)
|
||||||
|
suite.True(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobFinished, common_job.JobKindPeriodic)
|
||||||
|
suite.False(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobError, common_job.JobKindPeriodic)
|
||||||
|
suite.False(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobPending, common_job.JobKindGeneric)
|
||||||
|
suite.True(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobRunning, common_job.JobKindGeneric)
|
||||||
|
suite.True(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobFinished, common_job.JobKindGeneric)
|
||||||
|
suite.False(stats.Ongoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
stats := &all.Stats{}
|
||||||
|
setOngoing(stats, cm.JobError, common_job.JobKindGeneric)
|
||||||
|
suite.False(stats.Ongoing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user