mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 17:44:06 -08:00
remote write handler to checks version header
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
This commit is contained in:
parent
55c99d4efd
commit
ffa37767e5
|
@ -83,7 +83,7 @@ func init() {
|
|||
type Client struct {
|
||||
remoteName string // Used to differentiate clients in metrics.
|
||||
urlString string // url.String()
|
||||
remotewrite11 bool // For write clients, ignored for read clients.
|
||||
remoteWrite11 bool // For write clients, ignored for read clients.
|
||||
Client *http.Client
|
||||
timeout time.Duration
|
||||
|
||||
|
@ -165,7 +165,7 @@ func NewWriteClient(name string, conf *ClientConfig) (WriteClient, error) {
|
|||
httpClient.Transport = otelhttp.NewTransport(t)
|
||||
|
||||
return &Client{
|
||||
remotewrite11: conf.RemoteWrite11,
|
||||
remoteWrite11: conf.RemoteWrite11,
|
||||
remoteName: name,
|
||||
urlString: conf.URL.String(),
|
||||
Client: httpClient,
|
||||
|
@ -212,10 +212,10 @@ func (c *Client) Store(ctx context.Context, req []byte, attempt int) error {
|
|||
httpReq.Header.Set("User-Agent", UserAgent)
|
||||
|
||||
// Set the right header if we're using v1.1 remote write protocol
|
||||
if c.remotewrite11 {
|
||||
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.1") // TODO-RW11: Final value?
|
||||
if c.remoteWrite11 {
|
||||
httpReq.Header.Set(RemoteWriteVersionHeader, RemoteWriteVersion11HeaderValue)
|
||||
} else {
|
||||
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
|
||||
httpReq.Header.Set(RemoteWriteVersionHeader, RemoteWriteVersion1HeaderValue)
|
||||
}
|
||||
|
||||
if attempt > 0 {
|
||||
|
|
|
@ -32,6 +32,12 @@ import (
|
|||
otlptranslator "github.com/prometheus/prometheus/storage/remote/otlptranslator/prometheusremotewrite"
|
||||
)
|
||||
|
||||
const (
|
||||
RemoteWriteVersionHeader = "X-Prometheus-Remote-Write-Version"
|
||||
RemoteWriteVersion1HeaderValue = "0.1.0"
|
||||
RemoteWriteVersion11HeaderValue = "1.1" // TODO-RW11: Final value?
|
||||
)
|
||||
|
||||
type writeHandler struct {
|
||||
logger log.Logger
|
||||
appendable storage.Appendable
|
||||
|
@ -68,8 +74,7 @@ func (h *writeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
var err error
|
||||
var req *prompb.WriteRequest
|
||||
var reqWithRefs *prompb.WriteRequestWithRefs
|
||||
// TODO-RW11: Need to check headers to decide what version is and what to do
|
||||
if h.enableRemoteWrite11 {
|
||||
if h.enableRemoteWrite11 && r.Header.Get(RemoteWriteVersionHeader) == RemoteWriteVersion11HeaderValue {
|
||||
reqWithRefs, err = DecodeReducedWriteRequest(r.Body)
|
||||
} else {
|
||||
req, err = DecodeWriteRequest(r.Body)
|
||||
|
|
|
@ -199,6 +199,7 @@ func BenchmarkReducedRemoteWriteHandler(b *testing.B) {
|
|||
require.NoError(b, err)
|
||||
req, err := http.NewRequest("", "", bytes.NewReader(buf))
|
||||
require.NoError(b, err)
|
||||
req.Header.Set(RemoteWriteVersionHeader, RemoteWriteVersion11HeaderValue)
|
||||
reqs = append(reqs, req)
|
||||
}
|
||||
|
||||
|
@ -298,6 +299,7 @@ func TestRemoteWriteHandlerReducedProtocol(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
req, err := http.NewRequest("", "", bytes.NewReader(buf))
|
||||
req.Header.Set(RemoteWriteVersionHeader, RemoteWriteVersion11HeaderValue)
|
||||
require.NoError(t, err)
|
||||
|
||||
appendable := &mockAppendable{}
|
||||
|
|
Loading…
Reference in a new issue