changes to support new PQ enterprise fields (#16793)

This commit is contained in:
Michael Wilkerson 2023-03-27 15:40:49 -07:00 committed by GitHub
parent bd4a01f38f
commit baa1fd3cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 486 additions and 309 deletions

3
.changelog/_4821.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
connect: **(Enterprise Only)** Add support for specifying "Partition" and "Namespace" in Prepared Queries failover rules.
```

View File

@ -718,13 +718,13 @@ func queryFailover(q queryServer, query structs.PreparedQuery,
return err
}
// This will help us filter unknown DCs supplied by the user.
// This will help us filter unknown targets supplied by the user.
known := make(map[string]struct{})
for _, dc := range nearest {
known[dc] = struct{}{}
}
// Build a candidate list of DCs to try, starting with the nearest N
// Build a candidate list of failover targets to try, starting with the nearest N target
// from RTTs.
var targets []structs.QueryFailoverTarget
index := make(map[string]struct{})
@ -739,9 +739,9 @@ func queryFailover(q queryServer, query structs.PreparedQuery,
}
}
// Then add any DCs explicitly listed that weren't selected above.
// Then add any targets explicitly listed that weren't selected above.
for _, target := range query.Service.Failover.AsTargets() {
// This will prevent a log of other log spammage if we do not
// This will prevent a log of other log spam if we do not
// attempt to talk to datacenters we don't know about.
if dc := target.Datacenter; dc != "" {
if _, ok := known[dc]; !ok {
@ -753,15 +753,16 @@ func queryFailover(q queryServer, query structs.PreparedQuery,
// from the NearestN list.
if _, ok := index[dc]; !ok {
targets = append(targets, target)
continue
}
}
if target.Peer != "" {
if target.Peer != "" || target.PartitionOrEmpty() != "" || target.NamespaceOrEmpty() != "" {
targets = append(targets, target)
}
}
// Now try the selected DCs in priority order.
// Now try the selected targets in priority order.
failovers := 0
for _, target := range targets {
// This keeps track of how many iterations we actually run.
@ -775,9 +776,10 @@ func queryFailover(q queryServer, query structs.PreparedQuery,
// through this slice across successive RPC calls.
reply.Nodes = nil
// Reset PeerName because it may have been set by a previous failover
// Reset Peer, because it may have been set by a previous failover
// target.
query.Service.Peer = target.Peer
query.Service.EnterpriseMeta = target.EnterpriseMeta
dc := target.Datacenter
if target.Peer != "" {
dc = q.GetLocalDC()
@ -800,6 +802,7 @@ func queryFailover(q queryServer, query structs.PreparedQuery,
"service", query.Service.Service,
"peerName", query.Service.Peer,
"datacenter", dc,
"enterpriseMeta", query.Service.EnterpriseMeta,
"error", err,
)
continue

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ type preparedQueryCreateResponse struct {
}
// preparedQueryCreate makes a new prepared query.
func (s *HTTPHandlers) preparedQueryCreate(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
func (s *HTTPHandlers) preparedQueryCreate(_ http.ResponseWriter, req *http.Request) (interface{}, error) {
args := structs.PreparedQueryRequest{
Op: structs.PreparedQueryCreate,
}

View File

@ -47,6 +47,8 @@ type QueryFailoverTarget struct {
// Datacenter specifies a datacenter to try during failover.
Datacenter string
acl.EnterpriseMeta
}
// QueryDNSOptions controls settings when query results are served over DNS.

View File

@ -26,6 +26,14 @@ type QueryFailoverTarget struct {
// Datacenter specifies a datacenter to try during failover.
Datacenter string
// Partition specifies a partition to try during failover
// Note: Partition are available only in Consul Enterprise
Partition string
// Namespace specifies a namespace to try during failover
// Note: Namespaces are available only in Consul Enterprise
Namespace string
}
// QueryDNSOptions controls settings when query results are served over DNS.

View File

@ -10,7 +10,7 @@ The `/query` endpoints create, update, destroy, and execute prepared queries.
Prepared queries allow you to register a complex service query and then execute
it later by specifying the query ID or name. Consul returns a set of healthy nodes that provide a given
service. Refer to
service. Refer to
[Enable Dynamic DNS Queries](/consul/docs/services/discovery/dns-dynamic-lookups) for additional information.
Check the [Geo Failover tutorial](/consul/tutorials/developer-discovery/automate-geo-failover) for details and
@ -212,6 +212,12 @@ The table below shows this endpoint's support for
- `Datacenter` `(string: "")` - Specifies a WAN federated datacenter to forward the
query to.
- `Partition` `(string: "")` <EnterpriseAlert inline /> - Specifies a Partition to forward the
query to.
- `Namespace` `(string: "")` <EnterpriseAlert inline /> - Specifies a Namespace to forward the
query to.
- `IgnoreCheckIDs` `(array<string>: nil)` - Specifies a list of check IDs that
should be ignored when filtering unhealthy instances. This is mostly useful
in an emergency or as a temporary measure when a health check is found to be