diff --git a/web/api/query.go b/web/api/query.go index f007cd97a..9448acc3b 100644 --- a/web/api/query.go +++ b/web/api/query.go @@ -25,8 +25,8 @@ import ( "time" ) -func (serv MetricsService) Query(Expr string, Json string) (result string) { - exprNode, err := rules.LoadExprFromString(Expr) +func (serv MetricsService) Query(expr string, formatJson string) (result string) { + exprNode, err := rules.LoadExprFromString(expr) if err != nil { return ast.ErrorToJSON(err) } @@ -35,7 +35,7 @@ func (serv MetricsService) Query(Expr string, Json string) (result string) { rb := serv.ResponseBuilder() var format ast.OutputFormat - if Json != "" { + if formatJson != "" { format = ast.JSON rb.SetContentType(gorest.Application_Json) } else { @@ -46,8 +46,8 @@ func (serv MetricsService) Query(Expr string, Json string) (result string) { return ast.EvalToString(exprNode, ×tamp, format) } -func (serv MetricsService) QueryRange(Expr string, End int64, Range int64, Step int64) string { - exprNode, err := rules.LoadExprFromString(Expr) +func (serv MetricsService) QueryRange(expr string, end int64, duration int64, step int64) string { + exprNode, err := rules.LoadExprFromString(expr) if err != nil { return ast.ErrorToJSON(err) } @@ -57,26 +57,26 @@ func (serv MetricsService) QueryRange(Expr string, End int64, Range int64, Step rb := serv.ResponseBuilder() rb.SetContentType(gorest.Application_Json) - if End == 0 { - End = serv.time.Now().Unix() + if end == 0 { + end = serv.time.Now().Unix() } - if Step < 1 { - Step = 1 + if step < 1 { + step = 1 } - if End-Range < 0 { - Range = End + if end-duration < 0 { + duration = end } // Align the start to step "tick" boundary. - End -= End % Step + end -= end % step matrix := ast.EvalVectorRange( exprNode.(ast.VectorNode), - time.Unix(End-Range, 0), - time.Unix(End, 0), - time.Duration(Step)*time.Second) + time.Unix(end-duration, 0), + time.Unix(end, 0), + time.Duration(step)*time.Second) sort.Sort(matrix) return ast.TypedValueToJSON(matrix, "matrix")