From 9813d17e9391bc95ccbf1dde92b333756ceb1a85 Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Wed, 4 Oct 2023 14:51:35 +0200 Subject: [PATCH] Expose enterprise-commit in server version output (#75897) * Expose enterprise-commit in server version output * Define a DefaultCommitValue constant --- pkg/cmd/grafana-cli/commands/cli.go | 2 ++ pkg/cmd/grafana-server/commands/cli.go | 7 ++++++- pkg/cmd/grafana/main.go | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/cli.go b/pkg/cmd/grafana-cli/commands/cli.go index 9865c137800..93be4abf40a 100644 --- a/pkg/cmd/grafana-cli/commands/cli.go +++ b/pkg/cmd/grafana-cli/commands/cli.go @@ -11,6 +11,8 @@ import ( "github.com/grafana/grafana/pkg/cmd/grafana-cli/utils" ) +const DefaultCommitValue = "NA" + // CLICommand is the entrypoint for the grafana-cli command. It returns the exit code for the grafana-cli program. func CLICommand(version string) *cli.Command { return &cli.Command{ diff --git a/pkg/cmd/grafana-server/commands/cli.go b/pkg/cmd/grafana-server/commands/cli.go index 1e83ab2e0f6..37ff71f7c76 100644 --- a/pkg/cmd/grafana-server/commands/cli.go +++ b/pkg/cmd/grafana-server/commands/cli.go @@ -14,6 +14,7 @@ import ( "github.com/urfave/cli/v2" "github.com/grafana/grafana/pkg/api" + gcli "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/process" "github.com/grafana/grafana/pkg/server" @@ -52,7 +53,11 @@ func ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp st func RunServer(opts ServerOptions) error { if Version || VerboseVersion { - fmt.Printf("Version %s (commit: %s, branch: %s)\n", opts.Version, opts.Commit, opts.BuildBranch) + if opts.EnterpriseCommit != gcli.DefaultCommitValue && opts.EnterpriseCommit != "" { + fmt.Printf("Version %s (commit: %s, branch: %s, enterprise-commit: %s)\n", opts.Version, opts.Commit, opts.BuildBranch, opts.EnterpriseCommit) + } else { + fmt.Printf("Version %s (commit: %s, branch: %s)\n", opts.Version, opts.Commit, opts.BuildBranch) + } if VerboseVersion { fmt.Println("Dependencies:") if info, ok := debug.ReadBuildInfo(); ok { diff --git a/pkg/cmd/grafana/main.go b/pkg/cmd/grafana/main.go index de1657061bc..48ba9586f4f 100644 --- a/pkg/cmd/grafana/main.go +++ b/pkg/cmd/grafana/main.go @@ -13,8 +13,8 @@ import ( // The following variables cannot be constants, since they can be overridden through the -X link flag var version = "9.2.0" -var commit = "NA" -var enterpriseCommit = "NA" +var commit = gcli.DefaultCommitValue +var enterpriseCommit = gcli.DefaultCommitValue var buildBranch = "main" var buildstamp string