Stats uses the same logger output as the cluster

This commit is contained in:
Michael Baird 2017-05-16 10:52:10 -05:00
parent 4a051900c0
commit b2343c5ce3
3 changed files with 29 additions and 7 deletions

View file

@ -40,10 +40,9 @@ var _ pilosa.StatsClient = &StatsClient{}
// StatsClient represents a DataDog implementation of pilosa.StatsClient.
type StatsClient struct {
client *statsd.Client
tags []string
LogOutput io.Writer
client *statsd.Client
tags []string
logOutput io.Writer
}
// NewStatsClient returns a new instance of StatsClient.
@ -56,7 +55,7 @@ func NewStatsClient(host string) (*StatsClient, error) {
return &StatsClient{
client: c,
LogOutput: ioutil.Discard,
logOutput: ioutil.Discard,
}, nil
}
@ -75,7 +74,7 @@ func (c *StatsClient) WithTags(tags ...string) pilosa.StatsClient {
return &StatsClient{
client: c.client,
tags: pilosa.UnionStringSlice(c.tags, tags),
LogOutput: c.LogOutput,
logOutput: c.logOutput,
}
}
@ -122,7 +121,12 @@ func (c *StatsClient) Timing(name string, value time.Duration, rate float64) {
}
}
// SetLogger has no logger
func (c *StatsClient) SetLogger(logger io.Writer) {
c.logOutput = logger
}
// logger returns a logger that writes to LogOutput
func (c *StatsClient) logger() *log.Logger {
return log.New(c.LogOutput, "", log.LstdFlags)
return log.New(c.logOutput, "", log.LstdFlags)
}

View file

@ -141,6 +141,8 @@ func (m *Command) SetupServer() error {
return err
}
m.Server.Holder.Stats.SetLogger(m.Server.LogOutput)
// Copy configuration flags.
m.Server.MaxWritesPerRequest = m.Config.MaxWritesPerRequest

View file

@ -16,6 +16,7 @@ package pilosa
import (
"expvar"
"io"
"sort"
"strings"
"sync"
@ -54,6 +55,9 @@ type StatsClient interface {
// Tracks timing information for a metric.
Timing(name string, value time.Duration, rate float64)
// SetLogger Set the logger output type
SetLogger(logger io.Writer)
}
// NopStatsClient represents a client that doesn't do anything.
@ -69,6 +73,7 @@ func (c *nopStatsClient) Gauge(name string, value float64, rate float64)
func (c *nopStatsClient) Histogram(name string, value float64, rate float64) {}
func (c *nopStatsClient) Set(name string, value string, rate float64) {}
func (c *nopStatsClient) Timing(name string, value time.Duration, rate float64) {}
func (c *nopStatsClient) SetLogger(logger io.Writer) {}
// ExpvarStatsClient writes stats out to expvars.
type ExpvarStatsClient struct {
@ -138,6 +143,10 @@ func (c *ExpvarStatsClient) Timing(name string, value time.Duration, rate float6
c.mu.Unlock()
}
// SetLogger has no logger
func (c *ExpvarStatsClient) SetLogger(logger io.Writer) {
}
// MultiStatsClient joins multiple stats clients together.
type MultiStatsClient []StatsClient
@ -200,6 +209,13 @@ func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64)
}
}
// SetLogger Sets the StatsD logger output type
func (a MultiStatsClient) SetLogger(logger io.Writer) {
for _, c := range a {
c.SetLogger(logger)
}
}
// UnionStringSlice returns a sorted set of tags which combine a & b.
func UnionStringSlice(a, b []string) []string {
// Sort both sets first.