From 346b68a44104901ad349d48cbb6763db5c995ee7 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Wed, 4 May 2022 19:16:18 -0700 Subject: [PATCH] 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 --- agent/agent.go | 11 ++++++----- agent/agent_endpoint.go | 3 ++- agent/config/builder.go | 1 + agent/config/config.go | 1 + agent/config/default.go | 5 +++-- agent/config/runtime.go | 9 +++++++++ agent/config/runtime_test.go | 3 ++- .../config/testdata/TestRuntimeConfig_Sanitize.golden | 1 + 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 3978f27378..7b81821efb 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -720,7 +720,7 @@ func (a *Agent) Start(ctx context.Context) error { // consul version metric with labels 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}, }) @@ -1272,7 +1272,7 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co if len(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 @@ -3212,9 +3212,10 @@ func (a *Agent) Stats() map[string]map[string]string { revision = revision[:8] } stats["build"] = map[string]string{ - "revision": revision, - "version": a.config.Version, - "prerelease": a.config.VersionPrerelease, + "revision": revision, + "version": a.config.Version, + "version_metadata": a.config.VersionMetadata, + "prerelease": a.config.VersionPrerelease, } for outerKey, outerValue := range a.enterpriseStats() { diff --git a/agent/agent_endpoint.go b/agent/agent_endpoint.go index abaec4e498..385e08bfdb 100644 --- a/agent/agent_endpoint.go +++ b/agent/agent_endpoint.go @@ -99,7 +99,8 @@ func (s *HTTPHandlers) AgentSelf(resp http.ResponseWriter, req *http.Request) (i Partition: s.agent.config.PartitionOrEmpty(), Revision: s.agent.config.Revision, 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{ Config: config, diff --git a/agent/config/builder.go b/agent/config/builder.go index 86c493230e..76b41b113b 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -803,6 +803,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) { SyncCoordinateRateTarget: float64Val(c.SyncCoordinateRateTarget), Version: stringVal(c.Version), VersionPrerelease: stringVal(c.VersionPrerelease), + VersionMetadata: stringVal(c.VersionMetadata), // consul configuration ConsulCoordinateUpdateBatchSize: intVal(c.Consul.Coordinate.UpdateBatchSize), diff --git a/agent/config/config.go b/agent/config/config.go index 095be9353f..affcef6010 100644 --- a/agent/config/config.go +++ b/agent/config/config.go @@ -272,6 +272,7 @@ type Config struct { SyncCoordinateRateTarget *float64 `mapstructure:"sync_coordinate_rate_target"` Version *string `mapstructure:"version"` VersionPrerelease *string `mapstructure:"version_prerelease"` + VersionMetadata *string `mapstructure:"version_metadata"` // Enterprise Only Audit Audit `mapstructure:"audit"` diff --git a/agent/config/default.go b/agent/config/default.go index c0c1bd9b94..9355ec7ff0 100644 --- a/agent/config/default.go +++ b/agent/config/default.go @@ -209,13 +209,14 @@ func NonUserSource() Source { // versionSource creates a config source for the version parameters. // This should be merged in the tail since these values are not // user configurable. -func versionSource(rev, ver, verPre string) Source { +func versionSource(rev, ver, verPre, meta string) Source { return LiteralSource{ Name: "version", Config: Config{ Revision: &rev, Version: &ver, VersionPrerelease: &verPre, + VersionMetadata: &meta, }, } } @@ -223,7 +224,7 @@ func versionSource(rev, ver, verPre string) Source { // defaultVersionSource returns the version config source for the embedded // version numbers. 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. diff --git a/agent/config/runtime.go b/agent/config/runtime.go index de5004e1a5..dd2a7cabf8 100644 --- a/agent/config/runtime.go +++ b/agent/config/runtime.go @@ -61,6 +61,7 @@ type RuntimeConfig struct { Revision string Version string VersionPrerelease string + VersionMetadata string // consul config ConsulCoordinateUpdateMaxBatches int @@ -1629,6 +1630,14 @@ func (c *RuntimeConfig) APIConfig(includeClientCerts bool) (*api.Config, error) 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 // configuration where all fields with potential secrets had their // values replaced by 'hidden'. In addition, network addresses and diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 2ad434f8fb..719d8ddeba 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -5660,6 +5660,7 @@ func TestLoad_FullConfig(t *testing.T) { Revision: "JNtPSav3", Version: "R909Hblt", VersionPrerelease: "ZT1JOQLn", + VersionMetadata: "GtTCa13", // consul configuration ConsulCoordinateUpdateBatchSize: 128, @@ -6445,7 +6446,7 @@ func TestLoad_FullConfig(t *testing.T) { ConfigFiles: []string{"testdata/full-config." + format}, 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) require.NoError(t, err) prototest.AssertDeepEqual(t, expected, r.RuntimeConfig) diff --git a/agent/config/testdata/TestRuntimeConfig_Sanitize.golden b/agent/config/testdata/TestRuntimeConfig_Sanitize.golden index 9f4a6a1962..6cff27c9b0 100644 --- a/agent/config/testdata/TestRuntimeConfig_Sanitize.golden +++ b/agent/config/testdata/TestRuntimeConfig_Sanitize.golden @@ -458,6 +458,7 @@ "UnixSocketUser": "", "UseStreamingBackend": false, "Version": "", + "VersionMetadata": "", "VersionPrerelease": "", "Watches": [] } \ No newline at end of file