зеркало из https://github.com/github/vitess-gh.git
stats: rename Map* to Multi* to make multidimensionality of the counters more obvious.
Conflicts: go/cmd/vtgate/vtgate.go go/vt/tabletserver/schema_info.go go/vt/vtgate/scatter_conn.go
This commit is contained in:
Родитель
4dfe120382
Коммит
a73625a93a
|
@ -41,8 +41,8 @@ func main() {
|
|||
resilientSrvTopoServer = vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServerCounts")
|
||||
|
||||
labels := []string{"Cell", "Keyspace", "ShardName", "DbType"}
|
||||
_ = stats.NewMapCountersFunc("EndpointCount", labels, resilientSrvTopoServer.EndpointCount)
|
||||
_ = stats.NewMapCountersFunc("DegradedEndpointCount", labels, resilientSrvTopoServer.DegradedEndpointCount)
|
||||
_ = stats.NewMultiCountersFunc("EndpointCount", labels, resilientSrvTopoServer.EndpointCount)
|
||||
_ = stats.NewMultiCountersFunc("DegradedEndpointCount", labels, resilientSrvTopoServer.DegradedEndpointCount)
|
||||
|
||||
// For the initial phase vtgate is exposing
|
||||
// topoReader api. This will be subsumed by
|
||||
|
|
|
@ -95,17 +95,18 @@ func counterToString(m map[string]int64) string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
// MapCounters is a Counters implementation where names of categories
|
||||
// are compound names made with joining multiple strings with '.'.
|
||||
type MapCounters struct {
|
||||
// MultiCounters is a multidimensional Counters implementation where
|
||||
// names of categories are compound names made with joining multiple
|
||||
// strings with '.'.
|
||||
type MultiCounters struct {
|
||||
Counters
|
||||
labels []string
|
||||
}
|
||||
|
||||
// NewMapCounters creates a new MapCounters instance, and publishes it
|
||||
// NewMultiCounters creates a new MultiCounters instance, and publishes it
|
||||
// if name is set.
|
||||
func NewMapCounters(name string, labels []string) *MapCounters {
|
||||
t := &MapCounters{
|
||||
func NewMultiCounters(name string, labels []string) *MultiCounters {
|
||||
t := &MultiCounters{
|
||||
Counters: Counters{counts: make(map[string]int64)},
|
||||
labels: labels,
|
||||
}
|
||||
|
@ -114,46 +115,47 @@ func NewMapCounters(name string, labels []string) *MapCounters {
|
|||
}
|
||||
return t
|
||||
}
|
||||
func (mc *MapCounters) Labels() []string {
|
||||
func (mc *MultiCounters) Labels() []string {
|
||||
return mc.labels
|
||||
}
|
||||
|
||||
// Add adds a value to a named counter. len(names) must be equal to
|
||||
// len(Labels)
|
||||
func (mc *MapCounters) Add(names []string, value int64) {
|
||||
func (mc *MultiCounters) Add(names []string, value int64) {
|
||||
if len(names) != len(mc.labels) {
|
||||
panic("MapCounters: wrong number of values in Add")
|
||||
panic("MultiCounters: wrong number of values in Add")
|
||||
}
|
||||
mc.Counters.Add(strings.Join(names, "."), value)
|
||||
}
|
||||
|
||||
// Set sets the value of a named counter. len(names) must be equal to
|
||||
// len(Labels)
|
||||
func (mc *MapCounters) Set(names []string, value int64) {
|
||||
func (mc *MultiCounters) Set(names []string, value int64) {
|
||||
if len(names) != len(mc.labels) {
|
||||
panic("MapCounters: wrong number of values in Set")
|
||||
panic("MultiCounters: wrong number of values in Set")
|
||||
}
|
||||
mc.Counters.Set(strings.Join(names, "."), value)
|
||||
}
|
||||
|
||||
// MapCountersFunc is a CountersFunc implementation where names of categories
|
||||
// are compound names made with joining multiple strings with '.'.
|
||||
// Since the map is returned by the function, we assume it's in the rigth
|
||||
// format (meaning each key is of the form 'aaa.bbb.ccc' with as many elements
|
||||
// as there are in Labels).
|
||||
type MapCountersFunc struct {
|
||||
// MultiCountersFunc is a multidimensional CountersFunc implementation
|
||||
// where names of categories are compound names made with joining
|
||||
// multiple strings with '.'. Since the map is returned by the
|
||||
// function, we assume it's in the rigth format (meaning each key is
|
||||
// of the form 'aaa.bbb.ccc' with as many elements as there are in
|
||||
// Labels).
|
||||
type MultiCountersFunc struct {
|
||||
CountersFunc
|
||||
labels []string
|
||||
}
|
||||
|
||||
func (mcf *MapCountersFunc) Labels() []string {
|
||||
func (mcf *MultiCountersFunc) Labels() []string {
|
||||
return mcf.labels
|
||||
}
|
||||
|
||||
// NewMapCountersFunc creates a new MapCountersFunc mapping to the provided
|
||||
// NewMultiCountersFunc creates a new MultiCountersFunc mapping to the provided
|
||||
// function.
|
||||
func NewMapCountersFunc(name string, labels []string, f CountersFunc) *MapCountersFunc {
|
||||
t := &MapCountersFunc{
|
||||
func NewMultiCountersFunc(name string, labels []string, f CountersFunc) *MultiCountersFunc {
|
||||
t := &MultiCountersFunc{
|
||||
CountersFunc: f,
|
||||
labels: labels,
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ func TestCounters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMapCounters(t *testing.T) {
|
||||
func TestMultiCounters(t *testing.T) {
|
||||
clear()
|
||||
c := NewMapCounters("mapCounter1", []string{"aaa", "bbb"})
|
||||
c := NewMultiCounters("mapCounter1", []string{"aaa", "bbb"})
|
||||
c.Add([]string{"c1a", "c1b"}, 1)
|
||||
c.Add([]string{"c2a", "c2b"}, 1)
|
||||
c.Add([]string{"c2a", "c2b"}, 1)
|
||||
|
@ -56,7 +56,7 @@ func TestMapCounters(t *testing.T) {
|
|||
if counts["c2a.c2b"] != 2 {
|
||||
t.Errorf("want 2, got %d", counts["c2a.c2b"])
|
||||
}
|
||||
f := NewMapCountersFunc("", []string{"aaa", "bbb"}, func() map[string]int64 {
|
||||
f := NewMultiCountersFunc("", []string{"aaa", "bbb"}, func() map[string]int64 {
|
||||
return map[string]int64{
|
||||
"c1a.c1b": 1,
|
||||
"c2a.c2b": 2,
|
||||
|
|
|
@ -123,17 +123,17 @@ func init() {
|
|||
bucketLabels[len(bucketLabels)-1] = "Max"
|
||||
}
|
||||
|
||||
// MapTimings is meant to tracks timing data
|
||||
// by categories as well as histograms. The names of the categories
|
||||
// are compound names made with joining multiple strings with '.'.
|
||||
type MapTimings struct {
|
||||
// MultiTimings is meant to tracks timing data by categories as well
|
||||
// as histograms. The names of the categories are compound names made
|
||||
// with joining multiple strings with '.'.
|
||||
type MultiTimings struct {
|
||||
Timings
|
||||
labels []string
|
||||
}
|
||||
|
||||
// NewMapTimings creates a new MapTimings object.
|
||||
func NewMapTimings(name string, labels []string) *MapTimings {
|
||||
t := &MapTimings{
|
||||
// NewMultiTimings creates a new MultiTimings object.
|
||||
func NewMultiTimings(name string, labels []string) *MultiTimings {
|
||||
t := &MultiTimings{
|
||||
Timings: Timings{histograms: make(map[string]*Histogram)},
|
||||
labels: labels,
|
||||
}
|
||||
|
@ -143,23 +143,23 @@ func NewMapTimings(name string, labels []string) *MapTimings {
|
|||
return t
|
||||
}
|
||||
|
||||
func (mt *MapTimings) Labels() []string {
|
||||
func (mt *MultiTimings) Labels() []string {
|
||||
return mt.labels
|
||||
}
|
||||
|
||||
// Add will add a new value to the named histogram.
|
||||
func (mt *MapTimings) Add(names []string, elapsed time.Duration) {
|
||||
func (mt *MultiTimings) Add(names []string, elapsed time.Duration) {
|
||||
if len(names) != len(mt.labels) {
|
||||
panic("MapTimings: wrong number of values in Add")
|
||||
panic("MultiTimings: wrong number of values in Add")
|
||||
}
|
||||
mt.Timings.Add(strings.Join(names, "."), elapsed)
|
||||
}
|
||||
|
||||
// Record is a convenience function that records completion
|
||||
// timing data based on the provided start time of an event.
|
||||
func (mt *MapTimings) Record(names []string, startTime time.Time) {
|
||||
func (mt *MultiTimings) Record(names []string, startTime time.Time) {
|
||||
if len(names) != len(mt.labels) {
|
||||
panic("MapTimings: wrong number of values in Record")
|
||||
panic("MultiTimings: wrong number of values in Record")
|
||||
}
|
||||
mt.Timings.Record(strings.Join(names, "."), startTime)
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ func TestTimings(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMapTimings(t *testing.T) {
|
||||
func TestMultiTimings(t *testing.T) {
|
||||
clear()
|
||||
mtm := NewMapTimings("maptimings1", []string{"dim1", "dim2"})
|
||||
mtm := NewMultiTimings("maptimings1", []string{"dim1", "dim2"})
|
||||
mtm.Add([]string{"tag1a", "tag1b"}, 500*time.Microsecond)
|
||||
mtm.Add([]string{"tag1a", "tag1b"}, 1*time.Millisecond)
|
||||
mtm.Add([]string{"tag2a", "tag2b"}, 1*time.Millisecond)
|
||||
|
|
|
@ -106,12 +106,12 @@ func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout tim
|
|||
stats.Publish("SchemaReloadTime", stats.DurationFunc(func() time.Duration {
|
||||
return si.reloadTime
|
||||
}))
|
||||
_ = stats.NewMapCountersFunc("TableStats", []string{"Table", "Stats"}, si.getTableStats)
|
||||
_ = stats.NewMultiCountersFunc("TableStats", []string{"Table", "Stats"}, si.getTableStats)
|
||||
stats.Publish("TableInvalidations", stats.CountersFunc(si.getTableInvalidations))
|
||||
_ = stats.NewMapCountersFunc("QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
|
||||
_ = stats.NewMapCountersFunc("QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
|
||||
_ = stats.NewMapCountersFunc("QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
|
||||
_ = stats.NewMapCountersFunc("QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
|
||||
_ = stats.NewMultiCountersFunc("QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
|
||||
_ = stats.NewMultiCountersFunc("QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
|
||||
_ = stats.NewMultiCountersFunc("QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
|
||||
_ = stats.NewMultiCountersFunc("QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
|
||||
http.Handle("/debug/query_plans", si)
|
||||
http.Handle("/debug/query_stats", si)
|
||||
http.Handle("/debug/table_stats", si)
|
||||
|
|
|
@ -31,7 +31,7 @@ type ScatterConn struct {
|
|||
retryDelay time.Duration
|
||||
retryCount int
|
||||
timeout time.Duration
|
||||
timings *stats.MapTimings
|
||||
timings *stats.MultiTimings
|
||||
|
||||
mu sync.Mutex
|
||||
shardConns map[string]*ShardConn
|
||||
|
@ -53,7 +53,7 @@ func NewScatterConn(serv SrvTopoServer, statsName, cell string, retryDelay time.
|
|||
retryDelay: retryDelay,
|
||||
retryCount: retryCount,
|
||||
timeout: timeout,
|
||||
timings: stats.NewMapTimings(statsName, []string{"Operation", "Keyspace", "ShardName", "DbType"}),
|
||||
timings: stats.NewMultiTimings(statsName, []string{"Operation", "Keyspace", "ShardName", "DbType"}),
|
||||
shardConns: make(map[string]*ShardConn),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ var (
|
|||
// can be created.
|
||||
type VTGate struct {
|
||||
resolver *Resolver
|
||||
timings *stats.MapTimings
|
||||
errors *stats.MapCounters
|
||||
timings *stats.MultiTimings
|
||||
errors *stats.MultiCounters
|
||||
|
||||
// the throttled loggers for all errors, one per API entry
|
||||
logExecuteShard *logutil.ThrottledLogger
|
||||
|
@ -59,8 +59,8 @@ func Init(serv SrvTopoServer, cell string, retryDelay time.Duration, retryCount
|
|||
}
|
||||
RpcVTGate = &VTGate{
|
||||
resolver: NewResolver(serv, "VttabletCall", cell, retryDelay, retryCount, timeout),
|
||||
timings: stats.NewMapTimings("VtgateApi", []string{"Operation", "Keyspace", "DbType"}),
|
||||
errors: stats.NewMapCounters("VtgateApiErrorCounts", []string{"Operation", "Keyspace", "DbType"}),
|
||||
timings: stats.NewMultiTimings("VtgateApi", []string{"Operation", "Keyspace", "DbType"}),
|
||||
errors: stats.NewMultiCounters("VtgateApiErrorCounts", []string{"Operation", "Keyspace", "DbType"}),
|
||||
|
||||
logExecuteShard: logutil.NewThrottledLogger("ExecuteShard", 5*time.Second),
|
||||
logExecuteKeyspaceIds: logutil.NewThrottledLogger("ExecuteKeyspaceIds", 5*time.Second),
|
||||
|
|
Загрузка…
Ссылка в новой задаче