Skip to content

Commit f0c45ac

Browse files
author
beorn7
committed
Rename Deliver into Gather
1 parent f9c977b commit f0c45ac

File tree

8 files changed

+53
-54
lines changed

8 files changed

+53
-54
lines changed

prometheus/doc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
// So far, everything we did operated on the so-called default registry, as it
147147
// can be found in the global DefaultRegistry variable. With NewRegistry, you
148148
// can create a custom registry, or you can even implement the Registerer or
149-
// Deliverer interfaces yourself. The methods Register and Unregister work in
149+
// Gatherer interfaces yourself. The methods Register and Unregister work in
150150
// the same way on a custom registry as the global functions Register and
151151
// Unregister on the default registry.
152152
//
@@ -163,10 +163,10 @@
163163
//
164164
// HTTP Exposition
165165
//
166-
// The Registry implements the Deliverer interface. The caller of the Deliver
167-
// method can then expose the delivered metrics in some way. Usually, the
168-
// metrics are served via HTTP on the /metrics endpoint. That's happening in the
169-
// example above. The tools to expose metrics via HTTP are in the promhttp
166+
// The Registry implements the Gatherer interface. The caller of the Gather
167+
// method can then expose the gathered metrics in some way. Usually, the metrics
168+
// are served via HTTP on the /metrics endpoint. That's happening in the example
169+
// above. The tools to expose metrics via HTTP are in the promhttp
170170
// sub-package. (The top-level functions in the prometheus package are
171171
// deprecated.)
172172
//

