mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Use const for Arrow MIME type
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
This commit is contained in:
parent
692eb7e722
commit
4bb208eeb3
|
@ -84,6 +84,8 @@ const (
|
||||||
|
|
||||||
var LocalhostRepresentations = []string{"127.0.0.1", "localhost", "::1"}
|
var LocalhostRepresentations = []string{"127.0.0.1", "localhost", "::1"}
|
||||||
|
|
||||||
|
const mimeTypeArrowStream = "application/vnd.apache.arrow.stream"
|
||||||
|
|
||||||
type apiError struct {
|
type apiError struct {
|
||||||
typ errorType
|
typ errorType
|
||||||
err error
|
err error
|
||||||
|
@ -1572,7 +1574,7 @@ func (api *API) tryArrowResponse(w http.ResponseWriter, r *http.Request, data in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/vnd.apache.arrow.stream")
|
w.Header().Set("Content-Type", mimeTypeArrowStream)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
pool := memory.NewGoAllocator()
|
pool := memory.NewGoAllocator()
|
||||||
|
@ -1609,7 +1611,7 @@ func (api *API) tryArrowResponse(w http.ResponseWriter, r *http.Request, data in
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) respond(w http.ResponseWriter, r *http.Request, data interface{}, warnings storage.Warnings) {
|
func (api *API) respond(w http.ResponseWriter, r *http.Request, data interface{}, warnings storage.Warnings) {
|
||||||
if r.Header.Get("Accept") == "application/vnd.apache.arrow.stream" {
|
if r.Header.Get("Accept") == mimeTypeArrowStream {
|
||||||
err := api.tryArrowResponse(w, r, data, warnings)
|
err := api.tryArrowResponse(w, r, data, warnings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -3192,7 +3192,7 @@ func TestRespond(t *testing.T) {
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if useArrow {
|
if useArrow {
|
||||||
r.Header.Add("Accept", "application/vnd.apache.arrow.stream")
|
r.Header.Add("Accept", mimeTypeArrowStream)
|
||||||
}
|
}
|
||||||
api := API{}
|
api := API{}
|
||||||
api.respond(w, r, c.response, nil)
|
api.respond(w, r, c.response, nil)
|
||||||
|
@ -3204,7 +3204,7 @@ func TestRespond(t *testing.T) {
|
||||||
t.Fatalf("Error on test request: %s", err)
|
t.Fatalf("Error on test request: %s", err)
|
||||||
}
|
}
|
||||||
var body []byte
|
var body []byte
|
||||||
if resp.Header.Get("Content-Type") == "application/vnd.apache.arrow.stream" {
|
if resp.Header.Get("Content-Type") == mimeTypeArrowStream {
|
||||||
body, err = arrowToJSONResponse(resp.Body)
|
body, err = arrowToJSONResponse(resp.Body)
|
||||||
} else {
|
} else {
|
||||||
body, err = io.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
|
@ -3387,7 +3387,7 @@ func BenchmarkRespondArrow(b *testing.B) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
request, _ := http.NewRequest("GET", "http://localhost:9090", nil)
|
request, _ := http.NewRequest("GET", "http://localhost:9090", nil)
|
||||||
request.Header.Add("Accept", "application/vnd.apache.arrow.stream")
|
request.Header.Add("Accept", mimeTypeArrowStream)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
api := API{}
|
api := API{}
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
|
|
Loading…
Reference in a new issue