diff --git a/.changelog/12953.txt b/.changelog/12953.txt new file mode 100644 index 000000000000..82ed92b50a14 --- /dev/null +++ b/.changelog/12953.txt @@ -0,0 +1,3 @@ +```release-note:improvement +consul: Reduce load on Consul leader server by allowing stale results when listing namespaces. +``` diff --git a/command/agent/consul/namespaces_client.go b/command/agent/consul/namespaces_client.go index c2d8b082b328..7f7961bd2645 100644 --- a/command/agent/consul/namespaces_client.go +++ b/command/agent/consul/namespaces_client.go @@ -4,6 +4,8 @@ import ( "sort" "sync" "time" + + "github.com/hashicorp/consul/api" ) const ( @@ -66,8 +68,6 @@ func (ns *NamespacesClient) allowable(now time.Time) bool { } // List returns a list of Consul Namespaces. -// -// TODO(shoenig): return empty string instead of "default" when namespaces are not enabled. (Coming in followup PR). func (ns *NamespacesClient) List() ([]string, error) { if !ns.allowable(time.Now()) { // TODO(shoenig): lets return the empty string instead, that way we do not @@ -75,7 +75,10 @@ func (ns *NamespacesClient) List() ([]string, error) { return []string{"default"}, nil } - namespaces, _, err := ns.namespacesAPI.List(nil) + qo := &api.QueryOptions{ + AllowStale: true, + } + namespaces, _, err := ns.namespacesAPI.List(qo) if err != nil { return nil, err }