prometheus/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func ExampleSummaryVec() {
390390
reg := prometheus.NewRegistry()
391391
reg.MustRegister(temps)
392392

393-
metricFamilies, err := reg.Deliver()
393+
metricFamilies, err := reg.Gather()
394394
if err != nil || len(metricFamilies) != 1 {
395395
panic("unexpected behavior of custom test registry")
396396
}

prometheus/http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func giveBuf(buf *bytes.Buffer) {
5656
bufPool.Put(buf)
5757
}
5858

59-
// Handler returns an HTTP handler for the DefaultDeliverer. It is
59+
// Handler returns an HTTP handler for the DefaultGatherer. It is
6060
// already instrumented with InstrumentHandler (using "prometheus" as handler
6161
// name).
6262
//
@@ -67,12 +67,12 @@ func Handler() http.Handler {
6767
return InstrumentHandler("prometheus", UninstrumentedHandler())
6868
}
6969

70-
// UninstrumentedHandler returns an HTTP handler for the DefaultDeliverer.
70+
// UninstrumentedHandler returns an HTTP handler for the DefaultGatherer.
7171
//
7272
// Deprecated: Use promhttp.Handler instead. See there for further documentation.
7373
func UninstrumentedHandler() http.Handler {
7474
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
75-
mfs, err := DefaultDeliverer.Deliver()
75+
mfs, err := DefaultGatherer.Gather()
7676
if err != nil {
7777
http.Error(w, "An error has occurred during metrics collection:\n\n"+err.Error(), http.StatusInternalServerError)
7878
return

prometheus/process_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestProcessCollector(t *testing.T) {
2525
t.Fatal(err)
2626
}
2727

28-
mfs, err := registry.Deliver()
28+
mfs, err := registry.Gather()
2929
if err != nil {
3030
t.Fatal(err)
3131
}

prometheus/promhttp/http.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
// will also contain tooling to instrument instances of http.Handler and
2323
// http.RoundTripper.
2424
//
25-
// promhttp.Handler acts on the prometheus.DefaultDeliverer. With HandlerFor,
25+
// promhttp.Handler acts on the prometheus.DefaultGatherer. With HandlerFor,
2626
// you can create a handler for a custom registry or anything that implements
27-
// the Deliverer interface. It also allows to create handlers that act
27+
// the Gatherer interface. It also allows to create handlers that act
2828
// differently on errors or allow to log errors.
2929
package promhttp
3030

@@ -64,22 +64,22 @@ func giveBuf(buf *bytes.Buffer) {
6464
bufPool.Put(buf)
6565
}
6666

67-
// Handler returns an HTTP handler for the prometheus.DefaultDeliverer. The
67+
// Handler returns an HTTP handler for the prometheus.DefaultGatherer. The
6868
// Handler uses the default HandlerOpts, i.e. report the first error as an HTTP
6969
// error, no error logging, and compression if requested by the client.
7070
//
71-
// If you want to create a Handler for the DefaultDeliverer with different
72-
// HandlerOpts, create it with HandlerFor with prometheus.DefaultDeliverer and
71+
// If you want to create a Handler for the DefaultGatherer with different
72+
// HandlerOpts, create it with HandlerFor with prometheus.DefaultGatherer and
7373
// your desired HandlerOpts.
7474
func Handler() http.Handler {
75-
return HandlerFor(prometheus.DefaultDeliverer, HandlerOpts{})
75+
return HandlerFor(prometheus.DefaultGatherer, HandlerOpts{})
7676
}
7777

78-
// HandlerFor returns an http.Handler for the provided Deliverer. The behavior
78+
// HandlerFor returns an http.Handler for the provided Gatherer. The behavior
7979
// ef the Handler is defined by the provided HandlerOpts.
80-
func HandlerFor(reg prometheus.Deliverer, opts HandlerOpts) http.Handler {
80+
func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler {
8181
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
82-
mfs, err := reg.Deliver()
82+
mfs, err := reg.Gather()
8383
if err != nil {
8484
if opts.ErrorLog != nil {
8585
opts.ErrorLog.Println("error collecting metrics:", err)

prometheus/push/push.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import (
4444

4545
const contentTypeHeader = "Content-Type"
4646

47-
// Registry triggers a metric collection by the provided Deliverer (which is
47+
// Registry triggers a metric collection by the provided Gatherer (which is
4848
// usually implemented by a prometheus.Registry, thus the name of the function)
49-
// and pushes all delivered metrics to the Pushgateway specified by url, using
49+
// and pushes all gathered metrics to the Pushgateway specified by url, using
5050
// the provided job name and the (optional) further grouping labels (the
5151
// grouping map may be nil). See the Pushgateway documentation for detailed
5252
// implications of the job and other grouping labels. Neither the job name nor
@@ -60,18 +60,18 @@ const contentTypeHeader = "Content-Type"
6060
// Note that all previously pushed metrics with the same job and other grouping
6161
// labels will be replaced with the metrics pushed by this call. (It uses HTTP
6262
// method 'PUT' to push to the Pushgateway.)
63-
func Registry(job string, grouping map[string]string, url string, reg prometheus.Deliverer) error {
63+
func Registry(job string, grouping map[string]string, url string, reg prometheus.Gatherer) error {
6464
return push(job, grouping, url, reg, "PUT")
6565
}
6666

6767
// RegistryAdd works like Registry, but only previously pushed metrics with the
6868
// same name (and the same job and other grouping labels) will be replaced. (It
6969
// uses HTTP method 'POST' to push to the Pushgateway.)
70-
func RegistryAdd(job string, grouping map[string]string, url string, reg prometheus.Deliverer) error {
70+
func RegistryAdd(job string, grouping map[string]string, url string, reg prometheus.Gatherer) error {
7171
return push(job, grouping, url, reg, "POST")
7272
}
7373

74-
func push(job string, grouping map[string]string, pushURL string, reg prometheus.Deliverer, method string) error {
74+
func push(job string, grouping map[string]string, pushURL string, reg prometheus.Gatherer, method string) error {
7575
if !strings.Contains(pushURL, "://") {
7676
pushURL = "http://" + pushURL
7777
}
@@ -94,7 +94,7 @@ func push(job string, grouping map[string]string, pushURL string, reg prometheus
9494
}
9595
pushURL = fmt.Sprintf("%s/metrics/job/%s", pushURL, strings.Join(urlComponents, "/"))
9696

97-
mfs, err := reg.Deliver()
97+
mfs, err := reg.Gather()
9898
if err != nil {
9999
return err
100100
}
@@ -134,14 +134,14 @@ func push(job string, grouping map[string]string, pushURL string, reg prometheus
134134
return nil
135135
}
136136

137-
// Collectors works like Registry, but it does not use a Deliverer. Instead, it
137+
// Collectors works like Registry, but it does not use a Gatherer. Instead, it
138138
// collects from the provided collectors directly. It is a convenient way to
139139
// push only a few metrics.
140140
func Collectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error {
141141
return pushCollectors(job, grouping, url, "PUT", collectors...)
142142
}
143143

144-
// AddCollectors works like RegistryAdd, but it does not use a Deliverer.
144+
// AddCollectors works like RegistryAdd, but it does not use a Gatherer.
145145
// Instead, it collects from the provided collectors directly. It is a
146146
// convenient way to push only a few metrics.
147147
func AddCollectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error {

prometheus/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestPush(t *testing.T) {
8383
reg.MustRegister(metric1)
8484
reg.MustRegister(metric2)
8585

86-
mfs, err := reg.Deliver()
86+
mfs, err := reg.Gather()
8787
if err != nil {
8888
t.Fatal(err)
8989
}

prometheus/registry.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
)
3434

3535
// DefaultRegistry is a Registry instance that has a ProcessCollector and a
36-
// GoCollector pre-registered. DefaultRegisterer and DefaultDeliverer are both
36+
// GoCollector pre-registered. DefaultRegisterer and DefaultGatherer are both
3737
// pointing to it. A number of convenience functions in this package act on
3838
// them. This approach to keep a default instance as global state mirrors the
3939
// approach of other packages in the Go standard library. Note that there are
@@ -43,7 +43,7 @@ const (
4343
var (
4444
DefaultRegistry = NewRegistry()
4545
DefaultRegisterer Registerer = DefaultRegistry
46-
DefaultDeliverer Deliverer = DefaultRegistry
46+
DefaultGatherer Gatherer = DefaultRegistry
4747
)
4848

4949
func init() {
@@ -115,24 +115,23 @@ type Registerer interface {
115115
Unregister(Collector) bool
116116
}
117117

118-
// Deliverer is the interface for the part of a registry in charge of delivering
119-
// the collected metrics, wich the same general implication as described for the
120-
// Registerer interface.
121-
type Deliverer interface {
122-
// Deliver collects metrics from registered Collectors and returns them
123-
// as lexicographically sorted MetricFamily protobufs. Even if an error
124-
// occurs, Deliver attempts to collect as many metrics as
125-
// possible. Hence, if a non-nil error is returned, the returned
126-
// MetricFamily slice could be nil (in case of a fatal error that
127-
// prevented any meaningful metric collection) or contain a number of
128-
// MetricFamily protobufs, some of which might be incomplete, and some
129-
// might be missing altogether. The returned error (which might be a
130-
// multierror.Error) explains the details. In any case, the MetricFamily
131-
// protobufs are consistent and valid for Prometheus to ingest (e.g. no
132-
// duplicate metrics, no invalid identifiers). In scenarios where
133-
// complete collection is critical, the returned MetricFamily protobufs
134-
// should be disregarded if the returned error is non-nil.
135-
Deliver() ([]*dto.MetricFamily, error)
118+
// Gatherer is the interface for the part of a registry in charge of gathering
119+
// the collected metrics into a number of MetricFamilies. The Gatherer interface
120+
// comes with the same general implication as described for the Registerer
121+
// interface.
122+
type Gatherer interface {
123+
// Gather calls the Collect method of the registered Collectors and then
124+
// gathers the collected metrics into a lexicographically sorted slice
125+
// of MetricFamily protobufs. Even if an error occurs, Gather attempts
126+
// to gather as many metrics as possible. Hence, if a non-nil error is
127+
// returned, the returned MetricFamily slice could be nil (in case of a
128+
// fatal error that prevented any meaningful metric collection) or
129+
// contain a number of MetricFamily protobufs, some of which might be
130+
// incomplete, and some might be missing altogether. The returned error
131+
// (which might be a MultiError) explains the details. In scenarios
132+
// where complete collection is critical, the returned MetricFamily
133+
// protobufs should be disregarded if the returned error is non-nil.
134+
Gather() ([]*dto.MetricFamily, error)
136135
}
137136

138137
// Register registers the provided Collector with the DefaultRegisterer.
@@ -221,10 +220,10 @@ func (err AlreadyRegisteredError) Error() string {
221220
return "duplicate metrics collector registration attempted"
222221
}
223222

224-
// Registry registers Prometheus collectors, collects their metrics, and
225-
// delivers them for exposition. It implements Registerer and Deliverer. The
226-
// zero value is not usable. Use NewRegistry or NewPedanticRegistry to create
227-
// instances.
223+
// Registry registers Prometheus collectors, collects their metrics, and gathers
224+
// them into MetricFamilies for exposition. It implements Registerer and
225+
// Gatherer. The zero value is not usable. Create instances with NewRegistry or
226+
// NewPedanticRegistry.
228227
type Registry struct {
229228
mtx sync.RWMutex
230229
collectorsByID map[uint64]Collector // ID is a hash of the descIDs.
@@ -361,8 +360,8 @@ func (r *Registry) MustRegister(cs ...Collector) {
361360
}
362361
}
363362

364-
// Deliver implements Deliverer.
365-
func (r *Registry) Deliver() ([]*dto.MetricFamily, error) {
363+
// Gather implements Gatherer.
364+
func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
366365
var (
367366
metricChan = make(chan Metric, capMetricChan)
368367
metricHashes = map[uint64]struct{}{}

0 commit comments

Comments
 (0)