Skip to content

Commit

Permalink
add a conditional around setting LANFilter.AllSegments to make sure i…
Browse files Browse the repository at this point in the history
…t is valid (#18139)

This is to correct a code problem because this assumes all segments, but
when you get to Enterprise, you can be in partition that is not the
default partition, in which case specifying all segments does not
validate and fails. This is to correct the setting of this filter with
`AllSegments` to `true` to only occur when in the the `default`
partition.

<!--

* In the case of bugs, describe how to replicate
* If any manual tests were done, document the steps and the conditions
to replicate
* Call out any important/ relevant unit tests, e2e tests or integration
tests you have added or are adding

-->

<!--

Include any links here that might be helpful for people reviewing your
PR (Tickets, GH issues, API docs, external benchmarks, tools docs, etc).
If there are none, feel free to delete this section.

Please be mindful not to leak any customer or confidential information.
HashiCorp employees may want to use our internal URL shortener to
obfuscate links.

-->

* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
  • Loading branch information
jmurret committed Jul 17, 2023
1 parent 0b202a7 commit 713d067
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions agent/ui_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import (
"strings"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/serf/serf"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/config"
"github.com/hashicorp/consul/agent/consul"
"github.com/hashicorp/consul/agent/metadata"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/logging"
Expand Down Expand Up @@ -136,6 +139,47 @@ RPC:
return append(out.Dump, out.ImportedDump...), nil
}

// AgentMembersMapAddrVer is used to get version info from all serf members into a
// map of key-address,value-version.
func AgentMembersMapAddrVer(s *HTTPHandlers, req *http.Request) (map[string]string, error) {
var members []serf.Member

//Get WAN Members
wanMembers := s.agent.WANMembers()

//Get LAN Members
//Get the request partition and default to that of the agent.
entMeta := s.agent.AgentEnterpriseMeta()
if err := s.parseEntMetaPartition(req, entMeta); err != nil {
return nil, err
}
filter := consul.LANMemberFilter{
Partition: entMeta.PartitionOrDefault(),
}
if acl.IsDefaultPartition(filter.Partition) {
filter.AllSegments = true
}

lanMembers, err := s.agent.delegate.LANMembers(filter)
if err != nil {
return nil, err
}

//aggregate members
members = append(wanMembers, lanMembers...)

//create a map with key as IPv4 address and value as consul-version
mapAddrVer := make(map[string]string, len(members))
for i := range members {
buildVersion, err := metadata.Build(&members[i])
if err == nil {
mapAddrVer[members[i].Addr.String()] = buildVersion.String()
}
}

return mapAddrVer, nil
}

// UINodeInfo is used to get info on a single node in a given datacenter. We return a
// NodeInfo which provides overview information for the node
func (s *HTTPHandlers) UINodeInfo(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
Expand Down

0 comments on commit 713d067

Please sign in to comment.