Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

curl http://127.0.0.1:8181/v1/metrics/ panics (only with trailing /) #534

Closed
tiffanyfay opened this issue Nov 23, 2015 · 0 comments
Closed

Comments

@tiffanyfay
Copy link
Contributor

/tasks/ and /plugins/ redirect to /tasks and /plugins, but curl http://127.0.0.1:8181/v1/metrics/ panics with:

PANIC: runtime error: index out of range
goroutine 87 [running]:
github.com/codegangsta/negroni.(*Recovery).ServeHTTP.func1(0xf09d80, 0xc820145e40, 0xc820f86780)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/recovery.go:34 +0xe9
github.com/intelsdi-x/pulse/mgmt/rest.parseNamespace(0xc82011846f, 0x1, 0x0, 0x0, 0x0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/intelsdi-x/pulse/mgmt/rest/server.go:272 +0x113
github.com/intelsdi-x/pulse/mgmt/rest.(*Server).getMetricsFromTree(0xc820124a80, 0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc820118580, 0x1, 0x1)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/intelsdi-x/pulse/mgmt/rest/metric.go:44 +0x8a
github.com/intelsdi-x/pulse/mgmt/rest.(*Server).(github.com/intelsdi-x/pulse/mgmt/rest.getMetricsFromTree)-fm(0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc820118580, 0x1, 0x1)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/intelsdi-x/pulse/mgmt/rest/server.go:210 +0x5c
github.com/julienschmidt/httprouter.(*Router).ServeHTTP(0xc820113bc0, 0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/julienschmidt/httprouter/router.go:299 +0x193
github.com/codegangsta/negroni.Wrap.func1(0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc820118560)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:41 +0x50
github.com/codegangsta/negroni.HandlerFunc.ServeHTTP(0xc820f86820, 0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc820118560)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:24 +0x44
github.com/codegangsta/negroni.middleware.ServeHTTP(0xf09a48, 0xc820f86820, 0xc820f868a0, 0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:33 +0xaa
github.com/codegangsta/negroni.(middleware).ServeHTTP-fm(0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:33 +0x53
github.com/codegangsta/negroni.(*Recovery).ServeHTTP(0xc820f86780, 0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc820118520)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/recovery.go:45 +0x75
github.com/codegangsta/negroni.middleware.ServeHTTP(0xf09a20, 0xc820f86780, 0xc820f86860, 0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:33 +0xaa
github.com/codegangsta/negroni.(middleware).ServeHTTP-fm(0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:33 +0x53
github.com/intelsdi-x/pulse/mgmt/rest.(*Logger).ServeHTTP(0xc820114120, 0xf09d80, 0xc820145e40, 0xc8200b21c0, 0xc8201184c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/intelsdi-x/pulse/mgmt/rest/log_handler.go:46 +0x387
github.com/codegangsta/negroni.middleware.ServeHTTP(0xf099f8, 0xc820114120, 0xc820f86840, 0xf09d80, 0xc820145e40, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:33 +0xaa
github.com/codegangsta/negroni.(*Negroni).ServeHTTP(0xc820113b30, 0xf09ce8, 0xc8200984d0, 0xc8200b21c0)
    /Users/tjerniga/.gvm/pkgsets/system/global/src/github.com/codegangsta/negroni/negroni.go:73 +0x122
net/http.serverHandler.ServeHTTP(0xc820124b40, 0xf09ce8, 0xc8200984d0, 0xc8200b21c0)
    /Users/tjerniga/.gvm/gos/go1.5/src/net/http/server.go:1862 +0x19e
net/http.(*conn).serve(0xc820099130)
    /Users/tjerniga/.gvm/gos/go1.5/src/net/http/server.go:1361 +0xbee
created by net/http.(*Server).Serve
    /Users/tjerniga/.gvm/gos/go1.5/src/net/http/server.go:1910 +0x3f6

In server.go it makes ns len 0 and then tries accessing ns[0]

func parseNamespace(ns string) []string {
    if strings.Index(ns, "/") == 0 {
        ns = ns[1:]
    }
    ns[len(ns)-1] == '/' {
        ns = ns[:len(ns)-1]
    }
    return strings.Split(ns, "/")
}

Should be

if len(ns) > 0 && ns[len(ns)-1] == '/' 

instead

Not sure what about : instead of * makes the GET redirect (though it would break the rest of namespace)
e.g.

curl http://127.0.0.1:8181/v1/plugins/
<a href="/v1/plugins">Moved Permanently</a>.

Going to http://127.0.0.1:8181/v1/metrics/ seems fine and redirects to /metrics, but http://localhost:8181/v1/metrics/ mimics the curl with a panic.

@lynxbat lynxbat added the tracked label Dec 2, 2015
@pittma pittma closed this as completed in 7207c44 Dec 4, 2015
pittma added a commit that referenced this issue Dec 4, 2015
fix #534: panic on metric tree lookup with trailing slash
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants