From 8d320dbf509d80739f37181ee887a70758f6fe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 17:28:57 +0000 Subject: [PATCH 1/6] feat: add additional log fields --- go/porcelain/deploy.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index b8c82064..23a2f106 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -240,8 +240,10 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ - "site_id": options.SiteID, - "deploy_files": len(options.files.Sums), + "site_id": options.SiteID, + "deploy_files": len(options.files.Sums), + "functions": len(functions.Files), + "function_schedules": len(schedules), }).Debug("Starting to deploy files") authInfo := context.GetAuthInfo(ctx) From c15783458b593f386a344298a77166405318a646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 17:39:02 +0000 Subject: [PATCH 2/6] feat: add functions manifest logging --- go/porcelain/deploy.go | 18 ++++++++++-------- go/porcelain/deploy_test.go | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 23a2f106..3214668b 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -212,7 +212,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * options.files = files - functions, schedules, err := bundle(options.FunctionsDir, options.Observer) + functions, schedules, err := bundle(ctx, options.FunctionsDir, options.Observer) if err != nil { if options.Observer != nil { options.Observer.OnFailedWalk() @@ -240,10 +240,8 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ - "site_id": options.SiteID, - "deploy_files": len(options.files.Sums), - "functions": len(functions.Files), - "function_schedules": len(schedules), + "site_id": options.SiteID, + "deploy_files": len(options.files.Sums), }).Debug("Starting to deploy files") authInfo := context.GetAuthInfo(ctx) @@ -582,7 +580,7 @@ func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs return files, err } -func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { if functionDir == "" { return nil, nil, nil } @@ -594,7 +592,7 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models if err == nil { defer manifestFile.Close() - return bundleFromManifest(manifestFile, observer) + return bundleFromManifest(ctx, manifestFile, observer) } functions := newDeployFiles() @@ -640,13 +638,17 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models return functions, nil, nil } -func bundleFromManifest(manifestFile *os.File, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { manifestBytes, err := ioutil.ReadAll(manifestFile) if err != nil { return nil, nil, err } + context.GetLogger(ctx).WithFields(logrus.Fields{ + "manifest": string(manifestBytes), + }).Debug("Found functions manifest file") + var manifest functionsManifest err = json.Unmarshal(manifestBytes, &manifest) diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index 0b5f5f44..7f49d4cd 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -203,7 +203,7 @@ func TestUploadFiles_Cancelation(t *testing.T) { } func TestBundle(t *testing.T) { - functions, schedules, err := bundle("../internal/data", mockObserver{}) + functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err) assert.Equal(t, 3, len(functions.Files)) @@ -247,7 +247,7 @@ func TestBundleWithManifest(t *testing.T) { defer os.Remove(manifestPath) assert.Nil(t, err) - functions, schedules, err := bundle("../internal/data", mockObserver{}) + functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err) From 0f0bfd21e072aaa8f4c4961e448706e037beebc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 18:19:29 +0000 Subject: [PATCH 3/6] feat: add `scheduled_functions` log field --- go/porcelain/deploy.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 3214668b..6f95841c 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -240,8 +240,9 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ - "site_id": options.SiteID, - "deploy_files": len(options.files.Sums), + "site_id": options.SiteID, + "deploy_files": len(options.files.Sums), + "scheduled_functions": len(schedules), }).Debug("Starting to deploy files") authInfo := context.GetAuthInfo(ctx) From 1e3ea9725b6a6f2816089def48354d637c212201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 22:52:16 +0000 Subject: [PATCH 4/6] feat: pass `FunctionSchedules` to deploy --- go/porcelain/deploy.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 6f95841c..0be8ce1d 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -91,7 +91,7 @@ type DeployOptions struct { files *deployFiles functions *deployFiles - functionSchedules []models.FunctionSchedule + functionSchedules []*models.FunctionSchedule } type uploadError struct { @@ -238,6 +238,10 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * } } + if len(schedules) > 0 { + deployFiles.FunctionSchedules = schedules + } + l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ "site_id": options.SiteID, @@ -581,7 +585,7 @@ func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs return files, err } -func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { if functionDir == "" { return nil, nil, nil } @@ -639,7 +643,7 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (* return functions, nil, nil } -func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { manifestBytes, err := ioutil.ReadAll(manifestFile) if err != nil { @@ -658,7 +662,7 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep return nil, nil, fmt.Errorf("malformed functions manifest file: %w", err) } - schedules := make([]models.FunctionSchedule, 0, len(manifest.Functions)) + schedules := make([]*models.FunctionSchedule, 0, len(manifest.Functions)) functions := newDeployFiles() for _, function := range manifest.Functions { @@ -675,7 +679,7 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep } if function.Schedule != "" { - schedules = append(schedules, models.FunctionSchedule{ + schedules = append(schedules, &models.FunctionSchedule{ Cron: function.Schedule, Name: function.Name, }) From c8fc76bc12f2364c85dbd399b97ea85ffebb91c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 23:20:40 +0000 Subject: [PATCH 5/6] refactor: remove `manifest` log field --- go/porcelain/deploy.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 0be8ce1d..308679bd 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -650,9 +650,7 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep return nil, nil, err } - context.GetLogger(ctx).WithFields(logrus.Fields{ - "manifest": string(manifestBytes), - }).Debug("Found functions manifest file") + context.GetLogger(ctx).Debug("Found functions manifest file") var manifest functionsManifest From f043261248376aabeeddff475325b84fb872f9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 3 Jan 2022 23:23:38 +0000 Subject: [PATCH 6/6] refactor: add variable --- go/porcelain/deploy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 308679bd..e62f5755 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -650,7 +650,8 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep return nil, nil, err } - context.GetLogger(ctx).Debug("Found functions manifest file") + logger := context.GetLogger(ctx) + logger.Debug("Found functions manifest file") var manifest functionsManifest