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
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/prometheus/common v0.32.1
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.20.0
golang.org/x/exp v0.0.0-20220104160115-025e73f80486
golang.org/x/sys v0.0.0-20211204120058-94396e421777
golang.org/x/text v0.3.7
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220104160115-025e73f80486 h1:gpEOK9kxNqVPOaZayQV2bzetZplXWakHeirk1bXKu2s=
golang.org/x/exp v0.0.0-20220104160115-025e73f80486/go.mod h1:b9TAUYHmRtqA6klRHApnXMnj+OyLce4yF5cZCUbk2ps=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
2 changes: 2 additions & 0 deletions internal/handlers/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,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().Debug,
"maxBsonObjectSize", int32(bson.MaxDocumentLen),
"ok", float64(1),
"buildEnvironment", types.MustMakeDocument(),
),
},

Expand Down
2 changes: 2 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().Debug,
"maxBsonObjectSize", int32(bson.MaxDocumentLen),
"ok", float64(1),
"buildEnvironment", version.Get().BuildEnvironment,
)},
})
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions internal/util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"runtime/debug"
"strconv"
"strings"

"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/internal/types"
)

//go:generate ./generate.sh
Expand All @@ -32,10 +36,12 @@ var (
)

type Info struct {
Version string
Commit string
Branch string
Dirty bool
Version string
Commit string
Branch string
Dirty bool
Debug bool // testcover or -race
BuildEnvironment types.Document
}

var info *Info
Expand All @@ -55,12 +61,22 @@ func init() {
return
}

info.BuildEnvironment = types.MustMakeDocument()
for _, s := range buildInfo.Settings {
info.BuildEnvironment.Set(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":
if raceEnabled, _ := strconv.ParseBool(s.Value); raceEnabled {
info.Debug = true
}
case "-tags":
if slices.Contains(strings.Split(s.Value, ","), "testcover") {
info.Debug = true
}
}
}
}