mirror of
https://github.com/prometheus/prometheus
synced 2025-01-13 02:14:08 +00:00
efe61c18fa
``Target`` will be refactored down the road to support various nuanced endpoint types. Thusly incorporating the scheduling behavior within it will be problematic. To that end, the scheduling behavior has been moved into a separate assistance type to improve conciseness and testability. ``make format`` was also run.
30 lines
640 B
Go
30 lines
640 B
Go
package api
|
|
|
|
import (
|
|
"code.google.com/p/gorest"
|
|
"github.com/matttproud/prometheus/rules"
|
|
"github.com/matttproud/prometheus/rules/ast"
|
|
"time"
|
|
)
|
|
|
|
func (serv MetricsService) Query(Expr string, Json string, Start string, End string) (result string) {
|
|
exprNode, err := rules.LoadExprFromString(Expr)
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
|
|
timestamp := time.Now()
|
|
|
|
rb := serv.ResponseBuilder()
|
|
var format ast.OutputFormat
|
|
if Json != "" {
|
|
format = ast.JSON
|
|
rb.SetContentType(gorest.Application_Json)
|
|
} else {
|
|
format = ast.TEXT
|
|
rb.SetContentType(gorest.Text_Plain)
|
|
}
|
|
|
|
return ast.EvalToString(exprNode, ×tamp, format)
|
|
}
|