From 09f2dd4d59ca708a0c48094a4717cec09bb4acc4 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Thu, 14 Apr 2022 12:48:19 -0400 Subject: [PATCH] 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> --- .changelog/12791.txt | 3 +++ api/api.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .changelog/12791.txt diff --git a/.changelog/12791.txt b/.changelog/12791.txt new file mode 100644 index 0000000000..e7e1a7387c --- /dev/null +++ b/.changelog/12791.txt @@ -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). +``` diff --git a/api/api.go b/api/api.go index d97f1879f2..8cc771c082 100644 --- a/api/api.go +++ b/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 }