File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,16 @@ func (p *Pusher) Collector(c prometheus.Collector) *Pusher {
168
168
return p
169
169
}
170
170
171
+ // MustCollector works like Collector but registers any number of
172
+ // Collectors and panics upon the first registration that causes an
173
+ // error.
174
+ //
175
+ // For convenience, this method returns a pointer to the Pusher itself.
176
+ func (p * Pusher ) MustCollector (c ... prometheus.Collector ) * Pusher {
177
+ p .registerer .MustRegister (c ... )
178
+ return p
179
+ }
180
+
171
181
// Grouping adds a label pair to the grouping key of the Pusher, replacing any
172
182
// previously added label pair with the same label name. Note that setting any
173
183
// labels in the grouping key that are already contained in the metrics to push
Original file line number Diff line number Diff line change @@ -107,6 +107,22 @@ func TestPush(t *testing.T) {
107
107
t .Error ("unexpected path:" , lastPath )
108
108
}
109
109
110
+ // use MustCollectors, all good.
111
+ if err := New (pgwOK .URL , "testjob" ).
112
+ MustCollector (metric1 , metric2 ).
113
+ Push (); err != nil {
114
+ t .Fatal (err )
115
+ }
116
+ if lastMethod != http .MethodPut {
117
+ t .Errorf ("got method %q for Push, want %q" , lastMethod , http .MethodPut )
118
+ }
119
+ if ! bytes .Equal (lastBody , wantBody ) {
120
+ t .Errorf ("got body %v, want %v" , lastBody , wantBody )
121
+ }
122
+ if lastPath != "/metrics/job/testjob" {
123
+ t .Error ("unexpected path:" , lastPath )
124
+ }
125
+
110
126
// Add some Collectors, with nil grouping, all good.
111
127
if err := New (pgwOK .URL , "testjob" ).
112
128
Collector (metric1 ).
You can’t perform that action at this time.
0 commit comments