diff --git a/.gitignore b/.gitignore index c843eea5f54..86d805d9d28 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,3 @@ # Fossa .fossa.yml -# Build info -build/info/data.json - diff --git a/.goreleaser.yml b/.goreleaser.yml index 47656aacad3..3bc6cacfb3a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,7 +1,6 @@ before: hooks: - go mod download - - ./develop/scripts/create_build_info_data.sh archives: - id: default diff --git a/Makefile b/Makefile index 47fce43f82c..eafc5ad3449 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,6 @@ clean-bins: temporal-server: @printf $(COLOR) "Build temporal-server with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..." - @./develop/scripts/create_build_info_data.sh go build -o temporal-server ./cmd/server temporal-cassandra-tool: diff --git a/build/cgo/cgo.go b/build/cgo/cgo.go deleted file mode 100644 index 161df7613ae..00000000000 --- a/build/cgo/cgo.go +++ /dev/null @@ -1,31 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -//go:build cgo - -package cgo - -const ( - Enabled = true -) diff --git a/build/cgo/nocgo.go b/build/cgo/nocgo.go deleted file mode 100644 index 1ea0850fb0e..00000000000 --- a/build/cgo/nocgo.go +++ /dev/null @@ -1,31 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -//go:build !cgo - -package cgo - -const ( - Enabled = false -) diff --git a/build/info/empty b/build/info/empty deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cmd/server/main.go b/cmd/server/main.go index d632e19c460..3260ca2f6f4 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -29,14 +29,13 @@ import ( stdlog "log" "os" "path" - "runtime" "strings" _ "time/tzdata" // embed tzdata as a fallback "github.com/urfave/cli/v2" - "go.temporal.io/server/build" "go.temporal.io/server/common/authorization" + "go.temporal.io/server/common/build" "go.temporal.io/server/common/config" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/headers" @@ -133,13 +132,15 @@ func buildCLI() *cli.App { } logger := log.NewZapLogger(log.BuildZapLogger(cfg.Log)) - logger.Info("Build info", - tag.Timestamp(build.InfoData.BuildTime()), + logger.Info("Build info.", + tag.NewTimeTag("git-time", build.InfoData.GitTime), tag.NewStringTag("git-revision", build.InfoData.GitRevision), - tag.NewStringTag("platform", runtime.GOARCH), - tag.NewStringTag("go-version", runtime.Version()), - tag.NewStringTag("server-version", headers.ServerVersion), + tag.NewBoolTag("git-modified", build.InfoData.GitModified), + tag.NewStringTag("go-arch", build.InfoData.GoArch), + tag.NewStringTag("go-os", build.InfoData.GoOs), + tag.NewStringTag("go-version", build.InfoData.GoVersion), tag.NewBoolTag("cgo-enabled", build.InfoData.CgoEnabled), + tag.NewStringTag("server-version", headers.ServerVersion), ) var dynamicConfigClient dynamicconfig.Client diff --git a/build/build.go b/common/build/build.go similarity index 64% rename from build/build.go rename to common/build/build.go index 4f1ddf53f67..b875f11084c 100644 --- a/build/build.go +++ b/common/build/build.go @@ -25,48 +25,56 @@ package build import ( - "embed" - "encoding/json" + "runtime/debug" "time" - - "go.temporal.io/server/build/cgo" -) - -const ( - buildInfoDataFile = "info/data.json" ) type ( Info struct { - // GitRevision is the git revision associated with this build. - GitRevision string - // BuildTimeUnix is the seconds since epoch representing the date this build was created. - BuildTimeUnix int64 + Available bool + GoVersion string + GoArch string + GoOs string // CgoEnabled indicates whether cgo was enabled when this build was created. CgoEnabled bool + + // GitRevision is the git revision associated with this build. + GitRevision string + // GitTime is the git revision time. + GitTime time.Time + GitModified bool } ) var ( - //go:embed info - buildInfoFs embed.FS - InfoData Info + InfoData Info ) func init() { - InfoData = Info{ - GitRevision: "unknown", - BuildTimeUnix: 0, - CgoEnabled: cgo.Enabled, - } - - buildInfoDataJson, err := buildInfoFs.ReadFile(buildInfoDataFile) - if err != nil { + buildInfo, ok := debug.ReadBuildInfo() + if !ok { return } - _ = json.Unmarshal(buildInfoDataJson, &InfoData) -} -func (i Info) BuildTime() time.Time { - return time.Unix(i.BuildTimeUnix, 0) + InfoData.Available = true + InfoData.GoVersion = buildInfo.GoVersion + + for _, setting := range buildInfo.Settings { + switch setting.Key { + case "GOARCH": + InfoData.GoArch = setting.Value + case "GOOS": + InfoData.GoOs = setting.Value + case "CGO_ENABLED": + InfoData.CgoEnabled = setting.Value == "1" + case "vcs.revision": + InfoData.GitRevision = setting.Value + case "vcs.time": + if gitTime, err := time.Parse(time.RFC3339, setting.Value); err == nil { + InfoData.GitTime = gitTime + } + case "vcs.modified": + InfoData.GitModified = setting.Value == "true" + } + } } diff --git a/common/metrics/runtime.go b/common/metrics/runtime.go index 88466f07398..47922b66003 100644 --- a/common/metrics/runtime.go +++ b/common/metrics/runtime.go @@ -29,7 +29,7 @@ import ( "sync/atomic" "time" - "go.temporal.io/server/build" + "go.temporal.io/server/common/build" "go.temporal.io/server/common/headers" "go.temporal.io/server/common/log" ) @@ -73,13 +73,13 @@ func NewRuntimeMetricsReporter( logger: logger, lastNumGC: memstats.NumGC, quit: make(chan struct{}), - buildTime: build.InfoData.BuildTime(), + buildTime: build.InfoData.GitTime, buildInfoScope: scope.Tagged( map[string]string{ gitRevisionTag: build.InfoData.GitRevision, - buildDateTag: build.InfoData.BuildTime().Format(time.RFC3339), - buildPlatformTag: runtime.GOARCH, - goVersionTag: runtime.Version(), + buildDateTag: build.InfoData.GitTime.Format(time.RFC3339), + buildPlatformTag: build.InfoData.GoArch, + goVersionTag: build.InfoData.GoVersion, buildVersionTag: headers.ServerVersion, }, ), diff --git a/develop/scripts/create_build_info_data.sh b/develop/scripts/create_build_info_data.sh deleted file mode 100755 index dae5a61bdb8..00000000000 --- a/develop/scripts/create_build_info_data.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -set -eu - -build_info_data_file="build/info/data.json" - -git_revision="${GITHUB_SHA_SHORT:-$(git rev-parse --short HEAD)}" # "6cbfa2a3a" - -build_time_unix=$(date '+%s') # seconds since epoch - -echo '{"gitRevision":"'"${git_revision}"'","buildTimeUnix":'"${build_time_unix}"'}' > "${build_info_data_file}"