mirror of
https://github.com/status-im/consul.git
synced 2025-02-18 00:27:04 +00:00
http: add an X-Consul-Query-Backend header to responses
So that it is easier to detect and test when streaming is being used.
This commit is contained in:
parent
2e1e80266a
commit
16b21b0864
@ -723,6 +723,13 @@ func setMeta(resp http.ResponseWriter, m structs.QueryMetaCompat) {
|
|||||||
setLastContact(resp, m.GetLastContact())
|
setLastContact(resp, m.GetLastContact())
|
||||||
setKnownLeader(resp, m.GetKnownLeader())
|
setKnownLeader(resp, m.GetKnownLeader())
|
||||||
setConsistency(resp, m.GetConsistencyLevel())
|
setConsistency(resp, m.GetConsistencyLevel())
|
||||||
|
setQueryBackend(resp, m.GetBackend())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setQueryBackend(resp http.ResponseWriter, backend structs.QueryBackend) {
|
||||||
|
if b := backend.String(); b != "" {
|
||||||
|
resp.Header().Set("X-Consul-Query-Backend", b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setCacheMeta sets http response headers to indicate cache status.
|
// setCacheMeta sets http response headers to indicate cache status.
|
||||||
|
@ -44,6 +44,7 @@ type QueryMetaCompat interface {
|
|||||||
SetIndex(uint64)
|
SetIndex(uint64)
|
||||||
GetConsistencyLevel() string
|
GetConsistencyLevel() string
|
||||||
SetConsistencyLevel(string)
|
SetConsistencyLevel(string)
|
||||||
|
GetBackend() QueryBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetToken helps implement the QueryOptionsCompat interface
|
// GetToken helps implement the QueryOptionsCompat interface
|
||||||
@ -269,3 +270,7 @@ func (q *QueryMeta) SetIndex(index uint64) {
|
|||||||
func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
|
func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
|
||||||
q.ConsistencyLevel = consistencyLevel
|
q.ConsistencyLevel = consistencyLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *QueryMeta) GetBackend() QueryBackend {
|
||||||
|
return q.Backend
|
||||||
|
}
|
||||||
|
@ -339,6 +339,24 @@ func (w WriteRequest) HasTimedOut(start time.Time, rpcHoldTimeout, maxQueryTime,
|
|||||||
return time.Since(start) > rpcHoldTimeout
|
return time.Since(start) > rpcHoldTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryBackend int
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueryBackendBlocking QueryBackend = iota
|
||||||
|
QueryBackendStreaming
|
||||||
|
)
|
||||||
|
|
||||||
|
func (q QueryBackend) String() string {
|
||||||
|
switch q {
|
||||||
|
case QueryBackendBlocking:
|
||||||
|
return "blocking-query"
|
||||||
|
case QueryBackendStreaming:
|
||||||
|
return "streaming"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// QueryMeta allows a query response to include potentially
|
// QueryMeta allows a query response to include potentially
|
||||||
// useful metadata about a query
|
// useful metadata about a query
|
||||||
type QueryMeta struct {
|
type QueryMeta struct {
|
||||||
@ -363,6 +381,9 @@ type QueryMeta struct {
|
|||||||
// When NotModified is true, the response will not contain the result of
|
// When NotModified is true, the response will not contain the result of
|
||||||
// the query.
|
// the query.
|
||||||
NotModified bool
|
NotModified bool
|
||||||
|
|
||||||
|
// Backend used to handle this query, either blocking-query or streaming.
|
||||||
|
Backend QueryBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterRequest is used for the Catalog.Register endpoint
|
// RegisterRequest is used for the Catalog.Register endpoint
|
||||||
|
@ -2,6 +2,8 @@ package pbcommon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsRead is always true for QueryOption
|
// IsRead is always true for QueryOption
|
||||||
@ -97,6 +99,10 @@ func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
|
|||||||
q.ConsistencyLevel = consistencyLevel
|
q.ConsistencyLevel = consistencyLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *QueryMeta) GetBackend() structs.QueryBackend {
|
||||||
|
return structs.QueryBackend(0)
|
||||||
|
}
|
||||||
|
|
||||||
// WriteRequest only applies to writes, always false
|
// WriteRequest only applies to writes, always false
|
||||||
func (w WriteRequest) IsRead() bool {
|
func (w WriteRequest) IsRead() bool {
|
||||||
return false
|
return false
|
||||||
|
@ -99,6 +99,9 @@ While streaming is a significant optimization over long polling, it will not pop
|
|||||||
`X-Consul-LastContact` or `X-Consul-KnownLeader` response headers, because the required
|
`X-Consul-LastContact` or `X-Consul-KnownLeader` response headers, because the required
|
||||||
data is not available to the client.
|
data is not available to the client.
|
||||||
|
|
||||||
|
When the streaming backend is used, API responses will include the `X-Consul-Query-Backend`
|
||||||
|
header with a value of `streaming`.
|
||||||
|
|
||||||
|
|
||||||
## Hash-based Blocking Queries
|
## Hash-based Blocking Queries
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user