Skip to content

Commit 7f37ee2

Browse files
committed
metrics: fix docstrings (ethereum#29279)
1 parent 2220156 commit 7f37ee2

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

metrics/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func WriteJSONOnce(r Registry, w io.Writer) {
2626
json.NewEncoder(w).Encode(r)
2727
}
2828

29-
func (p *PrefixedRegistry) MarshalJSON() ([]byte, error) {
30-
return json.Marshal(p.GetAll())
29+
func (r *PrefixedRegistry) MarshalJSON() ([]byte, error) {
30+
return json.Marshal(r.GetAll())
3131
}

metrics/registry.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"sync"
99
)
1010

11-
// DuplicateMetric is the error returned by Registry.Register when a metric
12-
// already exists. If you mean to Register that metric you must first
11+
// DuplicateMetric is the error returned by Registry. Register when a metric
12+
// already exists. If you mean to Register that metric you must first
1313
// Unregister the existing metric.
1414
type DuplicateMetric string
1515

@@ -20,11 +20,11 @@ func (err DuplicateMetric) Error() string {
2020
// A Registry holds references to a set of metrics by name and can iterate
2121
// over them, calling callback functions provided by the user.
2222
//
23-
// This is an interface so as to encourage other structs to implement
23+
// This is an interface to encourage other structs to implement
2424
// the Registry API as appropriate.
2525
type Registry interface {
2626

27-
// Call the given function for each registered metric.
27+
// Each call the given function for each registered metric.
2828
Each(func(string, interface{}))
2929

3030
// Get the metric by the given name or nil if none is registered.
@@ -33,15 +33,15 @@ type Registry interface {
3333
// GetAll metrics in the Registry.
3434
GetAll() map[string]map[string]interface{}
3535

36-
// Gets an existing metric or registers the given one.
36+
// GetOrRegister gets an existing metric or registers the given one.
3737
// The interface can be the metric to register if not found in registry,
3838
// or a function returning the metric for lazy instantiation.
3939
GetOrRegister(string, interface{}) interface{}
4040

4141
// Register the given metric under the given name.
4242
Register(string, interface{}) error
4343

44-
// Run all registered healthchecks.
44+
// RunHealthchecks run all registered healthchecks.
4545
RunHealthchecks()
4646

4747
// Unregister the metric with the given name.
@@ -52,7 +52,7 @@ type orderedRegistry struct {
5252
StandardRegistry
5353
}
5454

55-
// Call the given function for each registered metric.
55+
// Each call the given function for each registered metric.
5656
func (r *orderedRegistry) Each(f func(string, interface{})) {
5757
var names []string
5858
reg := r.registered()
@@ -75,13 +75,13 @@ func NewOrderedRegistry() Registry {
7575
return new(orderedRegistry)
7676
}
7777

78-
// The standard implementation of a Registry uses sync.map
78+
// StandardRegistry the standard implementation of a Registry uses sync.map
7979
// of names to metrics.
8080
type StandardRegistry struct {
8181
metrics sync.Map
8282
}
8383

84-
// Call the given function for each registered metric.
84+
// Each call the given function for each registered metric.
8585
func (r *StandardRegistry) Each(f func(string, interface{})) {
8686
for name, i := range r.registered() {
8787
f(name, i)
@@ -94,7 +94,7 @@ func (r *StandardRegistry) Get(name string) interface{} {
9494
return item
9595
}
9696

97-
// Gets an existing metric or creates and registers a new one. Threadsafe
97+
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
9898
// alternative to calling Get and Register on failure.
9999
// The interface can be the metric to register if not found in registry,
100100
// or a function returning the metric for lazy instantiation.
@@ -114,7 +114,7 @@ func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}
114114
return item
115115
}
116116

117-
// Register the given metric under the given name. Returns a DuplicateMetric
117+
// Register the given metric under the given name. Returns a DuplicateMetric
118118
// if a metric by the given name is already registered.
119119
func (r *StandardRegistry) Register(name string, i interface{}) error {
120120
// fast path
@@ -133,7 +133,7 @@ func (r *StandardRegistry) Register(name string, i interface{}) error {
133133
return nil
134134
}
135135

136-
// Run all registered healthchecks.
136+
// RunHealthchecks run all registered healthchecks.
137137
func (r *StandardRegistry) RunHealthchecks() {
138138
r.metrics.Range(func(key, value any) bool {
139139
if h, ok := value.(Healthcheck); ok {
@@ -263,7 +263,7 @@ func NewPrefixedChildRegistry(parent Registry, prefix string) Registry {
263263
}
264264
}
265265

266-
// Call the given function for each registered metric.
266+
// Each call the given function for each registered metric.
267267
func (r *PrefixedRegistry) Each(fn func(string, interface{})) {
268268
wrappedFn := func(prefix string) func(string, interface{}) {
269269
return func(name string, iface interface{}) {
@@ -295,7 +295,7 @@ func (r *PrefixedRegistry) Get(name string) interface{} {
295295
return r.underlying.Get(realName)
296296
}
297297

298-
// Gets an existing metric or registers the given one.
298+
// GetOrRegister gets an existing metric or registers the given one.
299299
// The interface can be the metric to register if not found in registry,
300300
// or a function returning the metric for lazy instantiation.
301301
func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}) interface{} {
@@ -309,7 +309,7 @@ func (r *PrefixedRegistry) Register(name string, metric interface{}) error {
309309
return r.underlying.Register(realName, metric)
310310
}
311311

312-
// Run all registered healthchecks.
312+
// RunHealthchecks run all registered healthchecks.
313313
func (r *PrefixedRegistry) RunHealthchecks() {
314314
r.underlying.RunHealthchecks()
315315
}
@@ -329,7 +329,7 @@ var (
329329
DefaultRegistry = NewRegistry()
330330
)
331331

332-
// Call the given function for each registered metric.
332+
// Each call the given function for each registered metric.
333333
func Each(f func(string, interface{})) {
334334
DefaultRegistry.Each(f)
335335
}
@@ -339,7 +339,7 @@ func Get(name string) interface{} {
339339
return DefaultRegistry.Get(name)
340340
}
341341

342-
// Gets an existing metric or creates and registers a new one. Threadsafe
342+
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
343343
// alternative to calling Get and Register on failure.
344344
func GetOrRegister(name string, i interface{}) interface{} {
345345
return DefaultRegistry.GetOrRegister(name, i)
@@ -351,15 +351,15 @@ func Register(name string, i interface{}) error {
351351
return DefaultRegistry.Register(name, i)
352352
}
353353

354-
// Register the given metric under the given name. Panics if a metric by the
354+
// MustRegister register the given metric under the given name. Panics if a metric by the
355355
// given name is already registered.
356356
func MustRegister(name string, i interface{}) {
357357
if err := Register(name, i); err != nil {
358358
panic(err)
359359
}
360360
}
361361

362-
// Run all registered healthchecks.
362+
// RunHealthchecks run all registered healthchecks.
363363
func RunHealthchecks() {
364364
DefaultRegistry.RunHealthchecks()
365365
}

metrics/timer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type TimerSnapshot interface {
1010
MeterSnapshot
1111
}
1212

13-
// Timers capture the duration and rate of events.
13+
// Timer capture the duration and rate of events.
1414
type Timer interface {
1515
Snapshot() TimerSnapshot
1616
Stop()
@@ -99,22 +99,22 @@ func (t *StandardTimer) Stop() {
9999
t.meter.Stop()
100100
}
101101

102-
// Record the duration of the execution of the given function.
102+
// Time record the duration of the execution of the given function.
103103
func (t *StandardTimer) Time(f func()) {
104104
ts := time.Now()
105105
f()
106106
t.Update(time.Since(ts))
107107
}
108108

109-
// Record the duration of an event, in nanoseconds.
109+
// Update the duration of an event, in nanoseconds.
110110
func (t *StandardTimer) Update(d time.Duration) {
111111
t.mutex.Lock()
112112
defer t.mutex.Unlock()
113113
t.histogram.Update(d.Nanoseconds())
114114
t.meter.Mark(1)
115115
}
116116

117-
// Record the duration of an event that started at a time and ends now.
117+
// UpdateSince update the duration of an event that started at a time and ends now.
118118
// The record uses nanoseconds.
119119
func (t *StandardTimer) UpdateSince(ts time.Time) {
120120
t.Update(time.Since(ts))

0 commit comments

Comments
 (0)