Skip to content

Commit

Permalink
remove test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
maciuszek committed Jan 20, 2025
1 parent c2738fa commit 13cbeb5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
4 changes: 0 additions & 4 deletions logging_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,3 @@ func (s *loggingSink) Errorf(msg string, args ...interface{}) {
func (s *loggingSink) Warnf(msg string, args ...interface{}) {
s.logMessage("warn", fmt.Sprintf(msg, args...))
}

func (s *loggingSink) Infof(msg string, args ...interface{}) {
s.logMessage("info", fmt.Sprintf(msg, args...))
}
4 changes: 2 additions & 2 deletions net_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
type Logger interface {
Errorf(msg string, args ...interface{})
Warnf(msg string, args ...interface{})
Infof(msg string, args ...interface{})
}

const (
Expand Down Expand Up @@ -94,6 +93,7 @@ func NewTCPStatsdSink(opts ...SinkOption) FlushableSink {
// network. By default settings are taken from the environment, but can be
// overridden via SinkOptions.
func NewNetSink(opts ...SinkOption) FlushableSink {
settings := GetSettings()
s := &netSink{
// arbitrarily buffered
doFlush: make(chan chan struct{}, 8),
Expand All @@ -103,7 +103,7 @@ func NewNetSink(opts ...SinkOption) FlushableSink {
log: &loggingSink{writer: os.Stderr, now: time.Now},

// TODO (CEV): auto loading from the env is bad and should be removed.
conf: GetSettings(),
conf: settings,
}
for _, opt := range opts {
opt.apply(s)
Expand Down
27 changes: 1 addition & 26 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package stats

import (
"context"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -219,7 +217,6 @@ func NewStore(sink Sink, _ bool) Store {
return &statStore{
sink: sink,
timerType: standard,
log: &loggingSink{writer: os.Stderr, now: time.Now}, // should always be initialized since this is not exported todo: not sure if we really need this
}
}

Expand Down Expand Up @@ -332,7 +329,6 @@ type standardTimer struct {
base time.Duration
name string
sink Sink
log Logger
}

func (t *standardTimer) time(dur time.Duration) {
Expand All @@ -345,7 +341,6 @@ func (t *standardTimer) AddDuration(dur time.Duration) {

func (t *standardTimer) AddValue(value float64) {
t.sink.FlushTimer(t.name, value)
t.log.Infof("Flushed standard timer: %s", t.name) // todo: either remove or convert to debug logging
}

func (t *standardTimer) AllocateSpan() Timespan {
Expand Down Expand Up @@ -437,7 +432,6 @@ type statStore struct {
statGenerators []StatGenerator

sink Sink
log Logger
}

var ReservedTagWords = map[string]bool{"asg": true, "az": true, "backend": true, "canary": true, "host": true, "period": true, "region": true, "shard": true, "window": true, "source": true, "project": true, "facet": true, "envoyservice": true}
Expand Down Expand Up @@ -487,10 +481,7 @@ func (s *statStore) Flush() {
return true
})

flushedReservoirTimers := make([]string, 0)
skippedTimers := make([]string, 0)
s.timers.Range(func(key, v interface{}) bool {
name := key.(string)
if timer, ok := v.(*reservoirTimer); ok {

values, count := timer.Empty()
Expand All @@ -503,28 +494,13 @@ func (s *statStore) Flush() {
sampleRate = float64(reservoirSize) / float64(count)
}

var flushedSamples int64
for _, value := range values {
s.sink.FlushSampledTimer(name, value, sampleRate)
flushedSamples++
s.sink.FlushSampledTimer(key.(string), value, sampleRate)
}

var nameWithSampleCount strings.Builder
nameWithSampleCount.WriteString(name)
nameWithSampleCount.WriteString("|")
nameWithSampleCount.WriteString(strconv.FormatInt(flushedSamples, 10))
flushedReservoirTimers = append(flushedReservoirTimers, nameWithSampleCount.String())

} else {
skippedTimers = append(skippedTimers, name)
}

return true
})
s.log.Infof("Flushed reservoir timers: %s. Skipped timers: %s",
flushedReservoirTimers,
skippedTimers,
) // todo: remove this and related variable after testing to reduce performance hit

flushableSink, ok := s.sink.(FlushableSink)
if ok {
Expand Down Expand Up @@ -645,7 +621,6 @@ func (s *statStore) newTimer(serializedName string, base time.Duration) timer {
name: serializedName,
sink: s.sink,
base: base,
log: s.log,
}
}

Expand Down
6 changes: 3 additions & 3 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ func TestTagMapNotModified(t *testing.T) {
}

scopeGenerators := map[string]func() Scope{
"statStore": func() Scope { return &statStore{log: discardLogger()} },
"subScope": func() Scope { return newSubScope(&statStore{log: discardLogger()}, "name", nil) },
"statStore": func() Scope { return &statStore{} },
"subScope": func() Scope { return newSubScope(&statStore{}, "name", nil) },
}

methodTestCases := map[string]TagMethod{
Expand Down Expand Up @@ -764,7 +764,7 @@ func TestPerInstanceStats(t *testing.T) {
testPerInstanceMethods := func(t *testing.T, setupScope func(Scope) Scope) {
for _, x := range testCases {
sink := mock.NewSink()
scope := setupScope(&statStore{sink: sink, log: discardLogger()})
scope := setupScope(&statStore{sink: sink})

scope.NewPerInstanceCounter("name", x.tags).Inc()
scope.NewPerInstanceGauge("name", x.tags).Inc()
Expand Down

0 comments on commit 13cbeb5

Please sign in to comment.