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/upstream archivista #58

Merged
merged 2 commits into from
Sep 21, 2023
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
43 changes: 18 additions & 25 deletions cmd/archivista/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ import (
nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/sirupsen/logrus"

"github.com/testifysec/archivista"
"github.com/testifysec/archivista/internal/config"
"github.com/testifysec/archivista/internal/metadatastorage/mysqlstore"
Expand All @@ -49,6 +45,10 @@ import (
"github.com/testifysec/archivista/internal/server"
)

func init() {
logrus.SetFormatter(&nested.Formatter{})
}

func main() {
ctx, cancel := signal.NotifyContext(
context.Background(),
Expand All @@ -59,49 +59,42 @@ func main() {
)
defer cancel()

logrus.SetFormatter(&nested.Formatter{})
log.EnableTracing(true)
ctx = log.WithLog(ctx, logruslogger.New(ctx, map[string]interface{}{"cmd": os.Args[0]}))

if err := debug.Self(); err != nil {
log.FromContext(ctx).Infof("%s", err)
}
startTime := time.Now()

log.FromContext(ctx).Infof("executing phase 1: get config from environment (time since start: %s)", time.Since(startTime))
logrus.Infof("executing phase 1: get config from environment (time since start: %s)", time.Since(startTime))
now := time.Now()

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

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

log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 1: get config from environment")
logrus.WithField("duration", time.Since(now)).Infof("completed phase 1: get config from environment")

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 2: initializing storage clients (time since start: %s)", time.Since(startTime))
logrus.Infof("executing phase 2: initializing storage clients (time since start: %s)", time.Since(startTime))
// ********************************************************************************
now = time.Now()
fileStore, fileStoreCh, err := initObjectStore(ctx, cfg)
if err != nil {
log.FromContext(ctx).Fatalf("error initializing storage clients: %+v", err)
logrus.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)
logrus.Fatalf("error initializing mysql client: %+v", err)
}

log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 3: initializing storage clients")
logrus.WithField("duration", time.Since(now)).Infof("completed phase 3: initializing storage clients")

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 3: create and register http service (time since start: %s)", time.Since(startTime))
logrus.Infof("executing phase 3: create and register http service (time since start: %s)", time.Since(startTime))
// ********************************************************************************
now = time.Now()
server := server.New(mysqlStore, fileStore)
Expand Down Expand Up @@ -134,7 +127,7 @@ func main() {

listener, err := net.Listen(proto, listenAddress)
if err != nil {
log.FromContext(ctx).Fatalf("unable to start http listener: %+v", err)
logrus.Fatalf("unable to start http listener: %+v", err)
}

go func() {
Expand All @@ -143,18 +136,18 @@ func main() {
handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS"}),
handlers.AllowedHeaders([]string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization"}),
)(router)); err != nil {
log.FromContext(ctx).Fatalf("unable to start http server: %+v", err)
logrus.Fatalf("unable to start http server: %+v", err)
}
}()

log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 5: create and register http service")
log.FromContext(ctx).Infof("startup complete (time since start: %s)", time.Since(startTime))
logrus.WithField("duration", time.Since(now)).Infof("completed phase 5: create and register http service")
logrus.Infof("startup complete (time since start: %s)", time.Since(startTime))

<-ctx.Done()
<-fileStoreCh
<-mysqlStoreCh

log.FromContext(ctx).Infof("exiting, uptime: %v", time.Since(startTime))
logrus.Infof("exiting, uptime: %v", time.Since(startTime))
}

func initObjectStore(ctx context.Context, cfg *config.Config) (server.StorerGetter, <-chan error, error) {
Expand Down
37 changes: 10 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ require (
entgo.io/ent v0.11.3
github.com/99designs/gqlgen v0.17.5-0.20220428154617-9250f9ac1f90
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/digitorus/timestamp v0.0.0-20220704143351-8225fba02d52
github.com/digitorus/timestamp v0.0.0-20230220124323-d542479a2425
github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d
github.com/go-sql-driver/mysql v1.6.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-multierror v1.1.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/minio/minio-go v6.0.14+incompatible
github.com/networkservicemesh/sdk v1.6.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.3
github.com/testifysec/archivista-api v0.0.0-20230303165309-a31a92afd132
github.com/testifysec/go-witness v0.1.15
github.com/testifysec/go-witness v0.1.16
github.com/vektah/gqlparser/v2 v2.4.7
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.9
golang.org/x/sync v0.1.0
Expand All @@ -32,56 +31,40 @@ require (
github.com/agext/levenshtein v1.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/digitorus/pkcs7 v0.0.0-20220704143225-a9c8106cbfc6 // indirect
github.com/digitorus/pkcs7 v0.0.0-20230220124406-51331ccfc40f // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-test/deep v1.0.8 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
github.com/zclconf/go-cty v1.12.1 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.9.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.31.0 // indirect
go.opentelemetry.io/otel/trace v1.9.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading