@@ -11,6 +11,7 @@ import (
11
11
"strings"
12
12
"time"
13
13
14
+ "github.com/go-graphite/protocol/carbonapi_v3_pb"
14
15
"github.com/lomik/graphite-clickhouse/helper/client"
15
16
"github.com/lomik/graphite-clickhouse/helper/datetime"
16
17
"github.com/lomik/graphite-clickhouse/helper/tests/compare"
@@ -271,6 +272,24 @@ func compareRender(errors *[]string, name, url string, actual, expected []client
271
272
}
272
273
}
273
274
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
+
274
293
func verifyRender (ch * Clickhouse , gch * GraphiteClickhouse , check * RenderCheck , defaultPreision time.Duration ) []string {
275
294
var errors []string
276
295
httpClient := http.Client {
@@ -280,7 +299,18 @@ func verifyRender(ch *Clickhouse, gch *GraphiteClickhouse, check *RenderCheck, d
280
299
from := datetime .TimestampTruncate (check .from , defaultPreision )
281
300
until := datetime .TimestampTruncate (check .until , defaultPreision )
282
301
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 {
284
314
id := requestId (respHeader )
285
315
name := ""
286
316
if check .ErrorRegexp != "" {
@@ -303,7 +333,7 @@ func verifyRender(ch *Clickhouse, gch *GraphiteClickhouse, check *RenderCheck, d
303
333
if check .CacheTTL > 0 && check .ErrorRegexp == "" {
304
334
// second query must be find-cached
305
335
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 {
307
337
compareRender (& errors , name , url , result , check .result , true , respHeader , check .CacheTTL )
308
338
} else {
309
339
errStr := strings .TrimRight (err .Error (), "\n " )
0 commit comments