mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 00:23:18 +00: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,
|
||||
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 New Issue
Block a user