@@ -30,8 +30,8 @@ import (
3030type ClientImpl struct {
3131 // parentReporter is the parent scope for the metrics
3232 parentScope tally.Scope
33- childScopes map [int ]tally.Scope
34- metricDefs map [int ]metricDefinition
33+ childScopes map [ScopeIdx ]tally.Scope
34+ metricDefs map [MetricIdx ]metricDefinition
3535 serviceIdx ServiceIdx
3636}
3737
@@ -43,7 +43,7 @@ func NewClient(scope tally.Scope, serviceIdx ServiceIdx) Client {
4343 totalScopes := len (ScopeDefs [Common ]) + len (ScopeDefs [serviceIdx ])
4444 metricsClient := & ClientImpl {
4545 parentScope : scope ,
46- childScopes : make (map [int ]tally.Scope , totalScopes ),
46+ childScopes : make (map [ScopeIdx ]tally.Scope , totalScopes ),
4747 metricDefs : getMetricDefs (serviceIdx ),
4848 serviceIdx : serviceIdx ,
4949 }
@@ -69,60 +69,60 @@ func NewClient(scope tally.Scope, serviceIdx ServiceIdx) Client {
6969
7070// IncCounter increments one for a counter and emits
7171// to metrics backend
72- func (m * ClientImpl ) IncCounter (scopeIdx int , counterIdx int ) {
72+ func (m * ClientImpl ) IncCounter (scope ScopeIdx , counterIdx MetricIdx ) {
7373 name := string (m .metricDefs [counterIdx ].metricName )
74- m .childScopes [scopeIdx ].Counter (name ).Inc (1 )
74+ m .childScopes [scope ].Counter (name ).Inc (1 )
7575}
7676
7777// AddCounter adds delta to the counter and
7878// emits to the metrics backend
79- func (m * ClientImpl ) AddCounter (scopeIdx int , counterIdx int , delta int64 ) {
79+ func (m * ClientImpl ) AddCounter (scope ScopeIdx , counterIdx MetricIdx , delta int64 ) {
8080 name := string (m .metricDefs [counterIdx ].metricName )
81- m .childScopes [scopeIdx ].Counter (name ).Inc (delta )
81+ m .childScopes [scope ].Counter (name ).Inc (delta )
8282}
8383
8484// StartTimer starts a timer for the given
8585// metric name
86- func (m * ClientImpl ) StartTimer (scopeIdx int , timerIdx int ) tally.Stopwatch {
86+ func (m * ClientImpl ) StartTimer (scope ScopeIdx , timerIdx MetricIdx ) tally.Stopwatch {
8787 name := string (m .metricDefs [timerIdx ].metricName )
88- return m .childScopes [scopeIdx ].Timer (name ).Start ()
88+ return m .childScopes [scope ].Timer (name ).Start ()
8989}
9090
9191// RecordTimer record and emit a timer for the given
9292// metric name
93- func (m * ClientImpl ) RecordTimer (scopeIdx int , timerIdx int , d time.Duration ) {
93+ func (m * ClientImpl ) RecordTimer (scope ScopeIdx , timerIdx MetricIdx , d time.Duration ) {
9494 name := string (m .metricDefs [timerIdx ].metricName )
95- m .childScopes [scopeIdx ].Timer (name ).Record (d )
95+ m .childScopes [scope ].Timer (name ).Record (d )
9696}
9797
9898// RecordHistogramDuration record and emit a duration
99- func (m * ClientImpl ) RecordHistogramDuration (scopeIdx int , timerIdx int , d time.Duration ) {
99+ func (m * ClientImpl ) RecordHistogramDuration (scope ScopeIdx , timerIdx MetricIdx , d time.Duration ) {
100100 name := string (m .metricDefs [timerIdx ].metricName )
101- m .childScopes [scopeIdx ].Histogram (name , m .getBuckets (timerIdx )).RecordDuration (d )
101+ m .childScopes [scope ].Histogram (name , m .getBuckets (timerIdx )).RecordDuration (d )
102102}
103103
104104// UpdateGauge reports Gauge type metric
105- func (m * ClientImpl ) UpdateGauge (scopeIdx int , gaugeIdx int , value float64 ) {
105+ func (m * ClientImpl ) UpdateGauge (scopeIdx ScopeIdx , gaugeIdx MetricIdx , value float64 ) {
106106 name := string (m .metricDefs [gaugeIdx ].metricName )
107107 m .childScopes [scopeIdx ].Gauge (name ).Update (value )
108108}
109109
110110// Scope return a new internal metrics scope that can be used to add additional
111111// information to the metrics emitted
112- func (m * ClientImpl ) Scope (scopeIdx int , tags ... Tag ) Scope {
113- scope := m .childScopes [scopeIdx ]
114- return newMetricsScope (scope , scope , m .metricDefs , false ).Tagged (tags ... )
112+ func (m * ClientImpl ) Scope (scope ScopeIdx , tags ... Tag ) Scope {
113+ sc := m .childScopes [scope ]
114+ return newMetricsScope (sc , sc , m .metricDefs , false ).Tagged (tags ... )
115115}
116116
117- func (m * ClientImpl ) getBuckets (id int ) tally.Buckets {
117+ func (m * ClientImpl ) getBuckets (id MetricIdx ) tally.Buckets {
118118 if m .metricDefs [id ].buckets != nil {
119119 return m .metricDefs [id ].buckets
120120 }
121121 return tally .DefaultBuckets
122122}
123123
124- func getMetricDefs (serviceIdx ServiceIdx ) map [int ]metricDefinition {
125- defs := make (map [int ]metricDefinition )
124+ func getMetricDefs (serviceIdx ServiceIdx ) map [MetricIdx ]metricDefinition {
125+ defs := make (map [MetricIdx ]metricDefinition )
126126 for idx , def := range MetricDefs [Common ] {
127127 defs [idx ] = def
128128 }
0 commit comments