Add tags to MaxRow metric

This commit is contained in:
Alan Bernstein 2020-04-10 11:31:48 -05:00 committed by Matt Jaffee
parent b1838159f2
commit b37a0addb3
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
3 changed files with 37 additions and 8 deletions

View file

@ -30,6 +30,7 @@ import (
"os"
"runtime/debug"
"sort"
"strconv"
"strings"
"sync"
"syscall"
@ -208,7 +209,9 @@ func (f *fragment) Open() error {
// Read last bit to determine max row.
f.maxRowID = f.storage.Max() / ShardWidth
f.stats.Gauge(MetricMaximumRow, float64(f.maxRowID), 1.0)
fieldTag := "field:" + f.field
shardTag := "shard:" + strconv.FormatInt(int64(f.shard), 10)
f.stats.GaugeWithCustomTags(MetricMaximumRow, float64(f.maxRowID), 1.0, []string{fieldTag, shardTag})
return nil
}(); err != nil {
f.close()
@ -581,7 +584,9 @@ func (f *fragment) unprotectedSetBit(rowID, columnID uint64) (changed bool, err
// Update row count if they have increased.
if rowID > f.maxRowID {
f.maxRowID = rowID
f.stats.Gauge(MetricMaximumRow, float64(f.maxRowID), 1.0)
fieldTag := "field:" + f.field
shardTag := "shard:" + strconv.FormatInt(int64(f.shard), 10)
f.stats.GaugeWithCustomTags(MetricMaximumRow, float64(f.maxRowID), 1.0, []string{fieldTag, shardTag})
}
return changed, nil

View file

@ -202,6 +202,11 @@ func (c *prometheusClient) Gauge(name string, value float64, rate float64) {
gauge.Set(float64(value))
}
// GaugeWithCustomTags sets the value of a metric with custom tags.
func (c *prometheusClient) GaugeWithCustomTags(name string, value float64, rate float64, t []string) {
c.WithTags(append(c.tags, t...)...).Gauge(name, value, rate)
}
// Histogram tracks statistical distribution of a metric.
func (c *prometheusClient) Histogram(name string, value float64, rate float64) {
mu.Lock()

View file

@ -44,6 +44,9 @@ type StatsClient interface {
// Sets the value of a metric.
Gauge(name string, value float64, rate float64)
// Sets the value of a metric with custom tags
GaugeWithCustomTags(name string, value float64, rate float64, tags []string)
// Tracks statistical distribution of a metric.
Histogram(name string, value float64, rate float64)
@ -73,12 +76,14 @@ func (c *nopStatsClient) WithTags(tags ...string) StatsClient
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) {}
func (c *nopStatsClient) SetLogger(logger logger.Logger) {}
func (c *nopStatsClient) Open() {}
func (c *nopStatsClient) Close() error { return nil }
func (c *nopStatsClient) GaugeWithCustomTags(name string, value float64, rate float64, tags []string) {
}
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.Logger) {}
func (c *nopStatsClient) Open() {}
func (c *nopStatsClient) Close() error { return nil }
// expvarStatsClient writes stats out to expvars.
type expvarStatsClient struct {
@ -132,6 +137,13 @@ func (c *expvarStatsClient) Gauge(name string, value float64, rate float64) {
c.m.Set(name, &f)
}
// GaugeWithCustomTags Sets the value of a metric with custom tags
func (c *expvarStatsClient) GaugeWithCustomTags(name string, value float64, rate float64, tags []string) {
var f expvar.Float
f.Set(value)
c.m.Set(name, &f)
}
// Histogram tracks statistical distribution of a metric.
// This works the same as gauge for this client.
func (c *expvarStatsClient) Histogram(name string, value float64, rate float64) {
@ -204,6 +216,13 @@ func (a MultiStatsClient) Gauge(name string, value float64, rate float64) {
}
}
// GaugeWithCustomTags Sets the value of a metric with custom tags
func (a MultiStatsClient) GaugeWithCustomTags(name string, value float64, rate float64, tags []string) {
for _, c := range a {
c.GaugeWithCustomTags(name, value, rate, tags)
}
}
// Histogram tracks statistical distribution of a metric on all clients.
func (a MultiStatsClient) Histogram(name string, value float64, rate float64) {
for _, c := range a {