mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
HealthCheck: show enterprise commit (#75242)
This commit is contained in:
parent
3529b7413d
commit
4cfc834c08
@ -36,6 +36,29 @@ func TestHealthAPI_Version(t *testing.T) {
|
|||||||
require.JSONEq(t, expectedBody, rec.Body.String())
|
require.JSONEq(t, expectedBody, rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHealthAPI_VersionEnterprise(t *testing.T) {
|
||||||
|
m, _ := setupHealthAPITestEnvironment(t, func(cfg *setting.Cfg) {
|
||||||
|
cfg.BuildVersion = "7.4.0"
|
||||||
|
cfg.EnterpriseBuildCommit = "22206ab1be"
|
||||||
|
cfg.BuildCommit = "59906ab1bf"
|
||||||
|
})
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/health", nil)
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
m.ServeHTTP(rec, req)
|
||||||
|
|
||||||
|
require.Equal(t, 200, rec.Code)
|
||||||
|
expectedBody := `
|
||||||
|
{
|
||||||
|
"database": "ok",
|
||||||
|
"enterpriseCommit": "22206ab1be",
|
||||||
|
"version": "7.4.0",
|
||||||
|
"commit": "59906ab1bf"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
require.JSONEq(t, expectedBody, rec.Body.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestHealthAPI_AnonymousHideVersion(t *testing.T) {
|
func TestHealthAPI_AnonymousHideVersion(t *testing.T) {
|
||||||
m, hs := setupHealthAPITestEnvironment(t)
|
m, hs := setupHealthAPITestEnvironment(t)
|
||||||
hs.Cfg.AnonymousHideVersion = true
|
hs.Cfg.AnonymousHideVersion = true
|
||||||
|
@ -679,6 +679,9 @@ func (hs *HTTPServer) apiHealthHandler(ctx *web.Context) {
|
|||||||
if !hs.Cfg.AnonymousHideVersion {
|
if !hs.Cfg.AnonymousHideVersion {
|
||||||
data.Set("version", hs.Cfg.BuildVersion)
|
data.Set("version", hs.Cfg.BuildVersion)
|
||||||
data.Set("commit", hs.Cfg.BuildCommit)
|
data.Set("commit", hs.Cfg.BuildCommit)
|
||||||
|
if hs.Cfg.EnterpriseBuildCommit != "NA" && hs.Cfg.EnterpriseBuildCommit != "" {
|
||||||
|
data.Set("enterpriseCommit", hs.Cfg.EnterpriseBuildCommit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hs.databaseHealthy(ctx.Req.Context()) {
|
if !hs.databaseHealthy(ctx.Req.Context()) {
|
||||||
|
@ -222,15 +222,25 @@ func ldflags(opts BuildOpts) (string, error) {
|
|||||||
commitSha = v
|
commitSha = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var enterpriseCommitSha string
|
||||||
|
if opts.enterprise {
|
||||||
|
enterpriseCommitSha = getGitEnterpriseSha()
|
||||||
|
if v := os.Getenv("ENTERPRISE_COMMIT_SHA"); v != "" {
|
||||||
|
enterpriseCommitSha = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildBranch := getGitBranch()
|
buildBranch := getGitBranch()
|
||||||
if v := os.Getenv("BUILD_BRANCH"); v != "" {
|
if v := os.Getenv("BUILD_BRANCH"); v != "" {
|
||||||
buildBranch = v
|
buildBranch = v
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
b.WriteString("-w")
|
b.WriteString("-w")
|
||||||
b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version))
|
b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version))
|
||||||
b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha))
|
b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha))
|
||||||
|
if enterpriseCommitSha != "" {
|
||||||
|
b.WriteString(fmt.Sprintf(" -X main.enterpriseCommit=%s", enterpriseCommitSha))
|
||||||
|
}
|
||||||
b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp))
|
b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp))
|
||||||
b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", buildBranch))
|
b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", buildBranch))
|
||||||
if v := os.Getenv("LDFLAGS"); v != "" {
|
if v := os.Getenv("LDFLAGS"); v != "" {
|
||||||
|
@ -10,9 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Revision struct {
|
type Revision struct {
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
SHA256 string
|
SHA256 string
|
||||||
Branch string
|
EnterpriseCommit string
|
||||||
|
Branch string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GrafanaTimestamp(ctx context.Context, dir string) (int64, error) {
|
func GrafanaTimestamp(ctx context.Context, dir string) (int64, error) {
|
||||||
@ -42,14 +43,23 @@ func GrafanaRevision(ctx context.Context, grafanaDir string) (Revision, error) {
|
|||||||
return Revision{}, err
|
return Revision{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enterpriseCommit, err := executil.OutputAt(ctx, grafanaDir, "git", "-C", "../grafana-enterprise", "rev-parse", "--short", "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
enterpriseCommit, err = executil.OutputAt(ctx, grafanaDir, "git", "-C", "..", "rev-parse", "--short", "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
return Revision{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
branch, err := executil.OutputAt(ctx, grafanaDir, "git", "rev-parse", "--abbrev-ref", "HEAD")
|
branch, err := executil.OutputAt(ctx, grafanaDir, "git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Revision{}, err
|
return Revision{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return Revision{
|
return Revision{
|
||||||
SHA256: sha,
|
SHA256: sha,
|
||||||
Branch: branch,
|
EnterpriseCommit: enterpriseCommit,
|
||||||
Timestamp: stamp,
|
Branch: branch,
|
||||||
|
Timestamp: stamp,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -15,3 +15,16 @@ func getGitSha() string {
|
|||||||
}
|
}
|
||||||
return string(v)
|
return string(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getGitEnterpriseSha() string {
|
||||||
|
// supporting the old way of dev setup
|
||||||
|
v, err := runError("git", "-C", "../grafana-enterprise", "rev-parse", "--short", "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
// supporting the new way of dev setup
|
||||||
|
v, err = runError("git", "-C", "..", "rev-parse", "--short", "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(v)
|
||||||
|
}
|
||||||
|
@ -23,13 +23,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GrafanaLDFlags(version string, r config.Revision) []string {
|
func GrafanaLDFlags(version string, r config.Revision) []string {
|
||||||
return []string{
|
cmd := []string{
|
||||||
"-w",
|
"-w",
|
||||||
fmt.Sprintf("-X main.version=%s", version),
|
fmt.Sprintf("-X main.version=%s", version),
|
||||||
fmt.Sprintf("-X main.commit=%s", r.SHA256),
|
fmt.Sprintf("-X main.commit=%s", r.SHA256),
|
||||||
fmt.Sprintf("-X main.buildstamp=%d", r.Timestamp),
|
fmt.Sprintf("-X main.buildstamp=%d", r.Timestamp),
|
||||||
fmt.Sprintf("-X main.buildBranch=%s", r.Branch),
|
fmt.Sprintf("-X main.buildBranch=%s", r.Branch),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.EnterpriseCommit != "" {
|
||||||
|
cmd = append(cmd, fmt.Sprintf("-X main.enterpriseCommit=%s", r.EnterpriseCommit))
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// BinaryFolder returns the path to where the Grafana binary is build given the provided arguments.
|
// BinaryFolder returns the path to where the Grafana binary is build given the provided arguments.
|
||||||
|
@ -16,6 +16,7 @@ func setBuildInfo(opts ServerOptions) {
|
|||||||
}
|
}
|
||||||
setting.BuildVersion = opts.Version
|
setting.BuildVersion = opts.Version
|
||||||
setting.BuildCommit = opts.Commit
|
setting.BuildCommit = opts.Commit
|
||||||
|
setting.EnterpriseBuildCommit = opts.EnterpriseCommit
|
||||||
setting.BuildStamp = buildstampInt64
|
setting.BuildStamp = buildstampInt64
|
||||||
setting.BuildBranch = opts.BuildBranch
|
setting.BuildBranch = opts.BuildBranch
|
||||||
setting.IsEnterprise = extensions.IsEnterprise
|
setting.IsEnterprise = extensions.IsEnterprise
|
||||||
|
@ -23,25 +23,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ServerOptions struct {
|
type ServerOptions struct {
|
||||||
Version string
|
Version string
|
||||||
Commit string
|
Commit string
|
||||||
BuildBranch string
|
EnterpriseCommit string
|
||||||
BuildStamp string
|
BuildBranch string
|
||||||
Context *cli.Context
|
BuildStamp string
|
||||||
|
Context *cli.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServerCommand(version, commit, buildBranch, buildstamp string) *cli.Command {
|
func ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp string) *cli.Command {
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "server",
|
Name: "server",
|
||||||
Usage: "run the grafana server",
|
Usage: "run the grafana server",
|
||||||
Flags: commonFlags,
|
Flags: commonFlags,
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
return RunServer(ServerOptions{
|
return RunServer(ServerOptions{
|
||||||
Version: version,
|
Version: version,
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
BuildBranch: buildBranch,
|
EnterpriseCommit: enterpriseCommit,
|
||||||
BuildStamp: buildstamp,
|
BuildBranch: buildBranch,
|
||||||
Context: context,
|
BuildStamp: buildstamp,
|
||||||
|
Context: context,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Subcommands: []*cli.Command{TargetCommand(version, commit, buildBranch, buildstamp)},
|
Subcommands: []*cli.Command{TargetCommand(version, commit, buildBranch, buildstamp)},
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
// The following variables cannot be constants, since they can be overridden through the -X link flag
|
// The following variables cannot be constants, since they can be overridden through the -X link flag
|
||||||
var version = "9.2.0"
|
var version = "9.2.0"
|
||||||
var commit = "NA"
|
var commit = "NA"
|
||||||
|
var enterpriseCommit = "NA"
|
||||||
var buildBranch = "main"
|
var buildBranch = "main"
|
||||||
var buildstamp string
|
var buildstamp string
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ func main() {
|
|||||||
Version: version,
|
Version: version,
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
gcli.CLICommand(version),
|
gcli.CLICommand(version),
|
||||||
gsrv.ServerCommand(version, commit, buildBranch, buildstamp),
|
gsrv.ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp),
|
||||||
},
|
},
|
||||||
CommandNotFound: cmdNotFound,
|
CommandNotFound: cmdNotFound,
|
||||||
EnableBashCompletion: true,
|
EnableBashCompletion: true,
|
||||||
|
@ -63,11 +63,12 @@ var (
|
|||||||
InstanceName string
|
InstanceName string
|
||||||
|
|
||||||
// build
|
// build
|
||||||
BuildVersion string
|
BuildVersion string
|
||||||
BuildCommit string
|
BuildCommit string
|
||||||
BuildBranch string
|
EnterpriseBuildCommit string
|
||||||
BuildStamp int64
|
BuildBranch string
|
||||||
IsEnterprise bool
|
BuildStamp int64
|
||||||
|
IsEnterprise bool
|
||||||
|
|
||||||
// packaging
|
// packaging
|
||||||
Packaging = "unknown"
|
Packaging = "unknown"
|
||||||
@ -176,11 +177,12 @@ type Cfg struct {
|
|||||||
EmailCodeValidMinutes int
|
EmailCodeValidMinutes int
|
||||||
|
|
||||||
// build
|
// build
|
||||||
BuildVersion string
|
BuildVersion string
|
||||||
BuildCommit string
|
BuildCommit string
|
||||||
BuildBranch string
|
EnterpriseBuildCommit string
|
||||||
BuildStamp int64
|
BuildBranch string
|
||||||
IsEnterprise bool
|
BuildStamp int64
|
||||||
|
IsEnterprise bool
|
||||||
|
|
||||||
// packaging
|
// packaging
|
||||||
Packaging string
|
Packaging string
|
||||||
@ -1024,6 +1026,7 @@ func (cfg *Cfg) Load(args CommandLineArgs) error {
|
|||||||
|
|
||||||
cfg.BuildVersion = BuildVersion
|
cfg.BuildVersion = BuildVersion
|
||||||
cfg.BuildCommit = BuildCommit
|
cfg.BuildCommit = BuildCommit
|
||||||
|
cfg.EnterpriseBuildCommit = EnterpriseBuildCommit
|
||||||
cfg.BuildStamp = BuildStamp
|
cfg.BuildStamp = BuildStamp
|
||||||
cfg.BuildBranch = BuildBranch
|
cfg.BuildBranch = BuildBranch
|
||||||
cfg.IsEnterprise = IsEnterprise
|
cfg.IsEnterprise = IsEnterprise
|
||||||
|
Loading…
Reference in New Issue
Block a user