Fix whitespace with "make format".

This commit is contained in:
Julius Volz 2013-01-18 00:07:00 +01:00
parent 86e5edc7fe
commit a20bf35997
5 changed files with 64 additions and 65 deletions

View file

@ -7,6 +7,6 @@ import (
type MetricsService struct { type MetricsService struct {
gorest.RestService `root:"/api/" consumes:"application/json" produces:"application/json"` gorest.RestService `root:"/api/" consumes:"application/json" produces:"application/json"`
query gorest.EndPoint `method:"GET" path:"/query?{expr:string}&{json:string}" output:"string"` query gorest.EndPoint `method:"GET" path:"/query?{expr:string}&{json:string}" output:"string"`
queryRange gorest.EndPoint `method:"GET" path:"/query_range?{expr:string}&{end:int64}&{range:int64}&{step:int64}" output:"string"` queryRange gorest.EndPoint `method:"GET" path:"/query_range?{expr:string}&{end:int64}&{range:int64}&{step:int64}" output:"string"`
} }

View file

@ -4,7 +4,7 @@ import (
"code.google.com/p/gorest" "code.google.com/p/gorest"
"github.com/matttproud/prometheus/rules" "github.com/matttproud/prometheus/rules"
"github.com/matttproud/prometheus/rules/ast" "github.com/matttproud/prometheus/rules/ast"
"sort" "sort"
"time" "time"
) )
@ -34,33 +34,33 @@ func (serv MetricsService) QueryRange(Expr string, End int64, Range int64, Step
if err != nil { if err != nil {
return err.Error() return err.Error()
} }
if exprNode.Type() != ast.VECTOR { if exprNode.Type() != ast.VECTOR {
return "Expression does not evaluate to vector type" // TODO return errors correctly everywhere return "Expression does not evaluate to vector type" // TODO return errors correctly everywhere
} }
rb := serv.ResponseBuilder() rb := serv.ResponseBuilder()
rb.SetContentType(gorest.Application_Json) rb.SetContentType(gorest.Application_Json)
if End == 0 { if End == 0 {
End = time.Now().Unix() End = time.Now().Unix()
} }
if Step < 1 { if Step < 1 {
Step = 1 Step = 1
} }
if End - Range < 0 { if End-Range < 0 {
Range = End Range = End
} }
// Align the start to step "tick" boundary. // Align the start to step "tick" boundary.
End -= End % Step End -= End % Step
matrix := ast.EvalVectorRange( matrix := ast.EvalVectorRange(
exprNode.(ast.VectorNode), exprNode.(ast.VectorNode),
time.Unix(End - Range, 0), time.Unix(End-Range, 0),
time.Unix(End, 0), time.Unix(End, 0),
time.Duration(Step) * time.Second) time.Duration(Step)*time.Second)
sort.Sort(matrix) sort.Sort(matrix)
return ast.TypedValueToJSON(matrix, "matrix") return ast.TypedValueToJSON(matrix, "matrix")
} }

View file

