add queryBackend to the api query meta. (#12791)
* add queryBackend to the api query meta. * add a changelog * use string type instead of int * Apply suggestions from code review Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com> Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
This commit is contained in:
parent
7ce5abe928
commit
acf9a9799e
|
@ -0,0 +1,3 @@
|
|||
```release-note:enhancement
|
||||
api: add QueryBackend to QueryMeta so an api user can determine if a query was served using which backend (streaming or blocking query).
|
||||
```
|
13
api/api.go
13
api/api.go
|
@ -80,6 +80,12 @@ const (
|
|||
// HTTPPartitionEnvName defines an environment variable name which sets
|
||||
// the HTTP Partition to be used by default. This can still be overridden.
|
||||
HTTPPartitionEnvName = "CONSUL_PARTITION"
|
||||
|
||||
// QueryBackendStreaming Query backend of type streaming
|
||||
QueryBackendStreaming = "streaming"
|
||||
|
||||
// QueryBackendBlockingQuery Query backend of type blocking query
|
||||
QueryBackendBlockingQuery = "blocking-query"
|
||||
)
|
||||
|
||||
type StatusError struct {
|
||||
|
@ -277,6 +283,9 @@ type QueryMeta struct {
|
|||
// response is.
|
||||
CacheAge time.Duration
|
||||
|
||||
// QueryBackend represent which backend served the request.
|
||||
QueryBackend string
|
||||
|
||||
// DefaultACLPolicy is used to control the ACL interaction when there is no
|
||||
// defined policy. This can be "allow" which means ACLs are used to
|
||||
// deny-list, or "deny" which means ACLs are allow-lists.
|
||||
|
@ -1096,6 +1105,10 @@ func parseQueryMeta(resp *http.Response, q *QueryMeta) error {
|
|||
q.CacheAge = time.Duration(age) * time.Second
|
||||
}
|
||||
|
||||
switch v := header.Get("X-Consul-Query-Backend"); v {
|
||||
case QueryBackendStreaming, QueryBackendBlockingQuery:
|
||||
q.QueryBackend = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue