Update everything expect transfers & sftp to not use zap

This commit is contained in:
Dane Everitt 2020-06-13 10:40:26 -07:00
parent 65b1b96b06
commit 7d4a8d7f7e
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
9 changed files with 40 additions and 46 deletions

View File

@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@ -137,11 +136,7 @@ func postServerInstall(c *gin.Context) {
go func(serv *server.Server) { go func(serv *server.Server) {
if err := serv.Install(); err != nil { if err := serv.Install(); err != nil {
zap.S().Errorw( serv.Log().WithField("error", err).Error("failed to execute server installation process")
"failed to execute server installation process",
zap.String("server", serv.Uuid),
zap.Error(err),
)
} }
}(s) }(s)
@ -154,11 +149,7 @@ func postServerReinstall(c *gin.Context) {
go func(serv *server.Server) { go func(serv *server.Server) {
if err := serv.Reinstall(); err != nil { if err := serv.Reinstall(); err != nil {
zap.S().Errorw( serv.Log().WithField("error", err).Error("failed to complete server re-install process")
"failed to complete server reinstall process",
zap.String("server", serv.Uuid),
zap.Error(err),
)
} }
}(s) }(s)
@ -176,7 +167,7 @@ func deleteServer(c *gin.Context) {
// Delete the server's archive if it exists. We intentionally don't return // Delete the server's archive if it exists. We intentionally don't return
// here, if the archive fails to delete, the server can still be removed. // here, if the archive fails to delete, the server can still be removed.
if err := s.Archiver.DeleteIfExists(); err != nil { if err := s.Archiver.DeleteIfExists(); err != nil {
zap.S().Warnw("failed to delete server archive during deletion process", zap.String("server", s.Uuid), zap.Error(err)) s.Log().WithField("error", err).Warn("failed to delete server archive during deletion process")
} }
// Unsubscribe all of the event listeners. // Unsubscribe all of the event listeners.
@ -197,7 +188,10 @@ func deleteServer(c *gin.Context) {
// so we don't want to block the HTTP call while waiting on this. // so we don't want to block the HTTP call while waiting on this.
go func(p string) { go func(p string) {
if err := os.RemoveAll(p); err != nil { if err := os.RemoveAll(p); err != nil {
zap.S().Warnw("failed to remove server files during deletion process", zap.String("path", p), zap.Error(errors.WithStack(err))) log.WithFields(log.Fields{
"path": p,
"error": errors.WithStack(err),
}).Warn("failed to remove server files during deletion process")
} }
}(s.Filesystem.Path()) }(s.Filesystem.Path())

View File

@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"github.com/pterodactyl/wings/server/backup" "github.com/pterodactyl/wings/server/backup"
"go.uber.org/zap"
"net/http" "net/http"
) )
@ -40,7 +39,7 @@ func postServerBackup(c *gin.Context) {
go func(b backup.BackupInterface, serv *server.Server) { go func(b backup.BackupInterface, serv *server.Server) {
if err := serv.Backup(b); err != nil { if err := serv.Backup(b); err != nil {
zap.S().Errorw("failed to generate backup for server", zap.Error(err)) serv.Log().WithField("error", err).Error("failed to generate backup for server")
} }
}(adapter, s) }(adapter, s)

View File

@ -2,10 +2,10 @@ package server
import ( import (
"bufio" "bufio"
"github.com/apex/log"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/server/backup" "github.com/pterodactyl/wings/server/backup"
"go.uber.org/zap"
"os" "os"
"path" "path"
) )
@ -17,16 +17,15 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
rerr, err := r.SendBackupStatus(uuid, ad.ToRequest(successful)) rerr, err := r.SendBackupStatus(uuid, ad.ToRequest(successful))
if rerr != nil || err != nil { if rerr != nil || err != nil {
if err != nil { if err != nil {
zap.S().Errorw( s.Log().WithFields(log.Fields{
"failed to notify panel of backup status due to internal code error", "backup": uuid,
zap.String("backup", s.Uuid), "error": err,
zap.Error(err), }).Error("failed to notify panel of backup status due to internal code error")
)
return err return err
} }
zap.S().Warnw(rerr.String(), zap.String("backup", uuid)) s.Log().WithField("backup", uuid).Warn(rerr.String())
return errors.New(rerr.String()) return errors.New(rerr.String())
} }
@ -66,7 +65,7 @@ func (s *Server) GetIncludedBackupFiles(ignored []string) (*backup.IncludedFiles
// of the server files directory, and use that to generate the backup. // of the server files directory, and use that to generate the backup.
if len(ignored) == 0 { if len(ignored) == 0 {
if i, err := s.getServerwideIgnoredFiles(); err != nil { if i, err := s.getServerwideIgnoredFiles(); err != nil {
zap.S().Warnw("failed to retrieve server ignored files", zap.String("server", s.Uuid), zap.Error(err)) s.Log().WithField("error", err).Warn("failed to retrieve ignored files listing for server")
} else { } else {
ignored = i ignored = i
} }
@ -89,7 +88,10 @@ func (s *Server) Backup(b backup.BackupInterface) error {
ad, err := b.Generate(inc, s.Filesystem.Path()) ad, err := b.Generate(inc, s.Filesystem.Path())
if err != nil { if err != nil {
if notifyError := s.notifyPanelOfBackup(b.Identifier(), &backup.ArchiveDetails{}, false); notifyError != nil { if notifyError := s.notifyPanelOfBackup(b.Identifier(), &backup.ArchiveDetails{}, false); notifyError != nil {
zap.S().Warnw("failed to notify panel of failed backup state", zap.String("backup", b.Identifier()), zap.Error(err)) s.Log().WithFields(log.Fields{
"backup": b.Identifier(),
"error": err,
}).Warn("failed to notify panel of failed backup state")
} }
return errors.WithStack(err) return errors.WithStack(err)

View File

@ -3,9 +3,9 @@ package backup
import ( import (
"archive/tar" "archive/tar"
"context" "context"
"github.com/apex/log"
gzip "github.com/klauspost/pgzip" gzip "github.com/klauspost/pgzip"
"github.com/remeh/sizedwaitgroup" "github.com/remeh/sizedwaitgroup"
"go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"io" "io"
"os" "os"
@ -67,7 +67,7 @@ func (a *Archive) Create(dest string, ctx context.Context) error {
// Attempt to remove the archive if there is an error, report that error to // Attempt to remove the archive if there is an error, report that error to
// the logger if it fails. // the logger if it fails.
if rerr := os.Remove(dest); rerr != nil && !os.IsNotExist(rerr) { if rerr := os.Remove(dest); rerr != nil && !os.IsNotExist(rerr) {
zap.S().Warnw("failed to delete corrupted backup archive", zap.String("location", dest)) log.WithField("location", dest).Warn("failed to delete corrupted backup archive")
} }
return err return err

View File

@ -3,10 +3,10 @@ package backup
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"github.com/apex/log"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"io" "io"
"os" "os"
"path" "path"
@ -121,7 +121,10 @@ func (b *Backup) Details() *ArchiveDetails {
resp, err := b.Checksum() resp, err := b.Checksum()
if err != nil { if err != nil {
zap.S().Errorw("failed to calculate checksum for backup", zap.String("backup", b.Uuid), zap.Error(err)) log.WithFields(log.Fields{
"backup": b.Identifier(),
"error": err,
}).Error("failed to calculate checksum for backup")
} }
checksum = hex.EncodeToString(resp) checksum = hex.EncodeToString(resp)

View File

@ -3,7 +3,7 @@ package backup
import ( import (
"context" "context"
"fmt" "fmt"
"go.uber.org/zap" "github.com/apex/log"
"io" "io"
"net/http" "net/http"
"os" "os"
@ -77,7 +77,10 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) (*http.Response, erro
r.Body = rc r.Body = rc
zap.S().Debugw("uploading backup to remote S3 endpoint", zap.String("endpoint", s.PresignedUrl), zap.Any("headers", r.Header)) log.WithFields(log.Fields{
"endpoint": s.PresignedUrl,
"headers": r.Header,
}).Debug("uploading backup to remote S3 endpoint")
return http.DefaultClient.Do(r) return http.DefaultClient.Do(r)
} }

View File

@ -11,7 +11,6 @@ import (
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/server/backup" "github.com/pterodactyl/wings/server/backup"
ignore "github.com/sabhiram/go-gitignore" ignore "github.com/sabhiram/go-gitignore"
"go.uber.org/zap"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -134,7 +133,7 @@ func (fs *Filesystem) HasSpaceAvailable() bool {
// the cache once we've gotten it. // the cache once we've gotten it.
size, err := fs.DirectorySize("/") size, err := fs.DirectorySize("/")
if err != nil { if err != nil {
zap.S().Warnw("failed to determine directory size", zap.String("server", fs.Server.Uuid), zap.Error(err)) fs.Server.Log().WithField("error", err).Warn("failed to determine root server directory size")
} }
// Always cache the size, even if there is an error. We want to always return that value // Always cache the size, even if there is an error. We want to always return that value

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -98,7 +97,7 @@ func (s *Server) SetState(state string) error {
// to the disk should we forget to do it elsewhere. // to the disk should we forget to do it elsewhere.
go func() { go func() {
if err := saveServerStates(); err != nil { if err := saveServerStates(); err != nil {
zap.S().Warnw("failed to write server states to disk", zap.Error(err)) s.Log().WithField("error", err).Warn("failed to write server states to disk")
} }
}() }()
@ -111,14 +110,14 @@ func (s *Server) SetState(state string) error {
// separate thread as to not block any actions currently taking place in the flow // separate thread as to not block any actions currently taking place in the flow
// that called this function. // that called this function.
if (prevState == ProcessStartingState || prevState == ProcessRunningState) && s.GetState() == ProcessOfflineState { if (prevState == ProcessStartingState || prevState == ProcessRunningState) && s.GetState() == ProcessOfflineState {
zap.S().Infow("detected server as entering a potentially crashed state; running handler", zap.String("server", s.Uuid)) s.Log().Info("detected server as entering a crashed state; running crash handler")
go func(server *Server) { go func(server *Server) {
if err := server.handleServerCrash(); err != nil { if err := server.handleServerCrash(); err != nil {
if IsTooFrequentCrashError(err) { if IsTooFrequentCrashError(err) {
zap.S().Infow("did not restart server after crash; occurred too soon after last", zap.String("server", server.Uuid)) server.Log().Info("did not restart server after crash; occurred too soon after the last")
} else { } else {
zap.S().Errorw("failed to handle server crash state", zap.String("server", server.Uuid), zap.Error(err)) server.Log().WithField("error", err).Error("failed to handle server crash")
} }
} }
}(s) }(s)

View File

@ -5,7 +5,6 @@ import (
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/imdario/mergo" "github.com/imdario/mergo"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap"
) )
// Merges data passed through in JSON form into the existing server object. // Merges data passed through in JSON form into the existing server object.
@ -101,14 +100,10 @@ func (s *Server) runBackgroundActions() {
// yet, do it immediately. // yet, do it immediately.
go func(server *Server) { go func(server *Server) {
if server.Suspended && server.GetState() != ProcessOfflineState { if server.Suspended && server.GetState() != ProcessOfflineState {
zap.S().Infow("server suspended with running process state, terminating now", zap.String("server", server.Uuid)) server.Log().Info("server suspended with running process state, terminating now")
if err := server.Environment.WaitForStop(10, true); err != nil { if err := server.Environment.WaitForStop(10, true); err != nil {
zap.S().Warnw( server.Log().WithField("error", err).Warn("failed to terminate server environment after suspension")
"failed to stop server environment after seeing suspension",
zap.String("server", server.Uuid),
zap.Error(err),
)
} }
} }
}(s) }(s)