mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Restore legacy API scalar format
This commit is contained in:
parent
742efb4538
commit
62b4e89b39
|
@ -55,20 +55,25 @@ func TestQuery(t *testing.T) {
|
||||||
status: http.StatusOK,
|
status: http.StatusOK,
|
||||||
bodyRe: `{"type":"error","value":"Parse error at char 1: no expression found in input","version":1}`,
|
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",
|
queryStr: "expr=testmetric",
|
||||||
status: http.StatusOK,
|
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(),
|
queryStr: "expr=testmetric×tamp=" + testTimestamp.String(),
|
||||||
status: http.StatusOK,
|
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(),
|
queryStr: "expr=testmetric×tamp=" + testTimestamp.Add(-time.Hour).String(),
|
||||||
status: http.StatusOK,
|
status: http.StatusOK,
|
||||||
bodyRe: `{"type":"vector","value":\[\],"version":1\}`,
|
bodyRe: `{"type":"vector","value":\[\],"version":1}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
queryStr: "timestamp=invalid",
|
queryStr: "timestamp=invalid",
|
||||||
|
|
|
@ -133,11 +133,16 @@ func (pv plainVec) String() string {
|
||||||
// which does not fit the response format for the legacy API.
|
// which does not fit the response format for the legacy API.
|
||||||
type plainScalar promql.Scalar
|
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
|
return promql.ExprScalar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pv plainScalar) String() string {
|
func (plainScalar) String() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue