Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use the same logging everywhere #20

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions cmd/archivist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func main() {

cfg := new(config.Config)
if err := cfg.Process(); err != nil {
logrus.Fatal(err)
log.FromContext(ctx).Fatal(err)
}

level, err := logrus.ParseLevel(cfg.LogLevel)
if err != nil {
logrus.Fatalf("invalid log level %s", cfg.LogLevel)
log.FromContext(ctx).Fatalf("invalid log level %s", cfg.LogLevel)
}
logrus.SetLevel(level)

Expand All @@ -109,10 +109,13 @@ func main() {
now = time.Now()
fileStore, fileStoreCh, err := initObjectStore(ctx, cfg)
if err != nil {
logrus.Fatalf("error initializing storage clients: %+v", err)
log.FromContext(ctx).Fatalf("error initializing storage clients: %+v", err)
}

mysqlStore, mysqlStoreCh, err := mysqlstore.New(ctx, cfg.SQLStoreConnectionString)
if err != nil {
log.FromContext(ctx).Fatalf("error initializing mysql client: %+v", err)
}

log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 3: initializing storage clients")
// ********************************************************************************
Expand Down Expand Up @@ -161,7 +164,7 @@ func main() {

gqlListener, err := net.Listen(gqlProto, gqlAddress)
if err != nil {
log.FromContext(ctx).Fatalf("unable to start graphql listener: ", err)
log.FromContext(ctx).Fatalf("unable to start graphql listener: %+v", err)
}

go func() {
Expand Down Expand Up @@ -202,17 +205,18 @@ func initSpiffeConnection(ctx context.Context, cfg *config.Config) []grpc.Server
}
source, err := workloadapi.NewX509Source(ctx, workloadOpts...)
if err != nil {
logrus.Fatalf("error getting x509 source: %+v", err)
log.FromContext(ctx).Fatalf("error getting x509 source: %+v", err)
}
opts := []grpc.ServerOption{
grpc.Creds(credentials.NewTLS(tlsconfig.MTLSServerConfig(source, source, authorizer))),
}

svid, err = source.GetX509SVID()
if err != nil {
logrus.Fatalf("error getting x509 svid: %+v", err)
log.FromContext(ctx).Fatalf("error getting x509 svid: %+v", err)
}
logrus.Infof("SVID: %q", svid.ID)

log.FromContext(ctx).Infof("SVID: %q", svid.ID)
return opts
}

Expand Down
8 changes: 4 additions & 4 deletions internal/metadatastorage/mysqlstore/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"ariga.io/sqlcomment"
"entgo.io/ent/dialect/sql"
"github.com/sirupsen/logrus"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/testifysec/archivist-api/pkg/api/archivist"
"github.com/testifysec/archivist/ent"
"github.com/testifysec/archivist/ent/attestationcollection"
Expand Down Expand Up @@ -72,13 +72,13 @@ func New(ctx context.Context, connectionstring string) (*Store, <-chan error, er
<-ctx.Done()
err := client.Close()
if err != nil {
logrus.WithContext(ctx).Errorf("error closing database: %+v", err)
log.FromContext(ctx).Errorf("error closing database: %+v", err)
}
close(errCh)
}()

if err := client.Schema.Create(ctx); err != nil {
logrus.WithContext(ctx).Fatalf("failed creating schema resources: %v", err)
log.FromContext(ctx).Fatalf("failed creating schema resources: %v", err)
}

return &Store{
Expand Down Expand Up @@ -309,7 +309,7 @@ func (s *Store) Store(ctx context.Context, gitoid string, obj []byte) error {
})

if err != nil {
logrus.Errorf("unable to store metadata: %+v", err)
log.FromContext(ctx).Errorf("unable to store metadata: %+v", err)
return err
}

Expand Down
10 changes: 5 additions & 5 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"io"

"github.com/git-bom/gitbom-go"
"github.com/sirupsen/logrus"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/testifysec/archivist-api/pkg/api/archivist"
)

Expand All @@ -41,7 +41,7 @@ func NewArchivistServer(store MetadataStorer) archivist.ArchivistServer {
func (s *archivistServer) GetBySubjectDigest(request *archivist.GetBySubjectDigestRequest, server archivist.Archivist_GetBySubjectDigestServer) error {
ctx, cancel := context.WithCancel(server.Context())
defer cancel()
logrus.WithContext(ctx).Printf("retrieving by subject... ")
log.FromContext(ctx).Info("retrieving by subject... ")
responses, err := s.store.GetBySubjectDigest(ctx, request)
if err != nil {
return err
Expand Down Expand Up @@ -121,19 +121,19 @@ func (s *collectorServer) Store(server archivist.Collector_StoreServer) error {
// generate gitbom
gb := gitbom.NewSha256GitBom()
if err := gb.AddReference(payload, nil); err != nil {
logrus.WithContext(ctx).Errorf("gitbom tag generation failed: %+v", err)
log.FromContext(ctx).Errorf("gitbom tag generation failed: %+v", err)
return err
}

gitoid := gb.Identity()
if err := s.metadataStore.Store(ctx, gitoid, payload); err != nil {
logrus.WithContext(ctx).Printf("received error from metadata store: %+v", err)
log.FromContext(ctx).Errorf("received error from metadata store: %+v", err)
return err
}

if s.objectStore != nil {
if err := s.objectStore.Store(ctx, gitoid, payload); err != nil {
logrus.WithContext(ctx).Printf("received error from object store: %+v", err)
log.FromContext(ctx).Errorf("received error from object store: %+v", err)
return err
}
}
Expand Down