move Logger and Stats to their own packages

I'd like to add stat tracking to Roaring, which means it
has to be able to import the stats package, which means
stats has to be a package rather than part of the pilosa
package. If stats stops being in pilosa, it still needs
a way to import logger, so logger also has to leave the
pilosa package. Then everything using them needs to import
them and use package selectors on their names.

This doesn't actually add the stats support to roaring,
it just makes it so there's a way to import the stats
code from something in the roaring package.
This commit is contained in:
Seebs 2018-11-14 22:44:27 -06:00
parent 70f85211d9
commit a203313143
18 changed files with 121 additions and 95 deletions

3
api.go
View file

@ -28,6 +28,7 @@ import (
"github.com/pilosa/pilosa/pql"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
@ -930,7 +931,7 @@ func (api *API) AvailableShardsByIndex(_ context.Context) map[string]*roaring.Bi
// StatsWithTags returns an instance of whatever implementation of StatsClient
// pilosa is using with the given tags.
func (api *API) StatsWithTags(tags []string) StatsClient {
func (api *API) StatsWithTags(tags []string) stats.StatsClient {
if api.holder == nil || api.cluster == nil {
return nil
}

View file

@ -23,6 +23,7 @@ import (
"time"
"github.com/pilosa/pilosa/lru"
"github.com/pilosa/pilosa/stats"
)
const (
@ -50,14 +51,14 @@ type cache interface {
Top() []bitmapPair
// SetStats defines the stats client used in the cache.
SetStats(s StatsClient)
SetStats(s stats.StatsClient)
}
// lruCache represents a least recently used Cache implementation.
type lruCache struct {
cache *lru.Cache
counts map[uint64]uint64
stats StatsClient
stats stats.StatsClient
}
// newLRUCache returns a new instance of LRUCache.
@ -65,7 +66,7 @@ func newLRUCache(maxEntries uint32) *lruCache {
c := &lruCache{
cache: lru.New(int(maxEntries)),
counts: make(map[uint64]uint64),
stats: NopStatsClient,
stats: stats.NopStatsClient,
}
c.cache.OnEvicted = c.onEvicted
return c
@ -122,7 +123,7 @@ func (c *lruCache) Top() []bitmapPair {
}
// SetStats defines the stats client used in the cache.
func (c *lruCache) SetStats(s StatsClient) {
func (c *lruCache) SetStats(s stats.StatsClient) {
c.stats = s
}
@ -150,7 +151,7 @@ type rankCache struct {
// thresholdValue is the value of the last item in the cache
thresholdValue uint64
stats StatsClient
stats stats.StatsClient
}
// NewRankCache returns a new instance of RankCache.
@ -159,7 +160,7 @@ func NewRankCache(maxEntries uint32) *rankCache {
maxEntries: maxEntries,
thresholdBuffer: int(thresholdFactor * float64(maxEntries)),
entries: make(map[uint64]uint64),
stats: NopStatsClient,
stats: stats.NopStatsClient,
}
}
@ -279,7 +280,7 @@ func (c *rankCache) recalculate() {
}
// SetStats defines the stats client used in the cache.
func (c *rankCache) SetStats(s StatsClient) {
func (c *rankCache) SetStats(s stats.StatsClient) {
c.stats = s
}
@ -458,12 +459,12 @@ func (s *simpleCache) Add(id uint64, b *Row) {
// nopCache represents a no-op Cache implementation.
type nopCache struct {
stats StatsClient
stats stats.StatsClient
}
// Ensure NopCache implements Cache.
var globalNopCache cache = nopCache{
stats: NopStatsClient,
stats: stats.NopStatsClient,
}
func (c nopCache) Add(uint64, uint64) {}
@ -471,10 +472,10 @@ func (c nopCache) BulkAdd(uint64, uint64) {}
func (c nopCache) Get(uint64) uint64 { return 0 }
func (c nopCache) IDs() []uint64 { return []uint64{} }
func (c nopCache) Invalidate() {}
func (c nopCache) Len() int { return 0 }
func (c nopCache) Recalculate() {}
func (c nopCache) SetStats(StatsClient) {}
func (c nopCache) Invalidate() {}
func (c nopCache) Len() int { return 0 }
func (c nopCache) Recalculate() {}
func (c nopCache) SetStats(stats.StatsClient) {}
func (c nopCache) Top() []bitmapPair {
return []bitmapPair{}

View file

@ -31,6 +31,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/roaring"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@ -216,7 +217,7 @@ type cluster struct { // nolint: maligned
wg sync.WaitGroup
closing chan struct{}
logger Logger
logger logger.Logger
InternalClient InternalClient
}
@ -235,7 +236,7 @@ func newCluster() *cluster {
InternalClient: newNopInternalClient(),
logger: NopLogger,
logger: logger.NopLogger,
}
}
@ -1379,7 +1380,7 @@ type resizeJob struct {
mu sync.RWMutex
state string
Logger Logger
Logger logger.Logger
}
// newResizeJob returns a new instance of resizeJob.
@ -1411,7 +1412,7 @@ func newResizeJob(existingNodes []*Node, node *Node, action string) *resizeJob {
IDs: ids,
action: action,
result: make(chan string),
Logger: NopLogger,
Logger: logger.NopLogger,
}
}

View file

@ -24,6 +24,7 @@ import (
"sync"
"time"
"github.com/pilosa/pilosa/logger"
"github.com/pkg/errors"
)
@ -51,7 +52,7 @@ type diagnosticsCollector struct {
client *http.Client
Logger Logger
Logger logger.Logger
server *Server
}
@ -65,7 +66,7 @@ func newDiagnosticsCollector(host string) *diagnosticsCollector { // nolint: unp
start: time.Now(),
client: &http.Client{Timeout: 10 * time.Second},
metrics: make(map[string]interface{}),
Logger: NopLogger,
Logger: logger.NopLogger,
}
}

View file

@ -28,8 +28,10 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/pql"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
)
@ -69,7 +71,7 @@ type Field struct {
rowAttrStore AttrStore
broadcaster broadcaster
Stats StatsClient
Stats stats.StatsClient
// Field options.
options FieldOptions
@ -79,7 +81,7 @@ type Field struct {
// Shards with data on any node in the cluster, according to this node.
remoteAvailableShards *roaring.Bitmap
logger Logger
logger logger.Logger
}
// FieldOption is a functional option type for pilosa.fieldOptions.
@ -196,13 +198,13 @@ func newField(path, index, name string, opts FieldOption) (*Field, error) {
rowAttrStore: nopStore,
broadcaster: NopBroadcaster,
Stats: NopStatsClient,
Stats: stats.NopStatsClient,
options: applyDefaultOptions(fo),
remoteAvailableShards: roaring.NewBitmap(),
logger: NopLogger,
logger: logger.NopLogger,
}
return f, nil
}

View file

@ -36,8 +36,10 @@ import (
"github.com/cespare/xxhash"
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/pql"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
)
@ -116,7 +118,7 @@ type fragment struct {
MaxOpN int
// Logger used for out-of-band log entries.
Logger Logger
Logger logger.Logger
// Row attribute storage.
// This is set by the parent field unless overridden for testing.
@ -126,7 +128,7 @@ type fragment struct {
// existing value (to clear) prior to setting a new value.
mutexVector vector
stats StatsClient
stats stats.StatsClient
}
// newFragment returns a new instance of Fragment.
@ -140,10 +142,10 @@ func newFragment(path, index, field, view string, shard uint64) *fragment {
CacheType: DefaultCacheType,
CacheSize: DefaultCacheSize,
Logger: NopLogger,
Logger: logger.NopLogger,
MaxOpN: defaultFragmentMaxOpN,
stats: NopStatsClient,
stats: stats.NopStatsClient,
}
}
@ -1718,7 +1720,7 @@ func (f *fragment) Snapshot() error {
defer f.mu.Unlock()
return f.snapshot()
}
func track(start time.Time, message string, stats StatsClient, logger Logger) {
func track(start time.Time, message string, stats stats.StatsClient, logger logger.Logger) {
elapsed := time.Since(start)
logger.Printf("%s took %s", message, elapsed)
stats.Histogram("snapshot", elapsed.Seconds(), 1.0)

View file

@ -29,6 +29,7 @@ import (
"github.com/hashicorp/memberlist"
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/toml"
"github.com/pkg/errors"
@ -47,7 +48,7 @@ type memberSet struct {
papi *pilosa.API
config *config
Logger pilosa.Logger
Logger logger.Logger
logger *log.Logger
logOutput io.Writer
@ -170,7 +171,7 @@ func NewMemberSet(cfg Config, api *pilosa.API, options ...memberSetOption) (*mem
host := api.Node().URI.Host
g := &memberSet{
papi: api,
Logger: pilosa.NopLogger,
Logger: logger.NopLogger,
}
// options

View file

@ -27,7 +27,9 @@ import (
"syscall"
"time"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)
@ -66,7 +68,7 @@ type Holder struct {
closing chan struct{}
// Stats
Stats StatsClient
Stats stats.StatsClient
// Data directory path.
Path string
@ -74,7 +76,7 @@ type Holder struct {
// The interval at which the cached row ids are persisted to disk.
cacheFlushInterval time.Duration
Logger Logger
Logger logger.Logger
}
// NewHolder returns a new instance of Holder.
@ -89,13 +91,13 @@ func NewHolder() *Holder {
NewPrimaryTranslateStore: newNopTranslateStore,
broadcaster: NopBroadcaster,
Stats: NopStatsClient,
Stats: stats.NopStatsClient,
NewAttrStore: newNopAttrStore,
cacheFlushInterval: defaultCacheFlushInterval,
Logger: NopLogger,
Logger: logger.NopLogger,
}
}
@ -605,7 +607,7 @@ type holderSyncer struct {
Cluster *cluster
// Stats
Stats StatsClient
Stats stats.StatsClient
// Signals that the sync should stop.
Closing <-chan struct{}

View file

@ -36,6 +36,7 @@ import (
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/logger"
"github.com/pkg/errors"
)
@ -44,7 +45,7 @@ import (
type Handler struct {
Handler http.Handler
logger pilosa.Logger
logger logger.Logger
// Keeps the query argument validators for each handler
validators map[string]*queryValidationSpec
@ -95,7 +96,7 @@ func OptHandlerAPI(api *pilosa.API) handlerOption {
}
}
func OptHandlerLogger(logger pilosa.Logger) handlerOption {
func OptHandlerLogger(logger logger.Logger) handlerOption {
return func(h *Handler) error {
h.logger = logger
return nil
@ -121,7 +122,7 @@ func OptHandlerCloseTimeout(d time.Duration) handlerOption {
// NewHandler returns a new instance of Handler with a default logger.
func NewHandler(opts ...handlerOption) (*Handler, error) {
handler := &Handler{
logger: pilosa.NopLogger,
logger: logger.NopLogger,
closeTimeout: time.Second * 30,
}
handler.Handler = newRouter(handler)

View file

@ -25,7 +25,9 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
)
@ -49,9 +51,9 @@ type Index struct {
columnAttrs AttrStore
broadcaster broadcaster
Stats StatsClient
Stats stats.StatsClient
logger Logger
logger logger.Logger
}
// NewIndex returns a new instance of Index.
@ -70,8 +72,8 @@ func NewIndex(path, name string) (*Index, error) {
columnAttrs: nopStore,
broadcaster: NopBroadcaster,
Stats: NopStatsClient,
logger: NopLogger,
Stats: stats.NopStatsClient,
logger: logger.NopLogger,
trackExistence: true,
}, nil
}

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package pilosa
package logger
import (
"io"
@ -39,7 +39,7 @@ func (n *nopLogger) Printf(format string, v ...interface{}) {}
// Debugf is a no-op implementation of the Logger Debugf method.
func (n *nopLogger) Debugf(format string, v ...interface{}) {}
// standardLogger is a basic implementation of pilosa.Logger based on log.Logger.
// standardLogger is a basic implementation of Logger based on log.Logger.
type standardLogger struct {
logger *log.Logger
}
@ -60,7 +60,7 @@ func (s *standardLogger) Logger() *log.Logger {
return s.logger
}
// verboseLogger is an implementation of pilosa.Logger which includes debug messages.
// verboseLogger is an implementation of Logger which includes debug messages.
type verboseLogger struct {
logger *log.Logger
}

View file

@ -27,7 +27,9 @@ import (
"sync"
"time"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
@ -58,7 +60,7 @@ type Server struct { // nolint: maligned
// External
systemInfo SystemInfo
gcNotifier GCNotifier
logger Logger
logger logger.Logger
nodeID string
uri URI
@ -81,7 +83,7 @@ func (s *Server) Holder() *Holder {
// ServerOption is a functional option type for pilosa.Server
type ServerOption func(s *Server) error
func OptServerLogger(l Logger) ServerOption {
func OptServerLogger(l logger.Logger) ServerOption {
return func(s *Server) error {
s.logger = l
return nil
@ -176,7 +178,7 @@ func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) TranslateStore) Ser
}
}
func OptServerStatsClient(sc StatsClient) ServerOption {
func OptServerStatsClient(sc stats.StatsClient) ServerOption {
return func(s *Server) error {
s.holder.Stats = sc
return nil
@ -258,7 +260,7 @@ func NewServer(opts ...ServerOption) (*Server, error) {
metricInterval: 0,
diagnosticInterval: 0,
logger: NopLogger,
logger: logger.NopLogger,
}
s.executor = newExecutor(optExecutorInternalQueryClient(s.defaultClient))
s.cluster.InternalClient = s.defaultClient

View file

@ -41,12 +41,14 @@ import (
"github.com/pilosa/pilosa/gopsutil"
"github.com/pilosa/pilosa/gossip"
"github.com/pilosa/pilosa/http"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/stats"
"github.com/pilosa/pilosa/statsd"
"github.com/pkg/errors"
)
type loggerLogger interface {
pilosa.Logger
logger.Logger
Logger() *log.Logger
}
@ -185,9 +187,9 @@ func (m *Command) setupLogger() error {
}
if m.Config.Verbose {
m.logger = pilosa.NewVerboseLogger(m.logOutput)
m.logger = logger.NewVerboseLogger(m.logOutput)
} else {
m.logger = pilosa.NewStandardLogger(m.logOutput)
m.logger = logger.NewStandardLogger(m.logOutput)
}
return nil
}
@ -375,14 +377,14 @@ func (m *Command) Close() error {
}
// newStatsClient creates a stats client from the config
func newStatsClient(name string, host string) (pilosa.StatsClient, error) {
func newStatsClient(name string, host string) (stats.StatsClient, error) {
switch name {
case "expvar":
return pilosa.NewExpvarStatsClient(), nil
return stats.NewExpvarStatsClient(), nil
case "statsd":
return statsd.NewStatsClient(host)
case "nop", "none":
return pilosa.NopStatsClient, nil
return stats.NopStatsClient, nil
default:
return nil, errors.Errorf("'%v' not a valid stats client, choose from [expvar, statsd, none].", name)
}

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package pilosa
package stats
import (
"expvar"
@ -20,6 +20,8 @@ import (
"strings"
"sync"
"time"
"github.com/pilosa/pilosa/logger"
)
// Expvar global expvar map.
@ -52,7 +54,7 @@ type StatsClient interface {
Timing(name string, value time.Duration, rate float64)
// SetLogger Set the logger output type
SetLogger(logger Logger)
SetLogger(logger logger.Logger)
// Starts the service
Open()
@ -74,7 +76,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 Logger) {}
func (c *nopStatsClient) SetLogger(logger logger.Logger) {}
func (c *nopStatsClient) Open() {}
func (c *nopStatsClient) Close() error { return nil }
@ -149,7 +151,7 @@ func (c *expvarStatsClient) Timing(name string, value time.Duration, rate float6
}
// SetLogger has no logger.
func (c *expvarStatsClient) SetLogger(logger Logger) {
func (c *expvarStatsClient) SetLogger(logger logger.Logger) {
}
// Open no-op.
@ -221,7 +223,7 @@ func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64)
}
// SetLogger Sets the StatsD logger output type.
func (a MultiStatsClient) SetLogger(logger Logger) {
func (a MultiStatsClient) SetLogger(logger logger.Logger) {
for _, c := range a {
c.SetLogger(logger)
}

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package pilosa_test
package stats_test
import (
"context"
@ -23,6 +23,8 @@ import (
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/http"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/stats"
"github.com/pilosa/pilosa/test"
)
@ -32,51 +34,51 @@ func TestMultiStatClient_Expvar(t *testing.T) {
hldr := test.MustOpenHolder()
defer hldr.Close()
c := pilosa.NewExpvarStatsClient()
ms := make(pilosa.MultiStatsClient, 1)
c := stats.NewExpvarStatsClient()
ms := make(stats.MultiStatsClient, 1)
ms[0] = c
hldr.Stats = ms
hldr.SetBit("d", "f", 0, 0)
hldr.SetBit("d", "f", 0, 1)
hldr.SetBit("d", "f", 0, ShardWidth)
hldr.SetBit("d", "f", 0, ShardWidth+2)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth+2)
hldr.ClearBit("d", "f", 0, 1)
if pilosa.Expvar.String() != `{"index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
hldr.Stats.CountWithCustomTags("cc", 1, 1.0, []string{"foo:bar"})
if pilosa.Expvar.String() != `{"cc": 1, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"cc": 1, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
// Gauge creates a unique key, subsequent Gauge calls will overwrite
hldr.Stats.Gauge("g", 5, 1.0)
hldr.Stats.Gauge("g", 8, 1.0)
if pilosa.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
// Set creates a unique key, subsequent sets will overwrite
hldr.Stats.Set("s", "4", 1.0)
hldr.Stats.Set("s", "7", 1.0)
if pilosa.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7"}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7"}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
// Record timing duration and a uniquely Set key/value
dur, _ := time.ParseDuration("123us")
hldr.Stats.Timing("tt", dur, 1.0)
if pilosa.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7", "tt": 123µs}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"cc": 1, "g": 8, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7", "tt": 123µs}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
// Expvar histogram is implemented as a gauge
hldr.Stats.Histogram("hh", 3, 1.0)
if pilosa.Expvar.String() != `{"cc": 1, "g": 8, "hh": 3, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7", "tt": 123µs}` {
t.Fatalf("unexpected expvar : %s", pilosa.Expvar.String())
if stats.Expvar.String() != `{"cc": 1, "g": 8, "hh": 3, "index:d": {"field:f": {"view:standard": {"shard:0": {"clearBit": 1, "rows": 0, "setBit": 2}, "shard:1": {"rows": 0, "setBit": 2}}}}, "s": "7", "tt": 123µs}` {
t.Fatalf("unexpected expvar : %s", stats.Expvar.String())
}
// Expvar should ignore earlier set tags from setbit
@ -92,8 +94,8 @@ func TestStatsCount_TopN(t *testing.T) {
hldr.SetBit("d", "f", 0, 0)
hldr.SetBit("d", "f", 0, 1)
hldr.SetBit("d", "f", 0, ShardWidth)
hldr.SetBit("d", "f", 0, ShardWidth+2)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth+2)
// Execute query.
called := false
@ -311,11 +313,11 @@ func (s *MockStats) CountWithCustomTags(name string, value int64, rate float64,
}
func (c *MockStats) Tags() []string { return nil }
func (c *MockStats) WithTags(tags ...string) pilosa.StatsClient { return c }
func (c *MockStats) WithTags(tags ...string) stats.StatsClient { return c }
func (c *MockStats) Gauge(name string, value float64, rate float64) {}
func (c *MockStats) Histogram(name string, value float64, rate float64) {}
func (c *MockStats) Set(name string, value string, rate float64) {}
func (c *MockStats) Timing(name string, value time.Duration, rate float64) {}
func (c *MockStats) SetLogger(logger pilosa.Logger) {}
func (c *MockStats) SetLogger(logger logger.Logger) {}
func (c *MockStats) Open() {}
func (c *MockStats) Close() error { return nil }

View file

@ -19,7 +19,8 @@ import (
"time"
"github.com/DataDog/datadog-go/statsd"
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/stats"
)
// StatsD protocol wrapper using the DataDog library that added Tags to the StatsD protocol
@ -34,13 +35,13 @@ const (
)
// Ensure client implements interface.
var _ pilosa.StatsClient = &statsClient{}
var _ stats.StatsClient = &statsClient{}
// statsClient represents a StatsD implementation of pilosa.statsClient.
type statsClient struct {
client *statsd.Client
tags []string
logger pilosa.Logger
logger logger.Logger
}
// NewStatsClient returns a new instance of StatsClient.
@ -52,7 +53,7 @@ func NewStatsClient(host string) (*statsClient, error) {
return &statsClient{
client: c,
logger: pilosa.NopLogger,
logger: logger.NopLogger,
}, nil
}
@ -70,7 +71,7 @@ func (c *statsClient) Tags() []string {
}
// WithTags returns a new client with additional tags appended.
func (c *statsClient) WithTags(tags ...string) pilosa.StatsClient {
func (c *statsClient) WithTags(tags ...string) stats.StatsClient {
return &statsClient{
client: c.client,
tags: unionStringSlice(c.tags, tags),
@ -122,7 +123,7 @@ func (c *statsClient) Timing(name string, value time.Duration, rate float64) {
}
// SetLogger sets the logger for client.
func (c *statsClient) SetLogger(logger pilosa.Logger) {
func (c *statsClient) SetLogger(logger logger.Logger) {
c.logger = logger
}

View file

@ -15,6 +15,7 @@ import (
"time"
"github.com/cespare/xxhash"
"github.com/pilosa/pilosa/logger"
"github.com/pkg/errors"
)
@ -68,7 +69,7 @@ type TranslateFile struct {
Path string
mapSize int
logger Logger
logger logger.Logger
// If non-nil, data is streamed from a primary and this is a read-only store.
PrimaryTranslateStore TranslateStore
primaryID string // unique ID used to identify the primary store
@ -89,7 +90,7 @@ func OptTranslateFileMapSize(mapSize int) TranslateFileOption {
return nil
}
}
func OptTranslateFileLogger(l Logger) TranslateFileOption {
func OptTranslateFileLogger(l logger.Logger) TranslateFileOption {
return func(s *TranslateFile) error {
s.logger = l
return nil
@ -116,7 +117,7 @@ func NewTranslateFile(opts ...TranslateFileOption) *TranslateFile {
mapSize: defaultMapSize,
logger: NopLogger,
logger: logger.NopLogger,
replicationClosing: make(chan struct{}),
primaryStoreEvents: make(chan primaryStoreEvent),

10
view.go
View file

@ -22,8 +22,10 @@ import (
"strings"
"sync"
"github.com/pilosa/pilosa/logger"
"github.com/pilosa/pilosa/pql"
"github.com/pilosa/pilosa/roaring"
"github.com/pilosa/pilosa/stats"
"github.com/pkg/errors"
)
@ -50,9 +52,9 @@ type view struct {
fragments map[uint64]*fragment
broadcaster broadcaster
stats StatsClient
stats stats.StatsClient
rowAttrStore AttrStore
logger Logger
logger logger.Logger
}
// newView returns a new instance of View.
@ -70,8 +72,8 @@ func newView(path, index, field, name string, fieldOptions FieldOptions) *view {
fragments: make(map[uint64]*fragment),
broadcaster: NopBroadcaster,
stats: NopStatsClient,
logger: NopLogger,
stats: stats.NopStatsClient,
logger: logger.NopLogger,
}
}