From 38aa43885b1c60380d904b56c172b0e6994625e7 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 14 Nov 2017 13:04:06 -0500 Subject: [PATCH 1/5] Log when starting a backup Signed-off-by: Andy Goldstein --- pkg/controller/backup_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index 06e1290cf..88b47a524 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -316,6 +316,7 @@ func (controller *backupController) runBackup(backup *api.Backup, bucket string) err = kuberrs.NewAggregate(errs) }() + controller.logger.WithField("backup", kubeutil.NamespaceAndName(backup)).Info("starting backup") if err := controller.backupper.Backup(backup, backupFile, logFile); err != nil { return err } From 34a6f492e571f30c99904a7684a1bdfce6364eb2 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 14 Nov 2017 13:11:00 -0500 Subject: [PATCH 2/5] Log restore start/end Signed-off-by: Andy Goldstein --- pkg/controller/restore_controller.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 54a008d7d..adea632af 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -391,7 +391,9 @@ func (controller *restoreController) runRestore(restore *api.Restore, bucket str } }() + logContext.Info("starting restore") restoreWarnings, restoreErrors = controller.restorer.Restore(restore, backup, backupFile, logFile) + logContext.Info("restore completed") // Try to upload the log file. This is best-effort. If we fail, we'll add to the ark errors. From af189fd5f4333d63c91fcc025a8f219f5c2cb160 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 14 Nov 2017 13:17:20 -0500 Subject: [PATCH 3/5] Add error & logSource hooks to backup & restore loggers Signed-off-by: Andy Goldstein --- pkg/backup/backup.go | 3 +++ pkg/restore/restore.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index db2114808..623e829fe 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -35,6 +35,7 @@ import ( "github.com/heptio/ark/pkg/discovery" "github.com/heptio/ark/pkg/util/collections" kubeutil "github.com/heptio/ark/pkg/util/kube" + "github.com/heptio/ark/pkg/util/logging" ) // Backupper performs backups. @@ -183,6 +184,8 @@ func (kb *kubernetesBackupper) Backup(backup *api.Backup, backupFile, logFile io logger := logrus.New() logger.Out = gzippedLog + logger.Hooks.Add(&logging.ErrorLocationHook{}) + logger.Hooks.Add(&logging.LogLocationHook{}) log := logger.WithField("backup", kubeutil.NamespaceAndName(backup)) log.Info("Starting backup") diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index e02186ec9..f31779100 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -46,6 +46,7 @@ import ( "github.com/heptio/ark/pkg/restore/restorers" "github.com/heptio/ark/pkg/util/collections" "github.com/heptio/ark/pkg/util/kube" + "github.com/heptio/ark/pkg/util/logging" ) // Restorer knows how to restore a backup. @@ -207,6 +208,8 @@ func (kr *kubernetesRestorer) Restore(restore *api.Restore, backup *api.Backup, log := logrus.New() log.Out = gzippedLog + log.Hooks.Add(&logging.ErrorLocationHook{}) + log.Hooks.Add(&logging.LogLocationHook{}) ctx := &context{ backup: backup, From 4c481f4d231a594b20e71475d9aa92d35ff85468 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 14 Nov 2017 13:24:50 -0500 Subject: [PATCH 4/5] Make logSource more concise Strip off leading .../github.com/heptio/ark/ Signed-off-by: Andy Goldstein --- pkg/util/logging/log_location_hook.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/util/logging/log_location_hook.go b/pkg/util/logging/log_location_hook.go index 6362a9471..428627e46 100644 --- a/pkg/util/logging/log_location_hook.go +++ b/pkg/util/logging/log_location_hook.go @@ -27,6 +27,9 @@ import ( const ( logSourceField = "logSource" logSourceSetMarkerField = "@logSourceSetBy" + logrusPackage = "github.com/sirupsen/logrus" + arkPackage = "github.com/heptio/ark" + arkPackageLen = len(arkPackage) ) // LogLocationHook is a logrus hook that attaches location information @@ -73,7 +76,7 @@ func (h *LogLocationHook) Fire(entry *logrus.Entry) error { for more { frame, more = frames.Next() - if strings.Contains(frame.File, "github.com/sirupsen/logrus") { + if strings.Contains(frame.File, logrusPackage) { continue } @@ -87,7 +90,13 @@ func (h *LogLocationHook) Fire(entry *logrus.Entry) error { // we're in Ark server and not logging something that has the marker // set (which would indicate the log statement is coming from a plugin). if h.loggerName != "" || getLogSourceSetMarker(entry) == "" { - entry.Data[logSourceField] = fmt.Sprintf("%s:%d", frame.File, frame.Line) + file := frame.File + if index := strings.Index(file, arkPackage); index != -1 { + // strip off .../github.com/heptio/ark/ so we just have pkg/... + file = frame.File[index+arkPackageLen+1:] + } + + entry.Data[logSourceField] = fmt.Sprintf("%s:%d", file, frame.Line) } // if we're in the Ark server, remove the marker field since we don't From eb6f1a7b5cd825f575e775672c10065ac45a87e3 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 14 Nov 2017 14:24:33 -0500 Subject: [PATCH 5/5] Fix minio config Signed-off-by: Andy Goldstein --- examples/minio/10-ark-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/minio/10-ark-config.yaml b/examples/minio/10-ark-config.yaml index 4b3451177..fde7cbc9c 100644 --- a/examples/minio/10-ark-config.yaml +++ b/examples/minio/10-ark-config.yaml @@ -23,7 +23,7 @@ backupStorageProvider: bucket: ark config: region: minio - s3ForcePathStyle: true + s3ForcePathStyle: "true" s3Url: http://minio:9000 backupSyncPeriod: 1m gcSyncPeriod: 1m