mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Switch to json-iterator for v1 api.
This makes queries ~15% faster and cuts cpu time spent on json encoding by ~40%.
This commit is contained in:
parent
8ede14b24c
commit
299b78a887
|
@ -15,7 +15,6 @@ package v1
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
@ -28,6 +27,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/json-iterator/go"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/route"
|
||||
"github.com/prometheus/tsdb"
|
||||
|
@ -754,6 +754,7 @@ func respond(w http.ResponseWriter, data interface{}) {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
b, err := json.Marshal(&response{
|
||||
Status: statusSuccess,
|
||||
Data: data,
|
||||
|
@ -782,6 +783,7 @@ func respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) {
|
|||
}
|
||||
w.WriteHeader(code)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
b, err := json.Marshal(&response{
|
||||
Status: statusError,
|
||||
ErrorType: apiErr.typ,
|
||||
|
|
Loading…
Reference in a new issue