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:
Brian Brazil 2017-12-02 13:52:59 +00:00
parent 8ede14b24c
commit 299b78a887

View File

@ -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,