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

Add buildEnvironment and debug to buildInfo command #218

Merged
merged 16 commits into from
Jan 8, 2022
Merged
8 changes: 8 additions & 0 deletions internal/handlers/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ func TestReadOnlyHandlers(t *testing.T) {
}

hostname, err := os.Hostname()

buildEnvironment := types.MustMakeDocument()
for k, v := range version.Get().BuildEnvironment {
buildEnvironment.Set(k, v)
}
gevorgyg marked this conversation as resolved.
Show resolved Hide resolved

require.NoError(t, err)

testCases := map[string]testCase{
Expand All @@ -434,8 +440,10 @@ func TestReadOnlyHandlers(t *testing.T) {
"gitVersion", version.Get().Commit,
"versionArray", types.MustNewArray(int32(5), int32(0), int32(42), int32(0)),
"bits", int32(strconv.IntSize),
"debug", version.Get().IsDebugBuild,
"maxBsonObjectSize", int32(bson.MaxDocumentLen),
"ok", float64(1),
"buildEnvironment", buildEnvironment,
),
},
"CollStats": {
Expand Down
10 changes: 10 additions & 0 deletions internal/handlers/shared/msg_buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func (h *Handler) MsgBuildInfo(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs
"gitVersion", version.Get().Commit,
"versionArray", types.MustNewArray(int32(5), int32(0), int32(42), int32(0)),
"bits", int32(strconv.IntSize),
"debug", version.Get().IsDebugBuild,
"maxBsonObjectSize", int32(bson.MaxDocumentLen),
"ok", float64(1),
"buildEnvironment", buildEnvironment(),
)},
})
if err != nil {
Expand All @@ -47,3 +49,11 @@ func (h *Handler) MsgBuildInfo(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs

return &reply, nil
}

func buildEnvironment() (buildEnvironment types.Document) {
gevorgyg marked this conversation as resolved.
Show resolved Hide resolved
buildEnvironment = types.MustMakeDocument()
for k, v := range version.Get().BuildEnvironment {
buildEnvironment.Set(k, v)
}
return buildEnvironment
}
16 changes: 13 additions & 3 deletions internal/util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (
var version string

type Info struct {
Version string
Commit string
Dirty bool
Version string
Commit string
Dirty bool
IsDebugBuild bool
BuildEnvironment map[string]string
}

var info *Info
Expand All @@ -48,12 +50,20 @@ func init() {
return
}

info.BuildEnvironment = map[string]string{}
for _, s := range buildInfo.Settings {
info.BuildEnvironment[s.Key] = s.Value
switch s.Key {
case "vcs.revision":
info.Commit = s.Value
case "vcs.modified":
info.Dirty, _ = strconv.ParseBool(s.Value)
case "-race":
info.IsDebugBuild, _ = strconv.ParseBool(s.Value)
gevorgyg marked this conversation as resolved.
Show resolved Hide resolved
case "-tags":
if s.Value == "testcover" {
gevorgyg marked this conversation as resolved.
Show resolved Hide resolved
info.IsDebugBuild = true
}
}
}
}