From 3432b0a2d65ca67e6fb0ef085aa67f5a9590c027 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 17 Sep 2025 13:23:01 -0400 Subject: [PATCH] consul: only add fingerprint link if unique.consul.name is set (#26787) In Nomad Enterprise we can fingerprint multiple Consul datacenters. If neither is `"default"` then we end up with warning logs about adding a "link". The `Link` field on the `Node` struct is a map of attributes that only contributes to the node's computed hash. The `"consul"` key's value is derived from the `unique.consul.name` attribute, which only exists if there's a default Consul cluster. Update the fingerprint to skip setting the link field if there's no `unique.consul.name`, and lower the warning log for malformed fields to debug; this is a minor scheduling optimization largely captured by existing Consul fields in the node computed class. The only reason not to remove it entirely is to avoid changing computed classes on existing large clusters. Fixes: https://github.com/hashicorp/nomad/issues/26781 Ref: https://hashicorp.atlassian.net/browse/NMD-998 --- .changelog/26787.txt | 3 +++ client/fingerprint/consul.go | 10 +++++----- client/fingerprint/consul_test.go | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changelog/26787.txt diff --git a/.changelog/26787.txt b/.changelog/26787.txt new file mode 100644 index 000000000..e325a561d --- /dev/null +++ b/.changelog/26787.txt @@ -0,0 +1,3 @@ +```release-note:bug +consul (Enterprise): Fixed a bug where Consul fingerprinting would generate warning logs if there was no default cluster +``` diff --git a/client/fingerprint/consul.go b/client/fingerprint/consul.go index 2ff906857..339b8f5df 100644 --- a/client/fingerprint/consul.go +++ b/client/fingerprint/consul.go @@ -242,12 +242,12 @@ func (cfs *consulState) query(logger hclog.Logger) agentconsul.Self { } func (f *ConsulFingerprint) link(resp *FingerprintResponse) { - if dc, ok := resp.Attributes["consul.datacenter"]; ok { - if name, ok2 := resp.Attributes["unique.consul.name"]; ok2 { - resp.AddLink("consul", fmt.Sprintf("%s.%s", dc, name)) + if uniqueName, ok := resp.Attributes["unique.consul.name"]; ok { + if dc, ok := resp.Attributes["consul.datacenter"]; ok { + resp.AddLink("consul", fmt.Sprintf("%s.%s", dc, uniqueName)) + } else { + f.logger.Debug("malformed Consul response prevented adding link") } - } else { - f.logger.Warn("malformed Consul response prevented linking") } } diff --git a/client/fingerprint/consul_test.go b/client/fingerprint/consul_test.go index 078c93bf3..69935c33f 100644 --- a/client/fingerprint/consul_test.go +++ b/client/fingerprint/consul_test.go @@ -620,6 +620,7 @@ func TestConsulFingerprint_Fingerprint_oss(t *testing.T) { "unique.consul.name": "HAL9000", }, resp.Attributes) must.True(t, resp.Detected) + must.Eq(t, "dc1.HAL9000", resp.Links["consul"]) // consul now available must.NotNil(t, cf.clusters[structs.ConsulDefaultCluster]) @@ -711,6 +712,7 @@ func TestConsulFingerprint_Fingerprint_ent(t *testing.T) { "unique.consul.name": "HAL9000", }, resp.Attributes) must.True(t, resp.Detected) + must.Eq(t, "dc1.HAL9000", resp.Links["consul"]) // consul now available must.NotNil(t, cf.clusters[structs.ConsulDefaultCluster])