From 730584f582c1c1c70eb4472a93b35954fd9d8519 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 4 Sep 2023 11:48:54 -0400 Subject: [PATCH] Log version/build info on startup (#4723) ## Which problem is this PR solving? - When users ask questions and include logs, it's difficult to tell which version of the binary they are running, especially when they use the `latest` Docker tag. ## Description of the changes - Log build / version info on startup in all binaries - Move sub-commands into cmd/internal, to not confuse them with the actual binaries ## How was this change tested? ``` $ go run ./cmd/tracegen 2023-09-04T11:24:55.559-0400 INFO tracegen/main.go:56 application version: git-commit=, git-version=, build-date= $ go run ./cmd/all-in-one 2023/09/04 11:24:31 application version: git-commit=, git-version=, build-date= ``` ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Yuri Shkuro --- .gitignore | 4 ---- cmd/agent/app/reporter/flags.go | 2 +- cmd/agent/main.go | 6 +++--- cmd/all-in-one/main.go | 8 ++++---- cmd/collector/app/flags/flags.go | 2 +- cmd/collector/app/span_handler_builder_test.go | 2 +- cmd/collector/main.go | 8 ++++---- cmd/ingester/main.go | 8 ++++---- cmd/internal/docs/.gitignore | 4 ++++ cmd/{ => internal}/docs/command.go | 0 cmd/{ => internal}/docs/command_test.go | 0 cmd/{ => internal}/env/command.go | 0 cmd/{ => internal}/env/command_test.go | 0 cmd/{ => internal}/flags/.nocover | 0 cmd/{ => internal}/flags/admin.go | 0 cmd/{ => internal}/flags/admin_test.go | 2 +- cmd/{ => internal}/flags/doc.go | 0 cmd/{ => internal}/flags/flags.go | 0 cmd/{ => internal}/flags/flags_test.go | 0 cmd/{ => internal}/flags/service.go | 0 cmd/{ => internal}/flags/service_test.go | 0 cmd/{ => internal}/status/command.go | 0 cmd/{ => internal}/status/command_test.go | 0 cmd/query/app/server_test.go | 2 +- cmd/query/app/token_propagation_test.go | 2 +- cmd/query/main.go | 8 ++++---- cmd/remote-storage/app/server_test.go | 2 +- cmd/remote-storage/main.go | 8 ++++---- cmd/tracegen/main.go | 3 +++ pkg/version/build.go | 17 ++++++++++++++--- pkg/version/command.go | 4 +++- 31 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 cmd/internal/docs/.gitignore rename cmd/{ => internal}/docs/command.go (100%) rename cmd/{ => internal}/docs/command_test.go (100%) rename cmd/{ => internal}/env/command.go (100%) rename cmd/{ => internal}/env/command_test.go (100%) rename cmd/{ => internal}/flags/.nocover (100%) rename cmd/{ => internal}/flags/admin.go (100%) rename cmd/{ => internal}/flags/admin_test.go (98%) rename cmd/{ => internal}/flags/doc.go (100%) rename cmd/{ => internal}/flags/flags.go (100%) rename cmd/{ => internal}/flags/flags_test.go (100%) rename cmd/{ => internal}/flags/service.go (100%) rename cmd/{ => internal}/flags/service_test.go (100%) rename cmd/{ => internal}/status/command.go (100%) rename cmd/{ => internal}/status/command_test.go (100%) diff --git a/.gitignore b/.gitignore index 95e336f38c8..b3b980f51ea 100644 --- a/.gitignore +++ b/.gitignore @@ -35,10 +35,6 @@ cmd/query/query cmd/query/query-* cmd/tracegen/tracegen cmd/tracegen/tracegen-* -cmd/docs/*.md -cmd/docs/*.rst -cmd/docs/*.1 -cmd/docs/*.yaml crossdock/crossdock-* run-crossdock.log proto-gen/.patched-otel-proto/ diff --git a/cmd/agent/app/reporter/flags.go b/cmd/agent/app/reporter/flags.go index 0878b424361..c3ec9616789 100644 --- a/cmd/agent/app/reporter/flags.go +++ b/cmd/agent/app/reporter/flags.go @@ -22,7 +22,7 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/flags" ) const ( diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 6f3a5054645..e7fcf515795 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -27,9 +27,9 @@ import ( "github.com/jaegertracing/jaeger/cmd/agent/app" "github.com/jaegertracing/jaeger/cmd/agent/app/reporter" "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/flags" - "github.com/jaegertracing/jaeger/cmd/status" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" "github.com/jaegertracing/jaeger/internal/metrics/expvar" "github.com/jaegertracing/jaeger/internal/metrics/fork" "github.com/jaegertracing/jaeger/pkg/config" diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 34d86f534ce..6f79f6cdc06 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -33,12 +33,12 @@ import ( "github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext" collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app" collectorFlags "github.com/jaegertracing/jaeger/cmd/collector/app/flags" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/env" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/env" + "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" queryApp "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/cmd/status" "github.com/jaegertracing/jaeger/internal/metrics/expvar" "github.com/jaegertracing/jaeger/internal/metrics/fork" "github.com/jaegertracing/jaeger/pkg/config" diff --git a/cmd/collector/app/flags/flags.go b/cmd/collector/app/flags/flags.go index b5190cf27d6..f252380fb7b 100644 --- a/cmd/collector/app/flags/flags.go +++ b/cmd/collector/app/flags/flags.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/flags" "github.com/jaegertracing/jaeger/pkg/config/corscfg" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/tenancy" diff --git a/cmd/collector/app/span_handler_builder_test.go b/cmd/collector/app/span_handler_builder_test.go index 9799a2ad25a..3dbbeb8fced 100644 --- a/cmd/collector/app/span_handler_builder_test.go +++ b/cmd/collector/app/span_handler_builder_test.go @@ -23,7 +23,7 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/flags" - cmdFlags "github.com/jaegertracing/jaeger/cmd/flags" + cmdFlags "github.com/jaegertracing/jaeger/cmd/internal/flags" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/tenancy" diff --git a/cmd/collector/main.go b/cmd/collector/main.go index d8a5c2b9f34..4a0cd42b435 100644 --- a/cmd/collector/main.go +++ b/cmd/collector/main.go @@ -28,10 +28,10 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app" "github.com/jaegertracing/jaeger/cmd/collector/app/flags" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/env" - cmdFlags "github.com/jaegertracing/jaeger/cmd/flags" - "github.com/jaegertracing/jaeger/cmd/status" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/env" + cmdFlags "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" "github.com/jaegertracing/jaeger/internal/metrics/expvar" "github.com/jaegertracing/jaeger/internal/metrics/fork" "github.com/jaegertracing/jaeger/pkg/config" diff --git a/cmd/ingester/main.go b/cmd/ingester/main.go index b8cce567937..21641ac71aa 100644 --- a/cmd/ingester/main.go +++ b/cmd/ingester/main.go @@ -25,12 +25,12 @@ import ( _ "go.uber.org/automaxprocs" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/env" - "github.com/jaegertracing/jaeger/cmd/flags" "github.com/jaegertracing/jaeger/cmd/ingester/app" "github.com/jaegertracing/jaeger/cmd/ingester/app/builder" - "github.com/jaegertracing/jaeger/cmd/status" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/env" + "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/version" diff --git a/cmd/internal/docs/.gitignore b/cmd/internal/docs/.gitignore new file mode 100644 index 00000000000..d90f3efc24a --- /dev/null +++ b/cmd/internal/docs/.gitignore @@ -0,0 +1,4 @@ +*.md +*.rst +*.1 +*.yaml diff --git a/cmd/docs/command.go b/cmd/internal/docs/command.go similarity index 100% rename from cmd/docs/command.go rename to cmd/internal/docs/command.go diff --git a/cmd/docs/command_test.go b/cmd/internal/docs/command_test.go similarity index 100% rename from cmd/docs/command_test.go rename to cmd/internal/docs/command_test.go diff --git a/cmd/env/command.go b/cmd/internal/env/command.go similarity index 100% rename from cmd/env/command.go rename to cmd/internal/env/command.go diff --git a/cmd/env/command_test.go b/cmd/internal/env/command_test.go similarity index 100% rename from cmd/env/command_test.go rename to cmd/internal/env/command_test.go diff --git a/cmd/flags/.nocover b/cmd/internal/flags/.nocover similarity index 100% rename from cmd/flags/.nocover rename to cmd/internal/flags/.nocover diff --git a/cmd/flags/admin.go b/cmd/internal/flags/admin.go similarity index 100% rename from cmd/flags/admin.go rename to cmd/internal/flags/admin.go diff --git a/cmd/flags/admin_test.go b/cmd/internal/flags/admin_test.go similarity index 98% rename from cmd/flags/admin_test.go rename to cmd/internal/flags/admin_test.go index cda6080960d..0a561330451 100644 --- a/cmd/flags/admin_test.go +++ b/cmd/internal/flags/admin_test.go @@ -35,7 +35,7 @@ import ( "github.com/jaegertracing/jaeger/ports" ) -var testCertKeyLocation = "../../pkg/config/tlscfg/testdata" +var testCertKeyLocation = "../../../pkg/config/tlscfg/testdata" func TestAdminServerHandlesPortZero(t *testing.T) { adminServer := NewAdminServer(":0") diff --git a/cmd/flags/doc.go b/cmd/internal/flags/doc.go similarity index 100% rename from cmd/flags/doc.go rename to cmd/internal/flags/doc.go diff --git a/cmd/flags/flags.go b/cmd/internal/flags/flags.go similarity index 100% rename from cmd/flags/flags.go rename to cmd/internal/flags/flags.go diff --git a/cmd/flags/flags_test.go b/cmd/internal/flags/flags_test.go similarity index 100% rename from cmd/flags/flags_test.go rename to cmd/internal/flags/flags_test.go diff --git a/cmd/flags/service.go b/cmd/internal/flags/service.go similarity index 100% rename from cmd/flags/service.go rename to cmd/internal/flags/service.go diff --git a/cmd/flags/service_test.go b/cmd/internal/flags/service_test.go similarity index 100% rename from cmd/flags/service_test.go rename to cmd/internal/flags/service_test.go diff --git a/cmd/status/command.go b/cmd/internal/status/command.go similarity index 100% rename from cmd/status/command.go rename to cmd/internal/status/command.go diff --git a/cmd/status/command_test.go b/cmd/internal/status/command_test.go similarity index 100% rename from cmd/status/command_test.go rename to cmd/internal/status/command_test.go diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 300ae982d37..70efd2104ae 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -33,7 +33,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/flags" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/internal/grpctest" "github.com/jaegertracing/jaeger/model" diff --git a/cmd/query/app/token_propagation_test.go b/cmd/query/app/token_propagation_test.go index a106a2eb487..5b7a12042bc 100644 --- a/cmd/query/app/token_propagation_test.go +++ b/cmd/query/app/token_propagation_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/flags" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" diff --git a/cmd/query/main.go b/cmd/query/main.go index e43d0979346..24331d94c37 100644 --- a/cmd/query/main.go +++ b/cmd/query/main.go @@ -26,12 +26,12 @@ import ( _ "go.uber.org/automaxprocs" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/env" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/env" + "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" "github.com/jaegertracing/jaeger/cmd/query/app" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/cmd/status" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/jtracer" diff --git a/cmd/remote-storage/app/server_test.go b/cmd/remote-storage/app/server_test.go index 613f09cf26e..8d55c3a3262 100644 --- a/cmd/remote-storage/app/server_test.go +++ b/cmd/remote-storage/app/server_test.go @@ -30,7 +30,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/flags" "github.com/jaegertracing/jaeger/internal/grpctest" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/healthcheck" diff --git a/cmd/remote-storage/main.go b/cmd/remote-storage/main.go index a020504d72d..8fd37d037a8 100644 --- a/cmd/remote-storage/main.go +++ b/cmd/remote-storage/main.go @@ -24,11 +24,11 @@ import ( _ "go.uber.org/automaxprocs" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/docs" - "github.com/jaegertracing/jaeger/cmd/env" - "github.com/jaegertracing/jaeger/cmd/flags" + "github.com/jaegertracing/jaeger/cmd/internal/docs" + "github.com/jaegertracing/jaeger/cmd/internal/env" + "github.com/jaegertracing/jaeger/cmd/internal/flags" + "github.com/jaegertracing/jaeger/cmd/internal/status" "github.com/jaegertracing/jaeger/cmd/remote-storage/app" - "github.com/jaegertracing/jaeger/cmd/status" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/tenancy" diff --git a/cmd/tracegen/main.go b/cmd/tracegen/main.go index 4b8062a1c1e..974e2f54c89 100644 --- a/cmd/tracegen/main.go +++ b/cmd/tracegen/main.go @@ -36,6 +36,7 @@ import ( "github.com/jaegertracing/jaeger/internal/jaegerclientenv2otel" "github.com/jaegertracing/jaeger/internal/tracegen" + "github.com/jaegertracing/jaeger/pkg/version" ) func main() { @@ -52,6 +53,8 @@ func main() { cfg.Flags(fs) flag.Parse() + logger.Info(version.Get().String()) + otel.SetTextMapPropagator(propagation.TraceContext{}) jaegerclientenv2otel.MapJaegerToOtelEnvVars(logger) diff --git a/pkg/version/build.go b/pkg/version/build.go index 33438e23ef0..1d51ed7eb9a 100644 --- a/pkg/version/build.go +++ b/pkg/version/build.go @@ -14,7 +14,11 @@ package version -import "github.com/jaegertracing/jaeger/pkg/metrics" +import ( + "fmt" + + "github.com/jaegertracing/jaeger/pkg/metrics" +) var ( // commitFromGit is a constant representing the source version that @@ -27,14 +31,14 @@ var ( date string ) -// Info holds build information +// Info holds build information. type Info struct { GitCommit string `json:"gitCommit"` GitVersion string `json:"gitVersion"` BuildDate string `json:"buildDate"` } -// InfoMetrics hold metrics about build information +// InfoMetrics hold a gauge whose tags include build information. type InfoMetrics struct { BuildInfo metrics.Gauge `metric:"build_info"` } @@ -62,3 +66,10 @@ func NewInfoMetrics(metricsFactory metrics.Factory) *InfoMetrics { return &info } + +func (i Info) String() string { + return fmt.Sprintf( + "application version: git-commit=%s, git-version=%s, build-date=%s", + i.GitCommit, i.GitVersion, i.BuildDate, + ) +} diff --git a/pkg/version/command.go b/pkg/version/command.go index a7830161df4..55bc2dcfdfe 100644 --- a/pkg/version/command.go +++ b/pkg/version/command.go @@ -17,18 +17,20 @@ package version import ( "encoding/json" "fmt" + "log" "github.com/spf13/cobra" ) // Command creates version command func Command() *cobra.Command { + info := Get() + log.Println(info) return &cobra.Command{ Use: "version", Short: "Print the version.", Long: `Print the version and build information.`, RunE: func(cmd *cobra.Command, args []string) error { - info := Get() json, err := json.Marshal(info) if err != nil { return err