[MM-54132] Use annotated logger for log messages from jobs (#24275)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fcfcbd9909
Коммит
30b12f199b
@@ -138,7 +138,10 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
job, err := messageExportI.StartSynchronizeJob(ctx, startTime)
|
||||
c := request.EmptyContext(a.Log())
|
||||
c.SetContext(ctx)
|
||||
|
||||
job, err := messageExportI.StartSynchronizeJob(c, startTime)
|
||||
if err != nil || job.Status == model.JobStatusError || job.Status == model.JobStatusCanceled {
|
||||
CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
||||
|
||||
@@ -275,16 +276,20 @@ func (s *MmctlE2ETestSuite) TestExportDownloadCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestExportJobShowCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
job, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job.Logger = nil
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
s.Run("MM-T3885 - no permissions", func() {
|
||||
printer.Clean()
|
||||
|
||||
job1, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job1, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
@@ -317,6 +322,7 @@ func (s *MmctlE2ETestSuite) TestExportJobShowCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestExportJobListCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
s.Run("MM-T3887 - no permissions", func() {
|
||||
printer.Clean()
|
||||
@@ -356,24 +362,26 @@ func (s *MmctlE2ETestSuite) TestExportJobListCmdF() {
|
||||
cmd.Flags().Int("per-page", perPage, "")
|
||||
cmd.Flags().Bool("all", false, "")
|
||||
|
||||
_, appErr := s.th.App.CreateJob(&model.Job{
|
||||
_, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job2, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job2, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job2.Logger = nil
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job3, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job3, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job3.Logger = nil
|
||||
|
||||
err := exportJobListCmdF(c, cmd, nil)
|
||||
s.Require().Nil(err)
|
||||
@@ -386,13 +394,14 @@ func (s *MmctlE2ETestSuite) TestExportJobListCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestExportJobCancelCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
s.Run("Cancel an export job without permissions", func() {
|
||||
printer.Clean()
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
|
||||
job, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
@@ -421,14 +430,14 @@ func (s *MmctlE2ETestSuite) TestExportJobCancelCmdF() {
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
|
||||
job1, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job1, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job2, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job2, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
@@ -439,11 +448,11 @@ func (s *MmctlE2ETestSuite) TestExportJobCancelCmdF() {
|
||||
s.Require().Empty(printer.GetErrorLines())
|
||||
|
||||
// Get job1 again to refresh its status
|
||||
job1, appErr = s.th.App.GetJob(job1.Id)
|
||||
job1, appErr = s.th.App.GetJob(ctx, job1.Id)
|
||||
s.Require().Nil(appErr)
|
||||
|
||||
// Get job2 again to ensure its status did not change
|
||||
job2, _ = s.th.App.GetJob(job2.Id)
|
||||
job2, _ = s.th.App.GetJob(ctx, job2.Id)
|
||||
s.Require().Nil(appErr)
|
||||
|
||||
s.Require().Equal(job1.Status, model.JobStatusCanceled)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
||||
|
||||
@@ -70,17 +71,19 @@ func (s *MmctlE2ETestSuite) TestExtractRunCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestExtractJobShowCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
job, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job.Logger = nil
|
||||
|
||||
s.Run("no permissions", func() {
|
||||
printer.Clean()
|
||||
|
||||
job1, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job1, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{},
|
||||
})
|
||||
@@ -116,6 +119,7 @@ func (s *MmctlE2ETestSuite) TestExtractJobShowCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestExtractJobListCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
s.Run("no permissions", func() {
|
||||
printer.Clean()
|
||||
@@ -156,7 +160,7 @@ func (s *MmctlE2ETestSuite) TestExtractJobListCmdF() {
|
||||
cmd.Flags().Int("per-page", perPage, "")
|
||||
cmd.Flags().Bool("all", false, "")
|
||||
|
||||
_, appErr := s.th.App.CreateJob(&model.Job{
|
||||
_, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{},
|
||||
})
|
||||
@@ -164,19 +168,23 @@ func (s *MmctlE2ETestSuite) TestExtractJobListCmdF() {
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job2, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job2, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job2.Logger = nil
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job3, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job3, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job3.Logger = nil
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
err := extractJobListCmdF(c, cmd, nil)
|
||||
s.Require().Nil(err)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
||||
|
||||
@@ -250,17 +251,19 @@ func (s *MmctlE2ETestSuite) TestImportListIncompleteCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestImportJobShowCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
job, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{"import_file": "import1.zip"},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job.Logger = nil
|
||||
|
||||
s.Run("no permissions", func() {
|
||||
printer.Clean()
|
||||
|
||||
job1, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job1, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{"import_file": "import1.zip"},
|
||||
})
|
||||
@@ -296,6 +299,7 @@ func (s *MmctlE2ETestSuite) TestImportJobShowCmdF() {
|
||||
|
||||
func (s *MmctlE2ETestSuite) TestImportJobListCmdF() {
|
||||
s.SetupTestHelper().InitBasic()
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
s.Run("no permissions", func() {
|
||||
printer.Clean()
|
||||
@@ -336,7 +340,7 @@ func (s *MmctlE2ETestSuite) TestImportJobListCmdF() {
|
||||
cmd.Flags().Int("per-page", perPage, "")
|
||||
cmd.Flags().Bool("all", false, "")
|
||||
|
||||
_, appErr := s.th.App.CreateJob(&model.Job{
|
||||
_, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{"import_file": "import1.zip"},
|
||||
})
|
||||
@@ -344,19 +348,21 @@ func (s *MmctlE2ETestSuite) TestImportJobListCmdF() {
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job2, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job2, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{"import_file": "import2.zip"},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job2.Logger = nil
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
job3, appErr := s.th.App.CreateJob(&model.Job{
|
||||
job3, appErr := s.th.App.CreateJob(ctx, &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{"import_file": "import3.zip"},
|
||||
})
|
||||
s.Require().Nil(appErr)
|
||||
job3.Logger = nil
|
||||
|
||||
err := importJobListCmdF(c, cmd, nil)
|
||||
s.Require().Nil(err)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/api4"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -51,6 +52,7 @@ func configForLdap(th *api4.TestHelper) {
|
||||
func (s *MmctlE2ETestSuite) TestLdapSyncCmd() {
|
||||
s.SetupEnterpriseTestHelper().InitBasic()
|
||||
configForLdap(s.th)
|
||||
ctx := request.EmptyContext(s.th.App.Log())
|
||||
|
||||
s.Run("MM-T3971 Should not allow regular user to sync LDAP groups", func() {
|
||||
printer.Clean()
|
||||
@@ -64,7 +66,7 @@ func (s *MmctlE2ETestSuite) TestLdapSyncCmd() {
|
||||
s.RunForSystemAdminAndLocal("MM-T2529 Should sync LDAP groups", func(c client.Client) {
|
||||
printer.Clean()
|
||||
|
||||
jobs, appErr := s.th.App.GetJobsByTypePage(model.JobTypeLdapSync, 0, 100)
|
||||
jobs, appErr := s.th.App.GetJobsByTypePage(ctx, model.JobTypeLdapSync, 0, 100)
|
||||
s.Require().Nil(appErr)
|
||||
initialNumJobs := len(jobs)
|
||||
|
||||
@@ -78,7 +80,7 @@ func (s *MmctlE2ETestSuite) TestLdapSyncCmd() {
|
||||
// we need to wait a bit for job creation
|
||||
time.Sleep(time.Second)
|
||||
|
||||
jobs, appErr = s.th.App.GetJobsByTypePage(model.JobTypeLdapSync, 0, 100)
|
||||
jobs, appErr = s.th.App.GetJobsByTypePage(ctx, model.JobTypeLdapSync, 0, 100)
|
||||
s.Require().Nil(appErr)
|
||||
s.Require().NotEmpty(jobs)
|
||||
s.Assert().Equal(initialNumJobs+1, len(jobs))
|
||||
|
||||
Ссылка в новой задаче
Block a user