diff --git a/packages/grafana-data/src/types/config.ts b/packages/grafana-data/src/types/config.ts index 0a2a9783901..a606825d820 100644 --- a/packages/grafana-data/src/types/config.ts +++ b/packages/grafana-data/src/types/config.ts @@ -14,7 +14,10 @@ import { GrafanaTheme, IconName, NavLinkDTO, OrgRole } from '.'; * @public */ export interface BuildInfo { + // This MUST be a semver-ish version string, such as "11.0.0-54321" version: string; + // Version to show in the UI instead of version + versionString: string; commit: string; env: string; edition: GrafanaEdition; diff --git a/pkg/api/dtos/frontend_settings.go b/pkg/api/dtos/frontend_settings.go index 49d77b30b95..d1b30c6fdc7 100644 --- a/pkg/api/dtos/frontend_settings.go +++ b/pkg/api/dtos/frontend_settings.go @@ -35,9 +35,16 @@ type FrontendSettingsAuthDTO struct { } type FrontendSettingsBuildInfoDTO struct { - HideVersion bool `json:"hideVersion"` - Version string `json:"version"` + HideVersion bool `json:"hideVersion"` + + // A semver-ish version string, such as "11.0.0-12345" + Version string `json:"version"` + + // A branded version string to show in the UI, such as "Grafana v11.0.0-12345" + VersionString string `json:"versionString,omitempty"` + Commit string `json:"commit"` + CommitShort string `json:"commitShort"` Buildstamp int64 `json:"buildstamp"` Edition string `json:"edition"` LatestVersion string `json:"latestVersion"` diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index d5d42a08c26..a9956fd42b8 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -152,11 +152,15 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro hideVersion := hs.Cfg.AnonymousHideVersion && !c.IsSignedIn version := setting.BuildVersion commit := setting.BuildCommit + commitShort := getShortCommitHash(setting.BuildCommit, 10) buildstamp := setting.BuildStamp + versionString := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, version, commitShort) if hideVersion { version = "" + versionString = setting.ApplicationName commit = "" + commitShort = "" buildstamp = 0 } @@ -226,7 +230,9 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro BuildInfo: dtos.FrontendSettingsBuildInfoDTO{ HideVersion: hideVersion, Version: version, + VersionString: versionString, Commit: commit, + CommitShort: commitShort, Buildstamp: buildstamp, Edition: hs.License.Edition(), LatestVersion: hs.grafanaUpdateChecker.LatestVersion(), @@ -367,6 +373,13 @@ func isSupportBundlesEnabled(hs *HTTPServer) bool { return hs.Cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(true) } +func getShortCommitHash(commitHash string, maxLength int) string { + if len(commitHash) > maxLength { + return commitHash[:maxLength] + } + return commitHash +} + func (hs *HTTPServer) getFSDataSources(c *contextmodel.ReqContext, availablePlugins AvailablePlugins) (map[string]plugins.DataSourceDTO, error) { orgDataSources := make([]*datasources.DataSource, 0) if c.SignedInUser.GetOrgID() != 0 { diff --git a/pkg/api/index.go b/pkg/api/index.go index 2edc949bd58..3eb92001f94 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -161,6 +161,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV hs.HooksService.RunIndexDataHooks(&data, c) data.NavTree.ApplyAdminIA() + data.NavTree.ApplyHelpVersion(data.Settings.BuildInfo.VersionString) // RunIndexDataHooks can modify the version string data.NavTree.Sort() return &data, nil diff --git a/pkg/services/navtree/models.go b/pkg/services/navtree/models.go index b1c71b45fa7..76d718f4c10 100644 --- a/pkg/services/navtree/models.go +++ b/pkg/services/navtree/models.go @@ -127,6 +127,14 @@ func Sort(nodes []*NavLink) { } } +func (root *NavTreeRoot) ApplyHelpVersion(version string) { + helpNode := root.FindById("help") + + if helpNode != nil { + helpNode.SubTitle = version + } +} + func (root *NavTreeRoot) ApplyAdminIA() { orgAdminNode := root.FindById(NavIDCfg) diff --git a/pkg/services/navtree/navtreeimpl/navtree.go b/pkg/services/navtree/navtreeimpl/navtree.go index 2c81c6095cd..3b241ca8957 100644 --- a/pkg/services/navtree/navtreeimpl/navtree.go +++ b/pkg/services/navtree/navtreeimpl/navtree.go @@ -1,7 +1,6 @@ package navtreeimpl import ( - "fmt" "sort" "github.com/grafana/grafana/pkg/api/dtos" @@ -188,25 +187,11 @@ func isSupportBundlesEnabled(s *ServiceImpl) bool { return s.cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(true) } -// don't need to show the full commit hash in the UI -// let's substring to 10 chars like local git does automatically -func getShortCommitHash(commitHash string, maxLength int) string { - if len(commitHash) > maxLength { - return commitHash[:maxLength] - } - return commitHash -} - func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) { if s.cfg.HelpEnabled { - helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, getShortCommitHash(setting.BuildCommit, 10)) - if s.cfg.AnonymousHideVersion && !c.IsSignedIn { - helpVersion = setting.ApplicationName - } - + // The version subtitle is set later by NavTree.ApplyHelpVersion helpNode := &navtree.NavLink{ Text: "Help", - SubTitle: helpVersion, Id: "help", Url: "#", Icon: "question-circle", diff --git a/public/app/core/components/Footer/Footer.tsx b/public/app/core/components/Footer/Footer.tsx index 62739518c0c..16ffb45dc84 100644 --- a/public/app/core/components/Footer/Footer.tsx +++ b/public/app/core/components/Footer/Footer.tsx @@ -71,7 +71,7 @@ export function getVersionLinks(hideEdition?: boolean): FooterLink[] { links.push({ target: '_blank', id: 'version', - text: `v${buildInfo.version} (${buildInfo.commit})`, + text: buildInfo.versionString, url: hasReleaseNotes ? `https://github.com/grafana/grafana/blob/main/CHANGELOG.md` : undefined, }); @@ -105,8 +105,8 @@ export const Footer = React.memo(({ customLinks, hideEdition }: Props) => {