Skip to content

Commit

Permalink
Add consul segment fingerprint (hashicorp#7214)
Browse files Browse the repository at this point in the history
  • Loading branch information
daktari authored and fredrikhgrelland committed Oct 22, 2020
1 parent e71de8d commit ed35f50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/fingerprint/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")
}

Expand Down
3 changes: 3 additions & 0 deletions client/fingerprint/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -152,6 +153,7 @@ const mockConsulResponse = `
"expect": "3",
"port": "8300",
"role": "consul",
"segment": "mysegment",
"vsn": "2"
},
"Status": 1,
Expand Down Expand Up @@ -199,6 +201,7 @@ func TestConsulFingerprint_UnexpectedResponse(t *testing.T) {
"consul.revision",
"unique.consul.name",
"consul.datacenter",
"consul.segment",
}

for _, attr := range attrs {
Expand Down

0 comments on commit ed35f50

Please sign in to comment.