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:
Dhia Ayachi 2022-04-14 12:48:19 -04:00 committed by GitHub
parent 7ce5abe928
commit acf9a9799e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

3
.changelog/12791.txt Normal file
View File

@ -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).
```

View File

@ -80,6 +80,12 @@ const (
// HTTPPartitionEnvName defines an environment variable name which sets // HTTPPartitionEnvName defines an environment variable name which sets
// the HTTP Partition to be used by default. This can still be overridden. // the HTTP Partition to be used by default. This can still be overridden.
HTTPPartitionEnvName = "CONSUL_PARTITION" HTTPPartitionEnvName = "CONSUL_PARTITION"
// QueryBackendStreaming Query backend of type streaming
QueryBackendStreaming = "streaming"
// QueryBackendBlockingQuery Query backend of type blocking query
QueryBackendBlockingQuery = "blocking-query"
) )
type StatusError struct { type StatusError struct {
@ -277,6 +283,9 @@ type QueryMeta struct {
// response is. // response is.
CacheAge time.Duration CacheAge time.Duration
// QueryBackend represent which backend served the request.
QueryBackend string
// DefaultACLPolicy is used to control the ACL interaction when there is no // DefaultACLPolicy is used to control the ACL interaction when there is no
// defined policy. This can be "allow" which means ACLs are used to // defined policy. This can be "allow" which means ACLs are used to
// deny-list, or "deny" which means ACLs are allow-lists. // 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 q.CacheAge = time.Duration(age) * time.Second
} }
switch v := header.Get("X-Consul-Query-Backend"); v {
case QueryBackendStreaming, QueryBackendBlockingQuery:
q.QueryBackend = v
}
return nil return nil
} }