go-graphite / carbonapi

Implementation of graphite API (graphite-web) in golang
Other
308 stars 140 forks source link

[BUG] index out of range for groupByNode queries with negative node number #623

Closed loitho closed 3 years ago

loitho commented 3 years ago

Hi, there : Describe the bug When running a groupByNode query with a negative node, an error appear.

CarbonAPI Version v0.15.3

Logs Query : groupByNode(collectd.<server>.load.load.*, -1, 'sum')

Log :

2021-06-22T15:30:54.999Z        ERROR   access  request failed  {"data": {"handler":"render","carbonapi_uuid":"ebcd50e8-c68e-43d2-bfa9-536b9b1d7565","url":"/render","peer_ip":"peer","host":"host:8080","format":"json","use_cache":true,"targets":["groupByNode(collectd.<server>.load.load.*, -1, 'sum')"],"cache_timeout":10,"runtime":0.077667685,"http_code":500,"reason":"runtime error: index out of range [-1]\nStack trace: github.com/go-graphite/carbonapi/cmd/carbonapi/http.renderHandler.func2\n\t/go/src/github.com/go-graphite/carbonapi/cmd/carbonapi/http/render_handler.go:239\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:971\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:88\ngithub.com/go-graphite/carbonapi/expr/functions/groupByNode.(*groupByNode).Do\n\t/go/src/github.com/go-graphite/carbonapi/expr/functions/groupByNode/function.go:77\ngithub.com/go-graphite/carbonapi/expr.EvalExpr\n\t/go/src/github.com/go-graphite/carbonapi/expr/expr.go:160\ngithub.com/go-graphite/carbonapi/expr.evaluator.Eval\n\t/go/src/github.com/go-graphite/carbonapi/expr/expr.go:119\ngithub.com/go-graphite/carbonapi/expr.evaluator.FetchAndEvalExp\n\t/go/src/github.com/go-graphite/carbonapi/expr/expr.go:96\ngithub.com/go-graphite/carbonapi/expr.FetchAndEvalExp\n\t/go/src/github.com/go-graphite/carbonapi/expr/expr.go:131\ngithub.com/go-graphite/carbonapi/cmd/carbonapi/http.renderHandler\n\t/go/src/github.com/go-graphite/carbonapi/cmd/carbonapi/http/render_handler.go:268\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2069\ngithub.com/go-graphite/carbonapi/util/ctx.ParseCtx.func1\n\t/go/src/github.com/go-graphite/carbonapi/util/ctx/ctx.go:90\ngithub.com/go-graphite/carbonapi/cmd/carbonapi/http.enrichContextWithHeaders.func1\n\t/go/src/github.com/go-graphite/carbonapi/cmd/carbonapi/http/enrichcontext.go:32\ngithub.com/dgryski/httputil.TimeHandler.func1\n\t/go/src/github.com/go-graphite/carbonapi/vendor/github.com/dgryski/httputil/times.go:26\ngithub.com/dgryski/httputil.TrackConnections.func1\n\t/go/src/github.com/go-graphite/carbonapi/vendor/github.com/dgryski/httputil/track.go:40\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2069\nnet/http.(*ServeMux).ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2448\ngithub.com/gorilla/handlers.CompressHandlerLevel.func1\n\t/go/src/github.com/go-graphite/carbonapi/vendor/github.com/gorilla/handlers/compress.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2069\ngithub.com/gorilla/handlers.(*cors).ServeHTTP\n\t/go/src/github.com/go-graphite/carbonapi/vendor/github.com/gorilla/handlers/cors.go:54\ngithub.com/gorilla/handlers.ProxyHeaders.func1\n\t/go/src/github.com/go-graphite/carbonapi/vendor/github.com/gorilla/handlers/proxy_headers.go:59\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2069\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2887\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1952","from":1624372254,"until":1624375854,"from_raw":"-1h","until_raw":"now","uri":"/render","from_cache":false,"used_backend_cache":false,"request_headers":{"X-Grafana-Org-Id":"1","X-Panel-Id":"Q-75f3f5b5-2b57-4d60-800c-c0deb5c59d7b-0"}}}

CarbonAPI Configuration: I don't think there is any specific in my config as this is an issue with the function. But here is it :

isten: "0.0.0.0:8080"

notFoundStatusCode: 200

cache:
   type: "mem"
   size_mb: 0
   defaultTimeoutSec: 10

backendCache:
   type: "mem"
   size_mb: 0
   defaultTimeoutSec: 10

headersToPass:
    - "X-Dashboard-Id"
    - "X-Grafana-Org-Id"
    - "X-Panel-Id"

headersToLog:
    - "X-Dashboard-Id"
    - "X-Grafana-Org-Id"
    - "X-Panel-Id"

graphite:
    ## TCP
    host: "p-metro-graph.cplus:2004"
    interval: "60s"
    prefix: "carbon.api"
    pattern: "{prefix}.{fqdn}"

upstreams:
    graphite09compat: false
    buckets: 10

    concurrencyLimitPerServer: 0
    keepAliveInterval: "30s"
    maxIdleConnsPerHost: 100

    backendsv2:
        backends:
          -
            groupName: "go-carbon-prod"
            protocol: "carbonapi_v3_pb"
            lbMethod: "broadcast"
            maxTries: 2
#            maxBatchSize: 1000
            keepAliveInterval: "10s"
            concurrencyLimit: 0
            maxIdleConnsPerHost: 1000
            timeouts:
                find: "2s"
                render: "50s"
                connect: "200ms"
            servers:
                - "http://01:8080"
                - "http://02:8080"

Simplified query (if applicable) Please provide a query that triggered the issue, ideally narrowed down to smallest possible set of functions. groupByNode(collectd.<server>.load.load.*, -1, 'sum')

Is this an expected behavior ? This works on Graphite Web but not on CarbonAPI sadly Thank you for your help !

Felixoid commented 3 years ago

It looks to me like a lack of compatibility with graphite-web.

If you'd provide the list of functions that should have the node number with negative indexing, I can try to implement it

loitho commented 3 years ago

Hi,

Thank you for your reply, I see the issue happening for :

groupByNodes groupByNode

That's the only "node" function with the issue.

Kind regards,