traces: fix memory leak for long running traces that aren't being collected

Change-Id: I7576e5f420e83c52c5bdb65a30f68aa8ee3d3cc8
This commit is contained in:
JT Olio 2020-02-13 03:16:31 -07:00
parent 05a240050e
commit 900cc47772
3 changed files with 15 additions and 17 deletions

2
go.mod
View File

@ -51,7 +51,7 @@ require (
github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/jtolds/go-luar v0.0.0-20170419063437-0786921db8c0 github.com/jtolds/go-luar v0.0.0-20170419063437-0786921db8c0
github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3 github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3
github.com/jtolds/tracetagger/v2 v2.0.0-rc0 github.com/jtolds/tracetagger/v2 v2.0.0-rc2
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e // indirect github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e // indirect
github.com/klauspost/reedsolomon v0.0.0-20180704173009-925cb01d6510 // indirect github.com/klauspost/reedsolomon v0.0.0-20180704173009-925cb01d6510 // indirect
github.com/lib/pq v1.3.0 github.com/lib/pq v1.3.0

8
go.sum
View File

@ -232,8 +232,8 @@ github.com/jtolds/go-luar v0.0.0-20170419063437-0786921db8c0 h1:UyVaeqfY1fLPMt1i
github.com/jtolds/go-luar v0.0.0-20170419063437-0786921db8c0/go.mod h1:OtVLEpPHGJkn8jgGrHlYELCA3uXLU0YSfNN0faeDM2M= github.com/jtolds/go-luar v0.0.0-20170419063437-0786921db8c0/go.mod h1:OtVLEpPHGJkn8jgGrHlYELCA3uXLU0YSfNN0faeDM2M=
github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3 h1:dITCBge70U9RDyZUL/Thn/yAT/ct4Rz40mNUX51dFCk= github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3 h1:dITCBge70U9RDyZUL/Thn/yAT/ct4Rz40mNUX51dFCk=
github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3/go.mod h1:eo5po8nCwRcvZIIR8eGi7PKthzXuunpXzUmXzxCBfBc= github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3/go.mod h1:eo5po8nCwRcvZIIR8eGi7PKthzXuunpXzUmXzxCBfBc=
github.com/jtolds/tracetagger/v2 v2.0.0-rc0 h1:ND7ncC1SZyJ97ALL2QsKN5whzvRGOeXv0cu8PaCYttA= github.com/jtolds/tracetagger/v2 v2.0.0-rc2 h1:pxmt5o+WRYffMwMYuFlI3wKwYbPVAyiX8EEyM8a/U7o=
github.com/jtolds/tracetagger/v2 v2.0.0-rc0/go.mod h1:EeqZ0b80feEwRK+FutrQ/GJxruNqamJBKOezZVfzSxA= github.com/jtolds/tracetagger/v2 v2.0.0-rc2/go.mod h1:EeqZ0b80feEwRK+FutrQ/GJxruNqamJBKOezZVfzSxA=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
@ -609,9 +609,5 @@ storj.io/common v0.0.0-20200210174421-a3a30fc4862d/go.mod h1:n4sxosrQlw5iDBlbTdB
storj.io/drpc v0.0.7-0.20191115031725-2171c57838d2/go.mod h1:/ascUDbzNAv0A3Jj7wUIKFBH2JdJ2uJIBO/b9+2yHgQ= storj.io/drpc v0.0.7-0.20191115031725-2171c57838d2/go.mod h1:/ascUDbzNAv0A3Jj7wUIKFBH2JdJ2uJIBO/b9+2yHgQ=
storj.io/drpc v0.0.8 h1:wu68cMmtoT0vSWIAZz29RpJkWdi4o0S8BIrLslpH5FQ= storj.io/drpc v0.0.8 h1:wu68cMmtoT0vSWIAZz29RpJkWdi4o0S8BIrLslpH5FQ=
storj.io/drpc v0.0.8/go.mod h1:v39uWro/EbXXk+gNnrM9FQuVVS2zUBWBfeduydgeXUA= storj.io/drpc v0.0.8/go.mod h1:v39uWro/EbXXk+gNnrM9FQuVVS2zUBWBfeduydgeXUA=
storj.io/uplink v0.0.0-20200131143957-f3b6350b4add h1:/G2nFSq00KxD/9tQIpNJA2vRGkaSHdZvi1ZsX4qAgbQ=
storj.io/uplink v0.0.0-20200131143957-f3b6350b4add/go.mod h1:sqhw1H30vF8pD6coKYkx0nLAkw9M0ISwjLi+3R5b3A8=
storj.io/uplink v0.0.0-20200210111421-04761b3aaccd h1:jjOXtv0L9sd/i5UW0qsaMjFDA857z0BTBIsTIhImumk=
storj.io/uplink v0.0.0-20200210111421-04761b3aaccd/go.mod h1:sqhw1H30vF8pD6coKYkx0nLAkw9M0ISwjLi+3R5b3A8=
storj.io/uplink v0.0.0-20200211130624-1f304dca3b7d h1:Co/Sa2VflIZ4tHk+eLj8vSES/ciksSHILX9+fuTGtAQ= storj.io/uplink v0.0.0-20200211130624-1f304dca3b7d h1:Co/Sa2VflIZ4tHk+eLj8vSES/ciksSHILX9+fuTGtAQ=
storj.io/uplink v0.0.0-20200211130624-1f304dca3b7d/go.mod h1:sqhw1H30vF8pD6coKYkx0nLAkw9M0ISwjLi+3R5b3A8= storj.io/uplink v0.0.0-20200211130624-1f304dca3b7d/go.mod h1:sqhw1H30vF8pD6coKYkx0nLAkw9M0ISwjLi+3R5b3A8=

View File

@ -10,24 +10,22 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/jtolds/tracetagger/v2" tracetagger "github.com/jtolds/tracetagger/v2"
"github.com/spacemonkeygo/monkit/v3" monkit "github.com/spacemonkeygo/monkit/v3"
"github.com/spacemonkeygo/monkit/v3/collect" "github.com/spacemonkeygo/monkit/v3/collect"
) )
// TraceTag is a type to keep track of different types of tags for traces var (
type TraceTag int
const (
// TagDB tags a trace as hitting the database // TagDB tags a trace as hitting the database
TagDB TraceTag = 1 TagDB = tracetagger.NewTagRef()
) )
// CollectTraces starts storing all known tagged traces on disk, until cancel // CollectTraces starts storing all known tagged traces on disk, until cancel
// is called // is called
func CollectTraces() (cancel func()) { func CollectTraces() (cancel func()) {
path := filepath.Join(os.TempDir(), "storj-traces", fmt.Sprint(os.Getpid())) path := filepath.Join(os.TempDir(), "storj-traces", fmt.Sprint(os.Getpid()))
return tracetagger.TracesWithTag(TagDB, 10000, func(spans []*collect.FinishedSpan, capped bool) { disable := TagDB.Enable()
cancelCollect := tracetagger.TracesWithTag(TagDB, 10000, func(spans []*collect.FinishedSpan, capped bool) {
name := tracetagger.TracePathPrefix(spans, capped) name := tracetagger.TracePathPrefix(spans, capped)
err := tracetagger.SaveTrace(spans, capped, filepath.Join(path, "unfiltered", name)) err := tracetagger.SaveTrace(spans, capped, filepath.Join(path, "unfiltered", name))
if err != nil { if err != nil {
@ -39,14 +37,18 @@ func CollectTraces() (cancel func()) {
log.Print(err) log.Print(err)
} }
}) })
return func() {
cancelCollect()
disable()
}
} }
// Tag tags a trace with the given tag // Tag tags a trace with the given tag
func Tag(ctx context.Context, tag TraceTag) { func Tag(ctx context.Context, tag *tracetagger.TagRef) {
tracetagger.Tag(ctx, tag) tracetagger.Tag(ctx, tag)
} }
// TagScope tags all functions on an entire monkit Scope with a given tag // TagScope tags all functions on an entire monkit Scope with a given tag
func TagScope(tag TraceTag, scope *monkit.Scope) { func TagScope(tag *tracetagger.TagRef, scope *monkit.Scope) {
tracetagger.TagScope(tag, scope) tracetagger.TagScope(tag, scope)
} }