mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-09 04:17:51 +00:00
Add sampling rate to StatsD functions, and fix data dog logging
This commit is contained in:
parent
bd44949cb5
commit
4a051900c0
11 changed files with 111 additions and 101 deletions
6
cache.go
6
cache.go
|
|
@ -95,12 +95,12 @@ func (c *LRUCache) Len() int { return c.cache.Len() }
|
|||
|
||||
// Invalidate is a no-op.
|
||||
func (c *LRUCache) Invalidate() {
|
||||
c.stats.Gauge("LRUCache", float64(c.cache.Len()))
|
||||
c.stats.Gauge("LRUCache", float64(c.cache.Len()), 1.0)
|
||||
}
|
||||
|
||||
// Recalculate is a no-op.
|
||||
func (c *LRUCache) Recalculate() {
|
||||
c.stats.Gauge("LRUCache", float64(c.cache.Len()))
|
||||
c.stats.Gauge("LRUCache", float64(c.cache.Len()), 1.0)
|
||||
}
|
||||
|
||||
// IDs returns a list of all IDs in the cache.
|
||||
|
|
@ -256,7 +256,7 @@ func (c *RankCache) recalculate() {
|
|||
// Store the count of the item at the threshold index.
|
||||
c.rankings = rankings
|
||||
length := len(c.rankings)
|
||||
c.stats.Gauge("RankCache", float64(length))
|
||||
c.stats.Gauge("RankCache", float64(length), 1.0)
|
||||
|
||||
if length > int(c.maxEntries) {
|
||||
c.thresholdValue = rankings[c.maxEntries].Count
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ import (
|
|||
|
||||
const (
|
||||
// Rate represents a metric rate of 1/sec.
|
||||
Rate = 1
|
||||
// Rate = 1
|
||||
|
||||
// Client buffer size.
|
||||
BufferLen = 256
|
||||
// BufferLen Stats lient buffer size.
|
||||
BufferLen = 1024
|
||||
)
|
||||
|
||||
// Ensure client implements interface.
|
||||
|
|
@ -49,6 +49,7 @@ type StatsClient struct {
|
|||
// NewStatsClient returns a new instance of StatsClient.
|
||||
func NewStatsClient(host string) (*StatsClient, error) {
|
||||
c, err := statsd.NewBuffered(host, BufferLen)
|
||||
// c, err := statsd.New(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -72,50 +73,51 @@ func (c *StatsClient) Tags() []string {
|
|||
// WithTags returns a new client with additional tags appended.
|
||||
func (c *StatsClient) WithTags(tags ...string) pilosa.StatsClient {
|
||||
return &StatsClient{
|
||||
client: c.client,
|
||||
tags: pilosa.UnionStringSlice(c.tags, tags),
|
||||
client: c.client,
|
||||
tags: pilosa.UnionStringSlice(c.tags, tags),
|
||||
LogOutput: c.LogOutput,
|
||||
}
|
||||
}
|
||||
|
||||
// Count tracks the number of times something occurs per second.
|
||||
func (c *StatsClient) Count(name string, value int64) {
|
||||
if err := c.client.Count(name, value, c.tags, Rate); err != nil {
|
||||
func (c *StatsClient) Count(name string, value int64, rate float64) {
|
||||
if err := c.client.Count("pilosa."+name, value, c.tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Count error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Count tracks the number of times something occurs per second with custom tags.
|
||||
func (c *StatsClient) CountWithCustomTags(name string, value int64, t []string) {
|
||||
// CountWithCustomTags tracks the number of times something occurs per second with custom tags.
|
||||
func (c *StatsClient) CountWithCustomTags(name string, value int64, rate float64, t []string) {
|
||||
tags := append(c.tags, t...)
|
||||
if err := c.client.Count(name, value, tags, Rate); err != nil {
|
||||
if err := c.client.Count("pilosa."+name, value, tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Count error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Gauge sets the value of a metric.
|
||||
func (c *StatsClient) Gauge(name string, value float64) {
|
||||
if err := c.client.Gauge(name, value, c.tags, Rate); err != nil {
|
||||
func (c *StatsClient) Gauge(name string, value float64, rate float64) {
|
||||
if err := c.client.Gauge("pilosa."+name, value, c.tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Gauge error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Histogram tracks statistical distribution of a metric.
|
||||
func (c *StatsClient) Histogram(name string, value float64) {
|
||||
if err := c.client.Histogram(name, value, c.tags, Rate); err != nil {
|
||||
func (c *StatsClient) Histogram(name string, value float64, rate float64) {
|
||||
if err := c.client.Histogram("pilosa."+name, value, c.tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Histogram error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Set tracks number of unique elements.
|
||||
func (c *StatsClient) Set(name string, value string) {
|
||||
if err := c.client.Set(name, value, c.tags, Rate); err != nil {
|
||||
func (c *StatsClient) Set(name string, value string, rate float64) {
|
||||
if err := c.client.Set("pilosa."+name, value, c.tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Set error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Timing tracks timing information for a metric.
|
||||
func (c *StatsClient) Timing(name string, value time.Duration) {
|
||||
if err := c.client.Timing(name, value, c.tags, Rate); err != nil {
|
||||
func (c *StatsClient) Timing(name string, value time.Duration, rate float64) {
|
||||
if err := c.client.Timing("pilosa."+name, value, c.tags, rate); err != nil {
|
||||
c.logger().Printf("datadog.StatsClient.Timing error: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
executor.go
14
executor.go
|
|
@ -164,7 +164,7 @@ func (e *Executor) executeCall(ctx context.Context, index string, c *pql.Call, s
|
|||
case "ClearBit":
|
||||
return e.executeClearBit(ctx, index, c, opt)
|
||||
case "Count":
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, []string{indexTag})
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})
|
||||
return e.executeCount(ctx, index, c, slices, opt)
|
||||
case "SetBit":
|
||||
return e.executeSetBit(ctx, index, c, opt)
|
||||
|
|
@ -173,10 +173,10 @@ func (e *Executor) executeCall(ctx context.Context, index string, c *pql.Call, s
|
|||
case "SetColumnAttrs":
|
||||
return nil, e.executeSetColumnAttrs(ctx, index, c, opt)
|
||||
case "TopN":
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, []string{indexTag})
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})
|
||||
return e.executeTopN(ctx, index, c, slices, opt)
|
||||
default:
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, []string{indexTag})
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})
|
||||
return e.executeBitmapCall(ctx, index, c, slices, opt)
|
||||
}
|
||||
}
|
||||
|
|
@ -577,7 +577,7 @@ func (e *Executor) executeRangeSlice(ctx context.Context, index string, c *pql.C
|
|||
}
|
||||
bm = bm.Union(f.Row(id))
|
||||
}
|
||||
f.Stats.Count("range", 1)
|
||||
f.Stats.Count("range", 1, 1.0)
|
||||
return bm, nil
|
||||
}
|
||||
|
||||
|
|
@ -863,7 +863,7 @@ func (e *Executor) executeSetRowAttrs(ctx context.Context, index string, c *pql.
|
|||
if err := frame.RowAttrStore().SetAttrs(rowID, attrs); err != nil {
|
||||
return err
|
||||
}
|
||||
frame.Stats.Count("SetBitmapAttrs", 1)
|
||||
frame.Stats.Count("SetBitmapAttrs", 1, 1.0)
|
||||
|
||||
// Do not forward call if this is already being forwarded.
|
||||
if opt.Remote {
|
||||
|
|
@ -949,7 +949,7 @@ func (e *Executor) executeBulkSetRowAttrs(ctx context.Context, index string, cal
|
|||
if err := frame.RowAttrStore().SetBulkAttrs(frameMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame.Stats.Count("SetBitmapAttrs", 1)
|
||||
frame.Stats.Count("SetBitmapAttrs", 1, 1.0)
|
||||
}
|
||||
|
||||
// Do not forward call if this is already being forwarded.
|
||||
|
|
@ -1009,7 +1009,7 @@ func (e *Executor) executeSetColumnAttrs(ctx context.Context, index string, c *p
|
|||
if err := idx.ColumnAttrStore().SetAttrs(id, attrs); err != nil {
|
||||
return err
|
||||
}
|
||||
idx.Stats.Count("SetProfileAttrs", 1)
|
||||
idx.Stats.Count("SetProfileAttrs", 1, 1.0)
|
||||
// Do not forward call if this is already being forwarded.
|
||||
if opt.Remote {
|
||||
return nil
|
||||
|
|
|
|||
11
fragment.go
11
fragment.go
|
|
@ -407,7 +407,7 @@ func (f *Fragment) setBit(rowID, columnID uint64) (changed bool, err error) {
|
|||
// Update the cache.
|
||||
f.cache.Add(rowID, bm.Count())
|
||||
|
||||
f.stats.Count("setN", 1)
|
||||
f.stats.Count("setBit", 1, 1.0)
|
||||
|
||||
return changed, nil
|
||||
}
|
||||
|
|
@ -453,7 +453,7 @@ func (f *Fragment) clearBit(rowID, columnID uint64) (changed bool, err error) {
|
|||
// Update the cache.
|
||||
f.cache.Add(rowID, bm.Count())
|
||||
|
||||
f.stats.Count("clearN", 1)
|
||||
f.stats.Count("clearBit", 1, 1.0)
|
||||
|
||||
return changed, nil
|
||||
}
|
||||
|
|
@ -951,7 +951,8 @@ func (f *Fragment) Import(rowIDs, columnIDs []uint64) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.stats.Count("ImportBit", 1)
|
||||
// Reduce the StatsD rate for high volume stats
|
||||
f.stats.Count("ImportBit", 1, 0.0001)
|
||||
// import optimization to avoid linear foreach calls
|
||||
// slight risk of concurrent cache counter being off but
|
||||
// no real danger
|
||||
|
|
@ -1011,7 +1012,7 @@ func (f *Fragment) Snapshot() error {
|
|||
func track(start time.Time, message string, stats StatsClient, logger *log.Logger) {
|
||||
elapsed := time.Since(start)
|
||||
logger.Printf("%s took %s", message, elapsed)
|
||||
stats.Histogram("snapshot", elapsed.Seconds())
|
||||
stats.Histogram("snapshot", elapsed.Seconds(), 1.0)
|
||||
}
|
||||
|
||||
func (f *Fragment) snapshot() error {
|
||||
|
|
@ -1394,7 +1395,7 @@ func (s *FragmentSyncer) SyncFragment() error {
|
|||
if err := s.syncBlock(blockID); err != nil {
|
||||
return fmt.Errorf("sync block: id=%d, err=%s", blockID, err)
|
||||
}
|
||||
s.Fragment.stats.Count("BlockRepair", 1)
|
||||
s.Fragment.stats.Count("BlockRepair", 1, 1.0)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
2
frame.go
2
frame.go
|
|
@ -271,7 +271,7 @@ func (f *Frame) openViews() error {
|
|||
view.RowAttrStore = f.rowAttrStore
|
||||
f.views[view.Name()] = view
|
||||
|
||||
f.Stats.Count("maxSlice", 1)
|
||||
// f.Stats.Count("maxSlice", 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
10
handler.go
10
handler.go
|
|
@ -159,7 +159,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
statsTags = append(statsTags, "useragent:"+r.UserAgent())
|
||||
|
||||
stats := h.Holder.Stats.WithTags(statsTags...)
|
||||
stats.Histogram("http_"+endpointName, float64(dif))
|
||||
stats.Histogram("http."+endpointName, float64(dif), 1.0)
|
||||
}
|
||||
|
||||
func (h *Handler) handleWebUI(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -414,7 +414,7 @@ func (h *Handler) handleDeleteIndex(w http.ResponseWriter, r *http.Request) {
|
|||
h.logger().Printf("response encoding error: %s", err)
|
||||
}
|
||||
|
||||
h.Holder.Stats.Count("deleteIndex", 1)
|
||||
h.Holder.Stats.Count("deleteIndex", 1, 1.0)
|
||||
}
|
||||
|
||||
type deleteIndexResponse struct{}
|
||||
|
|
@ -459,7 +459,7 @@ func (h *Handler) handlePostIndex(w http.ResponseWriter, r *http.Request) {
|
|||
h.logger().Printf("response encoding error: %s", err)
|
||||
}
|
||||
|
||||
h.Holder.Stats.Count("createIndex", 1)
|
||||
h.Holder.Stats.Count("createIndex", 1, 1.0)
|
||||
}
|
||||
|
||||
// handlePatchIndexTimeQuantum handles PATCH /index/time_quantum request.
|
||||
|
|
@ -611,7 +611,7 @@ func (h *Handler) handlePostFrame(w http.ResponseWriter, r *http.Request) {
|
|||
h.logger().Printf("response encoding error: %s", err)
|
||||
}
|
||||
|
||||
h.Holder.Stats.CountWithCustomTags("createFrame", 1, []string{fmt.Sprintf("index:%s", indexName)})
|
||||
h.Holder.Stats.CountWithCustomTags("createFrame", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -695,7 +695,7 @@ func (h *Handler) handleDeleteFrame(w http.ResponseWriter, r *http.Request) {
|
|||
h.logger().Printf("response encoding error: %s", err)
|
||||
}
|
||||
|
||||
h.Holder.Stats.CountWithCustomTags("deleteFrame", 1, []string{fmt.Sprintf("index:%s", indexName)})
|
||||
h.Holder.Stats.CountWithCustomTags("deleteFrame", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)})
|
||||
}
|
||||
|
||||
type deleteFrameResponse struct{}
|
||||
|
|
|
|||
8
index.go
8
index.go
|
|
@ -260,6 +260,11 @@ func (i *Index) MaxSlice() uint64 {
|
|||
max = slice
|
||||
}
|
||||
}
|
||||
fmt.Println("*** Get MAXSLICE ***", max)
|
||||
i.Stats.Gauge("maxSlice", float64(max), 1.0)
|
||||
|
||||
fmt.Println("### My Remote MAXSLICE ###", i.remoteMaxSlice)
|
||||
|
||||
return max
|
||||
}
|
||||
|
||||
|
|
@ -268,6 +273,9 @@ func (i *Index) SetRemoteMaxSlice(newmax uint64) {
|
|||
i.mu.Lock()
|
||||
defer i.mu.Unlock()
|
||||
i.remoteMaxSlice = newmax
|
||||
|
||||
fmt.Println("### Set Remote MAXSLICE ###", newmax)
|
||||
// i.Stats.Gauge("maxSlice", float64(newmax), 1.0)
|
||||
}
|
||||
|
||||
// MaxInverseSlice returns the max inverse slice in the index according to this node.
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ func (s *Server) monitorAntiEntropy() {
|
|||
case <-s.closing:
|
||||
return
|
||||
case <-ticker.C:
|
||||
s.Holder.Stats.Count("AntiEntropy", 1)
|
||||
s.Holder.Stats.Count("AntiEntropy", 1, 1.0)
|
||||
}
|
||||
|
||||
s.logger().Printf("holder sync beginning")
|
||||
|
|
@ -226,7 +226,7 @@ func (s *Server) monitorAntiEntropy() {
|
|||
s.logger().Printf("holder sync complete")
|
||||
}
|
||||
dif := time.Since(t)
|
||||
s.Holder.Stats.Histogram("AntiEntropyDuration", float64(dif))
|
||||
s.Holder.Stats.Histogram("AntiEntropyDuration", float64(dif), 1.0)
|
||||
}
|
||||
|
||||
// monitorMaxSlices periodically pulls the highest slice from each node in the cluster.
|
||||
|
|
@ -465,12 +465,12 @@ func (s *Server) monitorRuntime() {
|
|||
return
|
||||
case <-gcn.AfterGC():
|
||||
// GC just ran
|
||||
s.Holder.Stats.Count("garbage_collection", 1)
|
||||
s.Holder.Stats.Count("garbage_collection", 1, 1.0)
|
||||
case <-ticker.C:
|
||||
}
|
||||
|
||||
// Record the number of go routines
|
||||
s.Holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()))
|
||||
s.Holder.Stats.Gauge("goroutines", float64(runtime.NumGoroutine()), 1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
stats.go
66
stats.go
|
|
@ -38,22 +38,22 @@ type StatsClient interface {
|
|||
WithTags(tags ...string) StatsClient
|
||||
|
||||
// Tracks the number of times something occurs per second.
|
||||
Count(name string, value int64)
|
||||
Count(name string, value int64, rate float64)
|
||||
|
||||
// Tracks the number of times something occurs per second with custom tags
|
||||
CountWithCustomTags(name string, value int64, tags []string)
|
||||
CountWithCustomTags(name string, value int64, rate float64, tags []string)
|
||||
|
||||
// Sets the value of a metric.
|
||||
Gauge(name string, value float64)
|
||||
Gauge(name string, value float64, rate float64)
|
||||
|
||||
// Tracks statistical distribution of a metric.
|
||||
Histogram(name string, value float64)
|
||||
Histogram(name string, value float64, rate float64)
|
||||
|
||||
// Tracks number of unique elements.
|
||||
Set(name string, value string)
|
||||
Set(name string, value string, rate float64)
|
||||
|
||||
// Tracks timing information for a metric.
|
||||
Timing(name string, value time.Duration)
|
||||
Timing(name string, value time.Duration, rate float64)
|
||||
}
|
||||
|
||||
// NopStatsClient represents a client that doesn't do anything.
|
||||
|
|
@ -61,14 +61,14 @@ var NopStatsClient StatsClient
|
|||
|
||||
type nopStatsClient struct{}
|
||||
|
||||
func (c *nopStatsClient) Tags() []string { return nil }
|
||||
func (c *nopStatsClient) WithTags(tags ...string) StatsClient { return c }
|
||||
func (c *nopStatsClient) Count(name string, value int64) {}
|
||||
func (c *nopStatsClient) CountWithCustomTags(name string, value int64, tags []string) {}
|
||||
func (c *nopStatsClient) Gauge(name string, value float64) {}
|
||||
func (c *nopStatsClient) Histogram(name string, value float64) {}
|
||||
func (c *nopStatsClient) Set(name string, value string) {}
|
||||
func (c *nopStatsClient) Timing(name string, value time.Duration) {}
|
||||
func (c *nopStatsClient) Tags() []string { return nil }
|
||||
func (c *nopStatsClient) WithTags(tags ...string) StatsClient { return c }
|
||||
func (c *nopStatsClient) Count(name string, value int64, rate float64) {}
|
||||
func (c *nopStatsClient) CountWithCustomTags(name string, value int64, rate float64, tags []string) {}
|
||||
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) {}
|
||||
|
||||
// ExpvarStatsClient writes stats out to expvars.
|
||||
type ExpvarStatsClient struct {
|
||||
|
|
@ -103,17 +103,17 @@ func (c *ExpvarStatsClient) WithTags(tags ...string) StatsClient {
|
|||
}
|
||||
|
||||
// Count tracks the number of times something occurs.
|
||||
func (c *ExpvarStatsClient) Count(name string, value int64) {
|
||||
func (c *ExpvarStatsClient) Count(name string, value int64, rate float64) {
|
||||
c.m.Add(name, value)
|
||||
}
|
||||
|
||||
// CountWithCustomTags Tracks the number of times something occurs per second with custom tags
|
||||
func (c *ExpvarStatsClient) CountWithCustomTags(name string, value int64, tags []string) {
|
||||
func (c *ExpvarStatsClient) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
|
||||
c.m.Add(name, value)
|
||||
}
|
||||
|
||||
// Gauge sets the value of a metric.
|
||||
func (c *ExpvarStatsClient) Gauge(name string, value float64) {
|
||||
func (c *ExpvarStatsClient) Gauge(name string, value float64, rate float64) {
|
||||
var f expvar.Float
|
||||
f.Set(value)
|
||||
c.m.Set(name, &f)
|
||||
|
|
@ -121,17 +121,17 @@ func (c *ExpvarStatsClient) Gauge(name string, value float64) {
|
|||
|
||||
// Histogram tracks statistical distribution of a metric.
|
||||
// This works the same as gauge for this client.
|
||||
func (c *ExpvarStatsClient) Histogram(name string, value float64) {
|
||||
c.Gauge(name, value)
|
||||
func (c *ExpvarStatsClient) Histogram(name string, value float64, rate float64) {
|
||||
c.Gauge(name, value, rate)
|
||||
}
|
||||
|
||||
// Set tracks number of unique elements.
|
||||
func (c *ExpvarStatsClient) Set(name string, value string) {
|
||||
func (c *ExpvarStatsClient) Set(name string, value string, rate float64) {
|
||||
c.m.Set(name, &expvar.String{})
|
||||
}
|
||||
|
||||
// Timing tracks timing information for a metric.
|
||||
func (c *ExpvarStatsClient) Timing(name string, value time.Duration) {
|
||||
func (c *ExpvarStatsClient) Timing(name string, value time.Duration, rate float64) {
|
||||
c.mu.Lock()
|
||||
d, _ := c.m.Get(name).(time.Duration)
|
||||
c.m.Set(name, d+value)
|
||||
|
|
@ -159,44 +159,44 @@ func (a MultiStatsClient) WithTags(tags ...string) StatsClient {
|
|||
}
|
||||
|
||||
// Count tracks the number of times something occurs per second on all clients.
|
||||
func (a MultiStatsClient) Count(name string, value int64) {
|
||||
func (a MultiStatsClient) Count(name string, value int64, rate float64) {
|
||||
for _, c := range a {
|
||||
c.Count(name, value)
|
||||
c.Count(name, value, rate)
|
||||
}
|
||||
}
|
||||
|
||||
// CountWithCustomTags Tracks the number of times something occurs per second with custom tags
|
||||
func (a MultiStatsClient) CountWithCustomTags(name string, value int64, tags []string) {
|
||||
func (a MultiStatsClient) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
|
||||
for _, c := range a {
|
||||
c.CountWithCustomTags(name, value, tags)
|
||||
c.CountWithCustomTags(name, value, rate, tags)
|
||||
}
|
||||
}
|
||||
|
||||
// Gauge sets the value of a metric on all clients.
|
||||
func (a MultiStatsClient) Gauge(name string, value float64) {
|
||||
func (a MultiStatsClient) Gauge(name string, value float64, rate float64) {
|
||||
for _, c := range a {
|
||||
c.Gauge(name, value)
|
||||
c.Gauge(name, value, rate)
|
||||
}
|
||||
}
|
||||
|
||||
// Histogram tracks statistical distribution of a metric on all clients.
|
||||
func (a MultiStatsClient) Histogram(name string, value float64) {
|
||||
func (a MultiStatsClient) Histogram(name string, value float64, rate float64) {
|
||||
for _, c := range a {
|
||||
c.Histogram(name, value)
|
||||
c.Histogram(name, value, rate)
|
||||
}
|
||||
}
|
||||
|
||||
// Set tracks number of unique elements on all clients.
|
||||
func (a MultiStatsClient) Set(name string, value string) {
|
||||
func (a MultiStatsClient) Set(name string, value string, rate float64) {
|
||||
for _, c := range a {
|
||||
c.Set(name, value)
|
||||
c.Set(name, value, rate)
|
||||
}
|
||||
}
|
||||
|
||||
// Timing tracks timing information for a metric on all clients.
|
||||
func (a MultiStatsClient) Timing(name string, value time.Duration) {
|
||||
func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64) {
|
||||
for _, c := range a {
|
||||
c.Timing(name, value)
|
||||
c.Timing(name, value, rate)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func TestStatsCount_TopN(t *testing.T) {
|
|||
called := false
|
||||
e := NewExecutor(hldr.Holder, NewCluster(1))
|
||||
e.Holder.Stats = &MockStats{
|
||||
mockCountWithTags: func(name string, value int64, tags []string) {
|
||||
mockCountWithTags: func(name string, value int64, rate float64, tags []string) {
|
||||
if name != "TopN" {
|
||||
t.Errorf("Expected TopN, Results %s", name)
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func TestStatsCount_Bitmap(t *testing.T) {
|
|||
called := false
|
||||
e := NewExecutor(hldr.Holder, NewCluster(1))
|
||||
e.Holder.Stats = &MockStats{
|
||||
mockCountWithTags: func(name string, value int64, tags []string) {
|
||||
mockCountWithTags: func(name string, value int64, rate float64, tags []string) {
|
||||
if name != "Bitmap" {
|
||||
t.Errorf("Expected Bitmap, Results %s", name)
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func TestStatsCount_SetBitmapAttrs(t *testing.T) {
|
|||
}
|
||||
|
||||
frame.Stats = &MockStats{
|
||||
mockCount: func(name string, value int64) {
|
||||
mockCount: func(name string, value int64, rate float64) {
|
||||
if name != "SetBitmapAttrs" {
|
||||
t.Errorf("Expected SetBitmapAttrs, Results %s", name)
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) {
|
|||
}
|
||||
|
||||
idx.Stats = &MockStats{
|
||||
mockCount: func(name string, value int64) {
|
||||
mockCount: func(name string, value int64, rate float64) {
|
||||
if name != "SetProfileAttrs" {
|
||||
t.Errorf("Expected SetProfilepAttrs, Results %s", name)
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ func TestStatsCount_CreateIndex(t *testing.T) {
|
|||
defer s.Close()
|
||||
called := false
|
||||
s.Handler.Holder.Stats = &MockStats{
|
||||
mockCount: func(name string, value int64) {
|
||||
mockCount: func(name string, value int64, rate float64) {
|
||||
if name != "createIndex" {
|
||||
t.Errorf("Expected createIndex, Results %s", name)
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ func TestStatsCount_DeleteIndex(t *testing.T) {
|
|||
}
|
||||
called := false
|
||||
s.Handler.Holder.Stats = &MockStats{
|
||||
mockCount: func(name string, value int64) {
|
||||
mockCount: func(name string, value int64, rate float64) {
|
||||
if name != "deleteIndex" {
|
||||
t.Errorf("Expected deleteIndex, Results %s", name)
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ func TestStatsCount_CreateFrame(t *testing.T) {
|
|||
}
|
||||
called := false
|
||||
s.Handler.Holder.Stats = &MockStats{
|
||||
mockCountWithTags: func(name string, value int64, index []string) {
|
||||
mockCountWithTags: func(name string, value int64, rate float64, index []string) {
|
||||
if name != "createFrame" {
|
||||
t.Errorf("Expected createFrame, Results %s", name)
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ func TestStatsCount_DeleteFrame(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
s.Handler.Holder.Stats = &MockStats{
|
||||
mockCountWithTags: func(name string, value int64, index []string) {
|
||||
mockCountWithTags: func(name string, value int64, rate float64, index []string) {
|
||||
if name != "deleteFrame" {
|
||||
t.Errorf("Expected deleteFrame, Results %s", name)
|
||||
}
|
||||
|
|
@ -254,29 +254,29 @@ func TestStatsCount_DeleteFrame(t *testing.T) {
|
|||
}
|
||||
|
||||
type MockStats struct {
|
||||
mockCount func(name string, value int64)
|
||||
mockCountWithTags func(name string, value int64, tags []string)
|
||||
mockCount func(name string, value int64, rate float64)
|
||||
mockCountWithTags func(name string, value int64, rate float64, tags []string)
|
||||
}
|
||||
|
||||
func (s *MockStats) Count(name string, value int64) {
|
||||
func (s *MockStats) Count(name string, value int64, rate float64) {
|
||||
if s.mockCount != nil {
|
||||
s.mockCount(name, value)
|
||||
s.mockCount(name, value, rate)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *MockStats) CountWithCustomTags(name string, value int64, tags []string) {
|
||||
func (s *MockStats) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
|
||||
if s.mockCountWithTags != nil {
|
||||
s.mockCountWithTags(name, value, tags)
|
||||
s.mockCountWithTags(name, value, rate, tags)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *MockStats) Tags() []string { return nil }
|
||||
func (c *MockStats) WithTags(tags ...string) pilosa.StatsClient { return c }
|
||||
func (c *MockStats) Gauge(name string, value float64) {}
|
||||
func (c *MockStats) Histogram(name string, value float64) {}
|
||||
func (c *MockStats) Set(name string, value string) {}
|
||||
func (c *MockStats) Timing(name string, value time.Duration) {}
|
||||
func (c *MockStats) Tags() []string { return nil }
|
||||
func (c *MockStats) WithTags(tags ...string) pilosa.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) {}
|
||||
|
|
|
|||
9
view.go
9
view.go
|
|
@ -148,8 +148,6 @@ func (v *View) openFragments() error {
|
|||
}
|
||||
frag.RowAttrStore = v.RowAttrStore
|
||||
v.fragments[frag.Slice()] = frag
|
||||
|
||||
v.stats.Count("maxSlice", 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -180,6 +178,8 @@ func (v *View) MaxSlice() uint64 {
|
|||
max = slice
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("*** VIEW MaxSlice", max)
|
||||
return max
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +233,8 @@ func (v *View) createFragmentIfNotExists(slice uint64) (*Fragment, error) {
|
|||
if slice > v.maxSlice {
|
||||
v.maxSlice = slice
|
||||
|
||||
fmt.Println("*** Create Fragment", slice)
|
||||
|
||||
// Send the create slice message to all nodes.
|
||||
err := v.broadcaster.SendAsync(
|
||||
&internal.CreateSliceMessage{
|
||||
|
|
@ -247,9 +249,6 @@ func (v *View) createFragmentIfNotExists(slice uint64) (*Fragment, error) {
|
|||
|
||||
// Save to lookup.
|
||||
v.fragments[slice] = frag
|
||||
|
||||
v.stats.Count("maxSlice", 1)
|
||||
|
||||
return frag, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue