Skip to content

Commit

Permalink
Remove the option to publish vars via expvars. (#76)
Browse files Browse the repository at this point in the history
Expvars exposes the program's command line arguments at /var/debug -
this cannot be disabled and is a security risk.  It also panics and logs
if a duplicate var name is passed in (because we use it incorrectly).
Additionally, it doesn't appear that anything still relies on the
memory or other stats published by expvars - so remove it.
  • Loading branch information
Charlie Vieth authored May 24, 2019
1 parent b51f9d2 commit 03ea723
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions stats.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package stats

import (
"expvar"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -178,11 +177,9 @@ type StatGenerator interface {
}

// NewStore returns an Empty store that flushes to Sink passed as an argument.
func NewStore(sink Sink, export bool) Store {
return &statStore{
sink: sink,
export: export,
}
// Note: the export argument is unused.
func NewStore(sink Sink, _ bool) Store {
return &statStore{sink: sink}
}

// NewDefaultStore returns a Store with a TCP statsd sink, and a running flush timer.
Expand All @@ -194,7 +191,7 @@ func NewDefaultStore() Store {
newStore = NewStore(NewLoggingSink(), false)
go newStore.Start(time.NewTicker(10 * time.Second))
} else {
newStore = NewStore(NewTCPStatsdSink(), true)
newStore = NewStore(NewTCPStatsdSink(), false)
go newStore.Start(time.NewTicker(time.Duration(settings.FlushIntervalS) * time.Second))
}
return newStore
Expand Down Expand Up @@ -303,8 +300,7 @@ type statStore struct {
genMtx sync.RWMutex
statGenerators []StatGenerator

sink Sink
export bool
sink Sink
}

func (s *statStore) Flush() {
Expand Down Expand Up @@ -373,8 +369,6 @@ func (s *statStore) NewCounterWithTags(name string, tags map[string]string) Coun
c := new(counter)
if v, loaded := s.counters.LoadOrStore(name, c); loaded {
c = v.(*counter)
} else if s.export {
publishExpVar(name, c)
}
return c
}
Expand Down Expand Up @@ -405,8 +399,6 @@ func (s *statStore) NewGaugeWithTags(name string, tags map[string]string) Gauge
g := new(gauge)
if v, loaded := s.gauges.LoadOrStore(name, g); loaded {
g = v.(*gauge)
} else if s.export {
publishExpVar(name, g)
}
return g
}
Expand Down Expand Up @@ -525,8 +517,3 @@ func (s subScope) mergeTags(tags map[string]string) map[string]string {
}
return tags
}

func publishExpVar(name string, v expvar.Var) {
defer func() { recover() }()
expvar.Publish(name, v)
}

0 comments on commit 03ea723

Please sign in to comment.