mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
Fixes all the racy output-side updates to tags.
This commit is contained in:
parent
11f6961e47
commit
1c6de1d623
@ -170,10 +170,11 @@ func (s *HTTPServer) AgentChecks(resp http.ResponseWriter, req *http.Request) (i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use empty list instead of nil
|
// Use empty list instead of nil
|
||||||
// checks needs to be a deep copy for this not be racy
|
for id, c := range checks {
|
||||||
for _, c := range checks {
|
|
||||||
if c.ServiceTags == nil {
|
if c.ServiceTags == nil {
|
||||||
c.ServiceTags = make([]string, 0)
|
clone := *c
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
checks[id] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,9 +201,11 @@ func (s *HTTPServer) CatalogServiceNodes(resp http.ResponseWriter, req *http.Req
|
|||||||
if out.ServiceNodes == nil {
|
if out.ServiceNodes == nil {
|
||||||
out.ServiceNodes = make(structs.ServiceNodes, 0)
|
out.ServiceNodes = make(structs.ServiceNodes, 0)
|
||||||
}
|
}
|
||||||
for _, s := range out.ServiceNodes {
|
for i, s := range out.ServiceNodes {
|
||||||
if s.ServiceTags == nil {
|
if s.ServiceTags == nil {
|
||||||
s.ServiceTags = make([]string, 0)
|
clone := *s
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
out.ServiceNodes[i] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
metrics.IncrCounterWithLabels([]string{"client", "api", "success", "catalog_service_nodes"}, 1,
|
metrics.IncrCounterWithLabels([]string{"client", "api", "success", "catalog_service_nodes"}, 1,
|
||||||
|
@ -42,9 +42,11 @@ func (s *HTTPServer) HealthChecksInState(resp http.ResponseWriter, req *http.Req
|
|||||||
if out.HealthChecks == nil {
|
if out.HealthChecks == nil {
|
||||||
out.HealthChecks = make(structs.HealthChecks, 0)
|
out.HealthChecks = make(structs.HealthChecks, 0)
|
||||||
}
|
}
|
||||||
for _, c := range out.HealthChecks {
|
for i, c := range out.HealthChecks {
|
||||||
if c.ServiceTags == nil {
|
if c.ServiceTags == nil {
|
||||||
c.ServiceTags = make([]string, 0)
|
clone := *c
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
out.HealthChecks[i] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.HealthChecks, nil
|
return out.HealthChecks, nil
|
||||||
@ -80,9 +82,11 @@ func (s *HTTPServer) HealthNodeChecks(resp http.ResponseWriter, req *http.Reques
|
|||||||
if out.HealthChecks == nil {
|
if out.HealthChecks == nil {
|
||||||
out.HealthChecks = make(structs.HealthChecks, 0)
|
out.HealthChecks = make(structs.HealthChecks, 0)
|
||||||
}
|
}
|
||||||
for _, c := range out.HealthChecks {
|
for i, c := range out.HealthChecks {
|
||||||
if c.ServiceTags == nil {
|
if c.ServiceTags == nil {
|
||||||
c.ServiceTags = make([]string, 0)
|
clone := *c
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
out.HealthChecks[i] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.HealthChecks, nil
|
return out.HealthChecks, nil
|
||||||
@ -120,9 +124,11 @@ func (s *HTTPServer) HealthServiceChecks(resp http.ResponseWriter, req *http.Req
|
|||||||
if out.HealthChecks == nil {
|
if out.HealthChecks == nil {
|
||||||
out.HealthChecks = make(structs.HealthChecks, 0)
|
out.HealthChecks = make(structs.HealthChecks, 0)
|
||||||
}
|
}
|
||||||
for _, c := range out.HealthChecks {
|
for i, c := range out.HealthChecks {
|
||||||
if c.ServiceTags == nil {
|
if c.ServiceTags == nil {
|
||||||
c.ServiceTags = make([]string, 0)
|
clone := *c
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
out.HealthChecks[i] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.HealthChecks, nil
|
return out.HealthChecks, nil
|
||||||
@ -194,19 +200,20 @@ func (s *HTTPServer) HealthServiceNodes(resp http.ResponseWriter, req *http.Requ
|
|||||||
out.Nodes = make(structs.CheckServiceNodes, 0)
|
out.Nodes = make(structs.CheckServiceNodes, 0)
|
||||||
}
|
}
|
||||||
for i := range out.Nodes {
|
for i := range out.Nodes {
|
||||||
// TODO (slackpad) It's lame that this isn't a slice of pointers
|
|
||||||
// but it's not a well-scoped change to fix this. We should
|
|
||||||
// change this at the next opportunity.
|
|
||||||
if out.Nodes[i].Checks == nil {
|
if out.Nodes[i].Checks == nil {
|
||||||
out.Nodes[i].Checks = make(structs.HealthChecks, 0)
|
out.Nodes[i].Checks = make(structs.HealthChecks, 0)
|
||||||
}
|
}
|
||||||
for _, c := range out.Nodes[i].Checks {
|
for j, c := range out.Nodes[i].Checks {
|
||||||
if c.ServiceTags == nil {
|
if c.ServiceTags == nil {
|
||||||
c.ServiceTags = make([]string, 0)
|
clone := *c
|
||||||
|
clone.ServiceTags = make([]string, 0)
|
||||||
|
out.Nodes[i].Checks[j] = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if out.Nodes[i].Service != nil && out.Nodes[i].Service.Tags == nil {
|
if out.Nodes[i].Service != nil && out.Nodes[i].Service.Tags == nil {
|
||||||
out.Nodes[i].Service.Tags = make([]string, 0)
|
clone := *out.Nodes[i].Service
|
||||||
|
clone.Tags = make([]string, 0)
|
||||||
|
out.Nodes[i].Service = &clone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.Nodes, nil
|
return out.Nodes, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user