@ -14,8 +14,8 @@
package model package model
import ( import (
"fmt"
"time" "time"
"fmt"
) )
// A Fingerprint is a simplified representation of an entity---e.g., a hash of // A Fingerprint is a simplified representation of an entity---e.g., a hash of
@ -47,11 +47,11 @@ type Metric map[LabelName]LabelValue
type SampleValue float32 type SampleValue float32
func (v SampleValue) MarshalJSON() ([]byte, error) { func (v SampleValue) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%f\"", v)), nil return []byte(fmt.Sprintf("\"%f\"", v)), nil
} }
func (s SamplePair) MarshalJSON() ([]byte, error) { func (s SamplePair) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("{\"Value\": \"%f\", \"Timestamp\": %d}", s.Value, s.Timestamp.Unix())), nil return []byte(fmt.Sprintf("{\"Value\": \"%f\", \"Timestamp\": %d}", s.Value, s.Timestamp.Unix())), nil
} }
type Sample struct { type Sample struct {

View file

@ -2,11 +2,11 @@ package ast
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/matttproud/prometheus/model" "github.com/matttproud/prometheus/model"
"log" "log"
"math" "math"
"sort" "sort"
"strings" "strings"
"time" "time"
) )
@ -219,41 +219,41 @@ func (node *VectorAggregation) labelsToGroupingKey(labels model.Metric) string {
} }
func labelsToKey(labels model.Metric) string { func labelsToKey(labels model.Metric) string {
keyParts := []string{} keyParts := []string{}
for label, value := range labels { for label, value := range labels {
keyParts = append(keyParts, fmt.Sprintf("%v='%v'", label, value)) keyParts = append(keyParts, fmt.Sprintf("%v='%v'", label, value))
} }
sort.Strings(keyParts) sort.Strings(keyParts)
return strings.Join(keyParts, ",") // TODO not safe when label value contains comma. return strings.Join(keyParts, ",") // TODO not safe when label value contains comma.
} }
func EvalVectorRange(node VectorNode, start time.Time, end time.Time, step time.Duration) Matrix { func EvalVectorRange(node VectorNode, start time.Time, end time.Time, step time.Duration) Matrix {
// TODO implement watchdog timer for long-running queries. // TODO implement watchdog timer for long-running queries.
sampleSets := map[string]*model.SampleSet{} sampleSets := map[string]*model.SampleSet{}
for t := start; t.Before(end); t = t.Add(step) { for t := start; t.Before(end); t = t.Add(step) {
vector := node.Eval(&t) vector := node.Eval(&t)
for _, sample := range vector { for _, sample := range vector {
samplePair := model.SamplePair{ samplePair := model.SamplePair{
Value: sample.Value, Value: sample.Value,
Timestamp: sample.Timestamp, Timestamp: sample.Timestamp,
} }
groupingKey := labelsToKey(sample.Metric) groupingKey := labelsToKey(sample.Metric)
if sampleSets[groupingKey] == nil { if sampleSets[groupingKey] == nil {
sampleSets[groupingKey] = &model.SampleSet{ sampleSets[groupingKey] = &model.SampleSet{
Metric: sample.Metric, Metric: sample.Metric,
Values: []model.SamplePair{samplePair}, Values: []model.SamplePair{samplePair},
} }
} else { } else {
sampleSets[groupingKey].Values = append(sampleSets[groupingKey].Values, samplePair) sampleSets[groupingKey].Values = append(sampleSets[groupingKey].Values, samplePair)
} }
} }
} }
matrix := Matrix{} matrix := Matrix{}
for _, sampleSet := range sampleSets { for _, sampleSet := range sampleSets {
matrix = append(matrix, sampleSet) matrix = append(matrix, sampleSet)
} }
return matrix return matrix
} }
func labelIntersection(metric1, metric2 model.Metric) model.Metric { func labelIntersection(metric1, metric2 model.Metric) model.Metric {
@ -526,18 +526,17 @@ func (node *MatrixLiteral) EvalBoundaries(timestamp *time.Time) Matrix {
} }
func (matrix Matrix) Len() int { func (matrix Matrix) Len() int {
return len(matrix) return len(matrix)
} }
func (matrix Matrix) Less(i, j int) bool { func (matrix Matrix) Less(i, j int) bool {
return labelsToKey(matrix[i].Metric) < labelsToKey(matrix[j].Metric) return labelsToKey(matrix[i].Metric) < labelsToKey(matrix[j].Metric)
} }
func (matrix Matrix) Swap(i, j int) { func (matrix Matrix) Swap(i, j int) {
matrix[i], matrix[j] = matrix[j], matrix[i] matrix[i], matrix[j] = matrix[j], matrix[i]
} }
func (node *StringLiteral) Eval(timestamp *time.Time) string { func (node *StringLiteral) Eval(timestamp *time.Time) string {
return node.str return node.str
} }

View file

@ -85,7 +85,7 @@ func (vector Vector) ToString() string {
labelStrings := []string{} labelStrings := []string{}
for label, value := range sample.Metric { for label, value := range sample.Metric {
if label != "name" { if label != "name" {
// TODO escape special chars in label values here and elsewhere. // TODO escape special chars in label values here and elsewhere.
labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value)) labelStrings = append(labelStrings, fmt.Sprintf("%v='%v'", label, value))
} }
} }