JobService: fix for missing log data in jobservice DB logging (#20684)

* 20548 MISSING CONDITION FOR RETURNING LOG DATA

As per bug 20548, if DB logging is enabled for jobservice and the parameter is also set for maximum log size
the log data is not being returned and 'Clean Up->Show GC Logs' shows a blank page

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
Co-authored-by: Nick Hindley <no-reply@example.com>

* db_getter_test.go: test fix for missing log data in jobservice DB logging

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>

---------

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
Co-authored-by: Nick Hindley <no-reply@example.com>
Co-authored-by: Shengwen YU <yshengwen@vmware.com>
This commit is contained in:
Mohamed Awnallah 2024-07-04 06:30:03 +03:00 committed by GitHub
parent 27e06ac609
commit cc1acc3890
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -47,7 +47,7 @@ func (dbg *DBGetter) Retrieve(logID string) ([]byte, error) {
sz := int64(len(jobLog.Content))
var buf []byte
sizeLimit := logSizeLimit()
if sizeLimit <= 0 {
if sizeLimit <= 0 || sz <= sizeLimit {
buf = []byte(jobLog.Content)
return buf, nil
}

View File

@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/jobservice/config"
"github.com/goharbor/harbor/src/jobservice/logger/backend"
"github.com/goharbor/harbor/src/jobservice/logger/sweeper"
"github.com/goharbor/harbor/src/lib/log"
@ -44,9 +45,11 @@ func TestDBGetter(t *testing.T) {
err = l.Close()
require.NoError(t, err)
_ = config.DefaultConfig.Load("../../config_test.yml", true)
dbGetter := NewDBGetter()
ll, err := dbGetter.Retrieve(uuid)
require.Nil(t, err)
require.NotEqual(t, 0, len(ll))
log.Infof("get logger %s", ll)
err = sweeper.PrepareDBSweep()