github.com/go-graphite/carbonapi@v0.17.0/expr/functions/slo/helpers.go (about) 1 package slo 2 3 import ( 4 "fmt" 5 6 "github.com/go-graphite/carbonapi/pkg/parser" 7 ) 8 9 func (f *slo) buildDataPoint(bucketQtyMatched, bucketQtyNotNull int) (isAbsent bool, value float64) { 10 if bucketQtyNotNull == 0 { 11 isAbsent = true 12 value = 0.0 13 } else { 14 isAbsent = false 15 value = float64(bucketQtyMatched) / float64(bucketQtyNotNull) 16 } 17 return 18 } 19 20 func (f *slo) buildMethod(e parser.Expr, argNumber int, value float64) (func(float64) bool, string, error) { 21 var methodFoo func(float64) bool = nil 22 23 methodName, err := e.GetStringArg(argNumber) 24 if err != nil { 25 return nil, methodName, err 26 } 27 28 if methodName == "above" { 29 methodFoo = func(testedValue float64) bool { 30 return testedValue > value 31 } 32 } 33 34 if methodName == "aboveOrEqual" { 35 methodFoo = func(testedValue float64) bool { 36 return testedValue >= value 37 } 38 } 39 40 if methodName == "below" { 41 methodFoo = func(testedValue float64) bool { 42 return testedValue < value 43 } 44 } 45 46 if methodName == "belowOrEqual" { 47 methodFoo = func(testedValue float64) bool { 48 return testedValue <= value 49 } 50 } 51 52 if methodFoo == nil { 53 return nil, methodName, fmt.Errorf("unknown method `%s`", methodName) 54 } 55 56 return methodFoo, methodName, nil 57 }