@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "time"
1313
14+ "github.com/go-graphite/protocol/carbonapi_v3_pb"
1415 "github.com/lomik/graphite-clickhouse/helper/client"
1516 "github.com/lomik/graphite-clickhouse/helper/datetime"
1617 "github.com/lomik/graphite-clickhouse/helper/tests/compare"
@@ -271,6 +272,24 @@ func compareRender(errors *[]string, name, url string, actual, expected []client
271272 }
272273}
273274
275+ func parseFilteringFunctions (strFilteringFuncs []string ) ([]* carbonapi_v3_pb.FilteringFunction , error ) {
276+ res := make ([]* carbonapi_v3_pb.FilteringFunction , 0 , len (strFilteringFuncs ))
277+ for _ , strFF := range strFilteringFuncs {
278+ strFFSplit := strings .Split (strFF , "(" )
279+ if len (strFFSplit ) != 2 {
280+ return nil , fmt .Errorf ("could not parse filtering function: %s" , strFF )
281+ }
282+ name := strFFSplit [0 ]
283+ args := strings .Split (strFFSplit [1 ], "," )
284+ for i := range args {
285+ args [i ] = strings .TrimSpace (args [i ])
286+ args [i ] = strings .Trim (args [i ], ")'" )
287+ }
288+ res = append (res , & carbonapi_v3_pb.FilteringFunction {Name : name , Arguments : args })
289+ }
290+ return res , nil
291+ }
292+
274293func verifyRender (ch * Clickhouse , gch * GraphiteClickhouse , check * RenderCheck , defaultPreision time.Duration ) []string {
275294 var errors []string
276295 httpClient := http.Client {
@@ -280,7 +299,18 @@ func verifyRender(ch *Clickhouse, gch *GraphiteClickhouse, check *RenderCheck, d
280299 from := datetime .TimestampTruncate (check .from , defaultPreision )
281300 until := datetime .TimestampTruncate (check .until , defaultPreision )
282301 for _ , format := range check .Formats {
283- if url , result , respHeader , err := client .Render (& httpClient , address , format , check .Targets , from , until ); err == nil {
302+
303+ var filteringFunctions []* carbonapi_v3_pb.FilteringFunction
304+ if format == client .FormatPb_v3 {
305+ var err error
306+ filteringFunctions , err = parseFilteringFunctions (check .FilteringFunctions )
307+ if err != nil {
308+ errors = append (errors , err .Error ())
309+ continue
310+ }
311+ }
312+
313+ if url , result , respHeader , err := client .Render (& httpClient , address , format , check .Targets , filteringFunctions , check .MaxDataPoints , from , until ); err == nil {
284314 id := requestId (respHeader )
285315 name := ""
286316 if check .ErrorRegexp != "" {
@@ -303,7 +333,7 @@ func verifyRender(ch *Clickhouse, gch *GraphiteClickhouse, check *RenderCheck, d
303333 if check .CacheTTL > 0 && check .ErrorRegexp == "" {
304334 // second query must be find-cached
305335 name = "cache"
306- if url , result , respHeader , err = client .Render (& httpClient , address , format , check .Targets , from , until ); err == nil {
336+ if url , result , respHeader , err = client .Render (& httpClient , address , format , check .Targets , filteringFunctions , check . MaxDataPoints , from , until ); err == nil {
307337 compareRender (& errors , name , url , result , check .result , true , respHeader , check .CacheTTL )
308338 } else {
309339 errStr := strings .TrimRight (err .Error (), "\n " )
0 commit comments