mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
Merge pull request #12961 from hashicorp/ma/fix-enterprise-version-string-oss
Ma/fix enterprise version string oss
This commit is contained in:
commit
c479cdce01
3
.changelog/12961.txt
Normal file
3
.changelog/12961.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
api: agent/self now returns version with +ent suffix for Enterprise Consul
|
||||||
|
```
|
@ -720,7 +720,7 @@ func (a *Agent) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
// consul version metric with labels
|
// consul version metric with labels
|
||||||
metrics.SetGaugeWithLabels([]string{"version"}, 1, []metrics.Label{
|
metrics.SetGaugeWithLabels([]string{"version"}, 1, []metrics.Label{
|
||||||
{Name: "version", Value: a.config.Version},
|
{Name: "version", Value: a.config.VersionWithMetadata()},
|
||||||
{Name: "pre_release", Value: a.config.VersionPrerelease},
|
{Name: "pre_release", Value: a.config.VersionPrerelease},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1272,7 +1272,7 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co
|
|||||||
if len(revision) > 8 {
|
if len(revision) > 8 {
|
||||||
revision = revision[:8]
|
revision = revision[:8]
|
||||||
}
|
}
|
||||||
cfg.Build = fmt.Sprintf("%s%s:%s", runtimeCfg.Version, runtimeCfg.VersionPrerelease, revision)
|
cfg.Build = fmt.Sprintf("%s%s:%s", runtimeCfg.VersionWithMetadata(), runtimeCfg.VersionPrerelease, revision)
|
||||||
|
|
||||||
cfg.TLSConfig = runtimeCfg.TLS
|
cfg.TLSConfig = runtimeCfg.TLS
|
||||||
|
|
||||||
@ -3214,6 +3214,7 @@ func (a *Agent) Stats() map[string]map[string]string {
|
|||||||
stats["build"] = map[string]string{
|
stats["build"] = map[string]string{
|
||||||
"revision": revision,
|
"revision": revision,
|
||||||
"version": a.config.Version,
|
"version": a.config.Version,
|
||||||
|
"version_metadata": a.config.VersionMetadata,
|
||||||
"prerelease": a.config.VersionPrerelease,
|
"prerelease": a.config.VersionPrerelease,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,8 @@ func (s *HTTPHandlers) AgentSelf(resp http.ResponseWriter, req *http.Request) (i
|
|||||||
Partition: s.agent.config.PartitionOrEmpty(),
|
Partition: s.agent.config.PartitionOrEmpty(),
|
||||||
Revision: s.agent.config.Revision,
|
Revision: s.agent.config.Revision,
|
||||||
Server: s.agent.config.ServerMode,
|
Server: s.agent.config.ServerMode,
|
||||||
Version: s.agent.config.Version,
|
// We expect the ent version to be part of the reported version string, and that's now part of the metadata, not the actual version.
|
||||||
|
Version: s.agent.config.VersionWithMetadata(),
|
||||||
}
|
}
|
||||||
return Self{
|
return Self{
|
||||||
Config: config,
|
Config: config,
|
||||||
|
49
agent/agent_endpoint_oss_test.go
Normal file
49
agent/agent_endpoint_oss_test.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
//go:build !consulent
|
||||||
|
// +build !consulent
|
||||||
|
|
||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/testrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAgent_Self_VersionLacksEnt(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("too slow for testing.Short")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cases := map[string]struct {
|
||||||
|
hcl string
|
||||||
|
expectXDS bool
|
||||||
|
}{
|
||||||
|
"normal": {
|
||||||
|
hcl: "primary_datacenter = \"dc1\"",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, tc := range cases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
a := NewTestAgent(t, tc.hcl)
|
||||||
|
defer a.Shutdown()
|
||||||
|
|
||||||
|
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
||||||
|
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
a.srv.h.ServeHTTP(resp, req)
|
||||||
|
|
||||||
|
dec := json.NewDecoder(resp.Body)
|
||||||
|
var out map[string]map[string]interface{}
|
||||||
|
require.NoError(t, dec.Decode(&out))
|
||||||
|
require.NotContains(t, out["Config"]["Version"], "ent")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -803,6 +803,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
|
|||||||
SyncCoordinateRateTarget: float64Val(c.SyncCoordinateRateTarget),
|
SyncCoordinateRateTarget: float64Val(c.SyncCoordinateRateTarget),
|
||||||
Version: stringVal(c.Version),
|
Version: stringVal(c.Version),
|
||||||
VersionPrerelease: stringVal(c.VersionPrerelease),
|
VersionPrerelease: stringVal(c.VersionPrerelease),
|
||||||
|
VersionMetadata: stringVal(c.VersionMetadata),
|
||||||
|
|
||||||
// consul configuration
|
// consul configuration
|
||||||
ConsulCoordinateUpdateBatchSize: intVal(c.Consul.Coordinate.UpdateBatchSize),
|
ConsulCoordinateUpdateBatchSize: intVal(c.Consul.Coordinate.UpdateBatchSize),
|
||||||
|
@ -272,6 +272,7 @@ type Config struct {
|
|||||||
SyncCoordinateRateTarget *float64 `mapstructure:"sync_coordinate_rate_target"`
|
SyncCoordinateRateTarget *float64 `mapstructure:"sync_coordinate_rate_target"`
|
||||||
Version *string `mapstructure:"version"`
|
Version *string `mapstructure:"version"`
|
||||||
VersionPrerelease *string `mapstructure:"version_prerelease"`
|
VersionPrerelease *string `mapstructure:"version_prerelease"`
|
||||||
|
VersionMetadata *string `mapstructure:"version_metadata"`
|
||||||
|
|
||||||
// Enterprise Only
|
// Enterprise Only
|
||||||
Audit Audit `mapstructure:"audit"`
|
Audit Audit `mapstructure:"audit"`
|
||||||
|
@ -209,13 +209,14 @@ func NonUserSource() Source {
|
|||||||
// versionSource creates a config source for the version parameters.
|
// versionSource creates a config source for the version parameters.
|
||||||
// This should be merged in the tail since these values are not
|
// This should be merged in the tail since these values are not
|
||||||
// user configurable.
|
// user configurable.
|
||||||
func versionSource(rev, ver, verPre string) Source {
|
func versionSource(rev, ver, verPre, meta string) Source {
|
||||||
return LiteralSource{
|
return LiteralSource{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Revision: &rev,
|
Revision: &rev,
|
||||||
Version: &ver,
|
Version: &ver,
|
||||||
VersionPrerelease: &verPre,
|
VersionPrerelease: &verPre,
|
||||||
|
VersionMetadata: &meta,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +224,7 @@ func versionSource(rev, ver, verPre string) Source {
|
|||||||
// defaultVersionSource returns the version config source for the embedded
|
// defaultVersionSource returns the version config source for the embedded
|
||||||
// version numbers.
|
// version numbers.
|
||||||
func defaultVersionSource() Source {
|
func defaultVersionSource() Source {
|
||||||
return versionSource(version.GitCommit, version.Version, version.VersionPrerelease)
|
return versionSource(version.GitCommit, version.Version, version.VersionPrerelease, version.VersionMetadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConsulSource returns the default configuration for the consul agent.
|
// DefaultConsulSource returns the default configuration for the consul agent.
|
||||||
|
@ -61,6 +61,7 @@ type RuntimeConfig struct {
|
|||||||
Revision string
|
Revision string
|
||||||
Version string
|
Version string
|
||||||
VersionPrerelease string
|
VersionPrerelease string
|
||||||
|
VersionMetadata string
|
||||||
|
|
||||||
// consul config
|
// consul config
|
||||||
ConsulCoordinateUpdateMaxBatches int
|
ConsulCoordinateUpdateMaxBatches int
|
||||||
@ -1629,6 +1630,14 @@ func (c *RuntimeConfig) APIConfig(includeClientCerts bool) (*api.Config, error)
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *RuntimeConfig) VersionWithMetadata() string {
|
||||||
|
version := c.Version
|
||||||
|
if c.VersionMetadata != "" {
|
||||||
|
version += "+" + c.VersionMetadata
|
||||||
|
}
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitized returns a JSON/HCL compatible representation of the runtime
|
// Sanitized returns a JSON/HCL compatible representation of the runtime
|
||||||
// configuration where all fields with potential secrets had their
|
// configuration where all fields with potential secrets had their
|
||||||
// values replaced by 'hidden'. In addition, network addresses and
|
// values replaced by 'hidden'. In addition, network addresses and
|
||||||
|
@ -5660,6 +5660,7 @@ func TestLoad_FullConfig(t *testing.T) {
|
|||||||
Revision: "JNtPSav3",
|
Revision: "JNtPSav3",
|
||||||
Version: "R909Hblt",
|
Version: "R909Hblt",
|
||||||
VersionPrerelease: "ZT1JOQLn",
|
VersionPrerelease: "ZT1JOQLn",
|
||||||
|
VersionMetadata: "GtTCa13",
|
||||||
|
|
||||||
// consul configuration
|
// consul configuration
|
||||||
ConsulCoordinateUpdateBatchSize: 128,
|
ConsulCoordinateUpdateBatchSize: 128,
|
||||||
@ -6445,7 +6446,7 @@ func TestLoad_FullConfig(t *testing.T) {
|
|||||||
ConfigFiles: []string{"testdata/full-config." + format},
|
ConfigFiles: []string{"testdata/full-config." + format},
|
||||||
HCL: []string{fmt.Sprintf(`data_dir = "%s"`, dataDir)},
|
HCL: []string{fmt.Sprintf(`data_dir = "%s"`, dataDir)},
|
||||||
}
|
}
|
||||||
opts.Overrides = append(opts.Overrides, versionSource("JNtPSav3", "R909Hblt", "ZT1JOQLn"))
|
opts.Overrides = append(opts.Overrides, versionSource("JNtPSav3", "R909Hblt", "ZT1JOQLn", "GtTCa13"))
|
||||||
r, err := Load(opts)
|
r, err := Load(opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
prototest.AssertDeepEqual(t, expected, r.RuntimeConfig)
|
prototest.AssertDeepEqual(t, expected, r.RuntimeConfig)
|
||||||
|
@ -458,6 +458,7 @@
|
|||||||
"UnixSocketUser": "",
|
"UnixSocketUser": "",
|
||||||
"UseStreamingBackend": false,
|
"UseStreamingBackend": false,
|
||||||
"Version": "",
|
"Version": "",
|
||||||
|
"VersionMetadata": "",
|
||||||
"VersionPrerelease": "",
|
"VersionPrerelease": "",
|
||||||
"Watches": []
|
"Watches": []
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +16,9 @@ var (
|
|||||||
// for tests to work.
|
// for tests to work.
|
||||||
Version = "1.12.0"
|
Version = "1.12.0"
|
||||||
|
|
||||||
|
// https://semver.org/#spec-item-10
|
||||||
|
VersionMetadata = ""
|
||||||
|
|
||||||
// A pre-release marker for the version. If this is "" (empty string)
|
// A pre-release marker for the version. If this is "" (empty string)
|
||||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||||
// such as "dev" (in development), "beta", "rc1", etc.
|
// such as "dev" (in development), "beta", "rc1", etc.
|
||||||
@ -26,13 +30,14 @@ var (
|
|||||||
func GetHumanVersion() string {
|
func GetHumanVersion() string {
|
||||||
version := Version
|
version := Version
|
||||||
release := VersionPrerelease
|
release := VersionPrerelease
|
||||||
|
metadata := VersionMetadata
|
||||||
|
|
||||||
if release != "" {
|
if release != "" {
|
||||||
suffix := "-" + release
|
version += fmt.Sprintf("-%s", release)
|
||||||
if !strings.HasSuffix(version, suffix) {
|
|
||||||
// if we tagged a prerelease version then the release is in the version already
|
|
||||||
version += suffix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if metadata != "" {
|
||||||
|
version += fmt.Sprintf("+%s", metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip off any single quotes added by the git information.
|
// Strip off any single quotes added by the git information.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user