From ed35f508a75141faa7daa8847278d939ccdc3caf Mon Sep 17 00:00:00 2001 From: Javier Heredia Date: Fri, 2 Oct 2020 21:15:59 +0200 Subject: [PATCH] Add consul segment fingerprint (#7214) --- client/fingerprint/consul.go | 9 ++++++++- client/fingerprint/consul_test.go | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/fingerprint/consul.go b/client/fingerprint/consul.go index 8717f2f84d1..3b2fe405489 100644 --- a/client/fingerprint/consul.go +++ b/client/fingerprint/consul.go @@ -81,7 +81,13 @@ func (f *ConsulFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpri } else { f.logger.Warn("unable to fingerprint consul.datacenter") } - + if g, ok := info["Member"]["Tags"].(map[string]interface{}); ok { + if s, ok := g["segment"].(string); ok { + resp.AddAttribute("consul.segment", s) + } + } else { + f.logger.Warn("unable to fingerprint consul.segment") + } 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)) @@ -108,6 +114,7 @@ func (f *ConsulFingerprint) clearConsulAttributes(r *FingerprintResponse) { r.RemoveAttribute("consul.revision") r.RemoveAttribute("unique.consul.name") r.RemoveAttribute("consul.datacenter") + r.RemoveAttribute("consul.segment") r.RemoveLink("consul") } diff --git a/client/fingerprint/consul_test.go b/client/fingerprint/consul_test.go index 79dee85fa6b..4f0287fbfbc 100644 --- a/client/fingerprint/consul_test.go +++ b/client/fingerprint/consul_test.go @@ -44,6 +44,7 @@ func TestConsulFingerprint(t *testing.T) { assertNodeAttributeContains(t, response.Attributes, "consul.revision") assertNodeAttributeContains(t, response.Attributes, "unique.consul.name") assertNodeAttributeContains(t, response.Attributes, "consul.datacenter") + assertNodeAttributeContains(t, response.Attributes, "consul.segment") if _, ok := response.Links["consul"]; !ok { t.Errorf("Expected a link to consul, none found") @@ -152,6 +153,7 @@ const mockConsulResponse = ` "expect": "3", "port": "8300", "role": "consul", + "segment": "mysegment", "vsn": "2" }, "Status": 1, @@ -199,6 +201,7 @@ func TestConsulFingerprint_UnexpectedResponse(t *testing.T) { "consul.revision", "unique.consul.name", "consul.datacenter", + "consul.segment", } for _, attr := range attrs {