Skip to content

Commit 0ceac8d

Browse files
authored
metrics: fix docstrings (#29279)
1 parent 45b88ab commit 0ceac8d

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
}
@@ -331,7 +331,7 @@ var (
331331
AccountingRegistry = NewRegistry() // registry used in swarm
332332
)
333333

334-
// Call the given function for each registered metric.
334+
// Each call the given function for each registered metric.
335335
func Each(f func(string, interface{})) {
336336
DefaultRegistry.Each(f)
337337
}
@@ -341,7 +341,7 @@ func Get(name string) interface{} {
341341
return DefaultRegistry.Get(name)
342342
}
343343

344-
// Gets an existing metric or creates and registers a new one. Threadsafe
344+
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
345345
// alternative to calling Get and Register on failure.
346346
func GetOrRegister(name string, i interface{}) interface{} {
347347
return DefaultRegistry.GetOrRegister(name, i)
@@ -353,15 +353,15 @@ func Register(name string, i interface{}) error {
353353
return DefaultRegistry.Register(name, i)
354354
}
355355

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

364-
// Run all registered healthchecks.
364+
// RunHealthchecks run all registered healthchecks.
365365
func RunHealthchecks() {
366366
DefaultRegistry.RunHealthchecks()
367367
}

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)