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

RSDK-8722 - Log RDK version to cloud #4358

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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: 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
Loading