Fix up enterprise version tag.

Changes to how the version string was handled created small regression with the release of consul 1.12.0 enterprise.

Many tools use the Config:Version field reported by the agent/self resource to determine whether Consul is an enterprise or OSS instance, expect something like 1.12.0+ent for enterprise and simply 1.12.0 for OSS. This was accidentally broken during the runup to 1.12.x

This work fixes the value returned by both the self endpoint in ["Config"]["Version"] and the metrics consul.version field.

Signed-off-by: Mark Anderson <manderson@hashicorp.com>
This commit is contained in:
Mark Anderson 2022-05-04 19:16:18 -07:00
parent a78015c5fd
commit 346b68a441
8 changed files with 25 additions and 9 deletions

View File

@ -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
@ -3212,9 +3212,10 @@ func (a *Agent) Stats() map[string]map[string]string {
revision = revision[:8] revision = revision[:8]
} }
stats["build"] = map[string]string{ stats["build"] = map[string]string{
"revision": revision, "revision": revision,
"version": a.config.Version, "version": a.config.Version,
"prerelease": a.config.VersionPrerelease, "version_metadata": a.config.VersionMetadata,
"prerelease": a.config.VersionPrerelease,
} }
for outerKey, outerValue := range a.enterpriseStats() { for outerKey, outerValue := range a.enterpriseStats() {

View File

@ -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,

View File

@ -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),

View File

@ -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"`

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -458,6 +458,7 @@
"UnixSocketUser": "", "UnixSocketUser": "",
"UseStreamingBackend": false, "UseStreamingBackend": false,
"Version": "", "Version": "",
"VersionMetadata": "",
"VersionPrerelease": "", "VersionPrerelease": "",
"Watches": [] "Watches": []
} }