Allow custom timestamps in instant query API.

This commit is contained in:
Julius Volz 2015-03-20 23:10:58 +01:00
parent c78436d707
commit 8a4acefd66

View file

@ -47,6 +47,14 @@ func (serv MetricsService) Query(w http.ResponseWriter, r *http.Request) {
params := httputils.GetQueryParams(r) params := httputils.GetQueryParams(r)
expr := params.Get("expr") expr := params.Get("expr")
asText := params.Get("asText") asText := params.Get("asText")
tsFloat, _ := strconv.ParseFloat(params.Get("timestamp"), 64)
var timestamp clientmodel.Timestamp
if tsFloat == 0 {
timestamp = clientmodel.Now()
} else {
timestamp = clientmodel.TimestampFromUnixNano(int64(tsFloat) * int64(time.Second/time.Nanosecond))
}
var format ast.OutputFormat var format ast.OutputFormat
// BUG(julius): Use Content-Type negotiation. // BUG(julius): Use Content-Type negotiation.
@ -64,7 +72,6 @@ func (serv MetricsService) Query(w http.ResponseWriter, r *http.Request) {
return return
} }
timestamp := clientmodel.TimestampFromTime(serv.time.Now())
queryStats := stats.NewTimerGroup() queryStats := stats.NewTimerGroup()
result := ast.EvalToString(exprNode, timestamp, format, serv.Storage, queryStats) result := ast.EvalToString(exprNode, timestamp, format, serv.Storage, queryStats)
glog.V(1).Infof("Instant query: %s\nQuery stats:\n%s\n", expr, queryStats) glog.V(1).Infof("Instant query: %s\nQuery stats:\n%s\n", expr, queryStats)