Skip to content

Commit

Permalink
RSDK-8722 - Log RDK version to cloud (viamrobotics#4358)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheukt authored Sep 9, 2024
1 parent a0cd8bd commit 0146b5d
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions web/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ type robotServer struct {
logger logging.Logger
}

func logVersion(logger logging.Logger) {
var versionFields []interface{}
if config.Version != "" {
versionFields = append(versionFields, "version", config.Version)
}
if config.GitRevision != "" {
versionFields = append(versionFields, "git_rev", config.GitRevision)
}
if len(versionFields) != 0 {
logger.Infow("Viam RDK", versionFields...)
} else {
logger.Info("Viam RDK built from source; version unknown")
}
}

// RunServer is an entry point to starting the web server that can be called by main in a code
// sample or otherwise be used to initialize the server.
func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error) {
Expand Down Expand Up @@ -85,24 +100,21 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)

config.InitLoggingSettings(logger, argsParsed.Debug)

// Always log the version, return early if the '-version' flag was provided
// fmt.Println would be better but fails linting. Good enough.
var versionFields []interface{}
if config.Version != "" {
versionFields = append(versionFields, "version", config.Version)
}
if config.GitRevision != "" {
versionFields = append(versionFields, "git_rev", config.GitRevision)
}
if len(versionFields) != 0 {
logger.Infow("Viam RDK", versionFields...)
} else {
logger.Info("Viam RDK built from source; version unknown")
}
if argsParsed.Version {
// log version here and return if version flag.
logVersion(logger)
return
}

// log version locally if server fails and exits while attempting to start up
var versionLogged bool
defer func() {
if !versionLogged {
logger.CInfo(ctx, "error starting viam-server, logging version and exiting")
logVersion(logger)
}
}()

if argsParsed.ConfigFile == "" {
logger.Error("please specify a config file through the -config parameter.")
return
Expand Down Expand Up @@ -155,6 +167,9 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)

logger.AddAppender(netAppender)
}
// log version after netlogger is initialized so it's captured in cloud machine logs.
logVersion(logger)
versionLogged = true

server := robotServer{
logger: logger,
Expand Down

0 comments on commit 0146b5d

Please sign in to comment.