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

feat: add server debug info #3988

Merged
merged 1 commit into from
Aug 27, 2024
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
24 changes: 12 additions & 12 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ func (app *App) initAnalytics(configFromDB config.Config) error {
return analytics.Init(configFromDB.IsAnalyticsEnabled(), app.serverID, version.Version, version.Env, app.cfg.AnalyticsServerKey(), app.cfg.AnalyticsFrontendKey())
}

// instanceID is a temporary ID for this instance of the server
// it is regenerated on every start intentionally
var instanceID = id.GenerateID().String()

func (app *App) Start(opts ...appOption) error {
// instanceID is a temporary ID for this instance of the server
// it is regenerated on every start intentionally
for _, opt := range opts {
opt(app)
}
Expand All @@ -153,18 +153,18 @@ func (app *App) Start(opts ...appOption) error {

poolcfg, err := pgxpool.ParseConfig(app.cfg.PostgresConnString())
if err != nil {
return err
return fmt.Errorf("could not parse postgres connection string: %w", err)
}
poolcfg.MaxConns = 20

pool, err := pgxpool.NewWithConfig(context.Background(), poolcfg)
if err != nil {
return err
return fmt.Errorf("could not create postgres connection pool: %w", err)
}

db, err := testdb.Connect(app.cfg.PostgresConnString())
if err != nil {
return err
return fmt.Errorf("could not connect to postgres: %w", err)
}
db.SetMaxOpenConns(80)

Expand All @@ -173,7 +173,7 @@ func (app *App) Start(opts ...appOption) error {
)

if err != nil {
log.Fatal(err)
log.Fatal(fmt.Errorf("could not create testdb: %w", err))
}

natsConn, err := nats.Connect(app.cfg.NATSEndpoint())
Expand All @@ -189,12 +189,12 @@ func (app *App) Start(opts ...appOption) error {

tracer, err := telemetry.NewTracer(ctx, app.cfg)
if err != nil {
log.Fatal(err)
log.Fatal(fmt.Errorf("could not create tracer: %w", err))
}

meter, err := telemetry.NewMeter(ctx, app.cfg)
if err != nil {
log.Fatal(err)
log.Fatal(fmt.Errorf("could not create meter: %w", err))
}

app.registerStopFn(func() {
Expand All @@ -204,20 +204,20 @@ func (app *App) Start(opts ...appOption) error {

serverID, isNewInstall, err := testDB.ServerID()
if err != nil {
return err
return fmt.Errorf("could not get server ID: %w", err)
}
app.serverID = serverID

err = app.initAnalytics(configFromDB)
if err != nil {
return err
return fmt.Errorf("could not init analytics: %w", err)
}

fmt.Println("New install?", isNewInstall)
if isNewInstall {
err = analytics.SendEvent("Install", "beacon", "", nil)
if err != nil {
return err
return fmt.Errorf("could not send install event: %w", err)
}
}

Expand Down Expand Up @@ -304,7 +304,7 @@ func (app *App) Start(opts ...appOption) error {

err = analytics.SendEvent("Server Started", "beacon", "", nil)
if err != nil {
return err
return fmt.Errorf("could not send server started event: %w", err)
}

provisioner := provisioning.New()
Expand Down
4 changes: 2 additions & 2 deletions server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
var err error
appInstance, err = app.New(cfg)
if err != nil {
return err
return fmt.Errorf("cannot create app instance: %w", err)
}

return nil
Expand All @@ -44,7 +44,7 @@ func init() {
config.WithLogger(log.Default()),
)
if err != nil {
fmt.Println(err.Error())
fmt.Println("error loading config:", err.Error())
os.Exit(1)
}
})
Expand Down
2 changes: 2 additions & 0 deletions server/cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -45,6 +46,7 @@ var serveCmd = &cobra.Command{
wg.Add(1)
err := appInstance.Start(app.WithProvisioningFile(provisioningFile))
if err != nil {
fmt.Println("Error starting server:", err.Error())
return err
}

Expand Down
2 changes: 1 addition & 1 deletion server/config/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func New(confOpts ...Option) (*AppConfig, error) {

err = cfg.vp.Unmarshal(&cfg.config)
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot unmarshal config: %w", err)
}

if err := cfg.Validate(); err != nil {
Expand Down
Loading