Skip to content

Commit

Permalink
JobService: fix for missing log data in jobservice DB logging (#20684)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent 27e06ac commit cc1acc3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jobservice/logger/getter/db_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions src/jobservice/logger/getter/db_getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cc1acc3

Please sign in to comment.