mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Merge pull request #900 from prometheus/fabxc/scalar
Restore legacy API scalar format
This commit is contained in:
commit
0924e7c830
|
@ -55,20 +55,25 @@ func TestQuery(t *testing.T) {
|
|||
status: http.StatusOK,
|
||||
bodyRe: `{"type":"error","value":"Parse error at char 1: no expression found in input","version":1}`,
|
||||
},
|
||||
{
|
||||
queryStr: "expr=1.4",
|
||||
status: http.StatusOK,
|
||||
bodyRe: `{"type":"scalar","value":"1.4","version":1}`,
|
||||
},
|
||||
{
|
||||
queryStr: "expr=testmetric",
|
||||
status: http.StatusOK,
|
||||
bodyRe: `{"type":"vector","value":\[\{"metric":{"__name__":"testmetric"},"value":"0","timestamp":\d+\.\d+}\],"version":1\}`,
|
||||
bodyRe: `{"type":"vector","value":\[{"metric":{"__name__":"testmetric"},"value":"0","timestamp":\d+\.\d+}\],"version":1}`,
|
||||
},
|
||||
{
|
||||
queryStr: "expr=testmetric×tamp=" + testTimestamp.String(),
|
||||
status: http.StatusOK,
|
||||
bodyRe: `{"type":"vector","value":\[\{"metric":{"__name__":"testmetric"},"value":"0","timestamp":` + testTimestamp.String() + `}\],"version":1\}`,
|
||||
bodyRe: `{"type":"vector","value":\[{"metric":{"__name__":"testmetric"},"value":"0","timestamp":` + testTimestamp.String() + `}\],"version":1}`,
|
||||
},
|
||||
{
|
||||
queryStr: "expr=testmetric×tamp=" + testTimestamp.Add(-time.Hour).String(),
|
||||
status: http.StatusOK,
|
||||
bodyRe: `{"type":"vector","value":\[\],"version":1\}`,
|
||||
bodyRe: `{"type":"vector","value":\[\],"version":1}`,
|
||||
},
|
||||
{
|
||||
queryStr: "timestamp=invalid",
|
||||
|
|
|
@ -133,11 +133,16 @@ func (pv plainVec) String() string {
|
|||
// which does not fit the response format for the legacy API.
|
||||
type plainScalar promql.Scalar
|
||||
|
||||
func (pv plainScalar) Type() promql.ExprType {
|
||||
func (ps plainScalar) MarshalJSON() ([]byte, error) {
|
||||
s := strconv.FormatFloat(float64(ps.Value), 'f', -1, 64)
|
||||
return json.Marshal(&s)
|
||||
}
|
||||
|
||||
func (plainScalar) Type() promql.ExprType {
|
||||
return promql.ExprScalar
|
||||
}
|
||||
|
||||
func (pv plainScalar) String() string {
|
||||
func (plainScalar) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue