Skip to content

Commit 254a48e

Browse files
SuperQdomgreen
authored andcommitted
Bump Prometheus client_golang vendoring (thanos-io#523)
* Bump Prometheus client_golang vendoring Use the version recommended by the upstream maintainer until there is an official release. There are a number of issues with the very old 0.8.0 verision. Specifically for client_golang, master is considered stable enough to rely on. Experiments are kept in branches. [0]: prometheus/node_exporter#1076 * Fix ProcessCollectorOpts. * Fix 0 counter initializer. * Fixup objstore metrics.
1 parent 1d582af commit 254a48e

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ignored = ["github.com/improbable-eng/thanos/benchmark/*"]
3030

3131
[[constraint]]
3232
name = "github.com/prometheus/client_golang"
33-
version = "0.8.0"
33+
revision = "e637cec7d9c8990247098639ebc6d43dd34ddd49"
3434

3535
[[constraint]]
3636
branch = "master"

cmd/thanos/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func main() {
104104
metrics.MustRegister(
105105
version.NewCollector("thanos"),
106106
prometheus.NewGoCollector(),
107-
prometheus.NewProcessCollector(os.Getpid(), ""),
107+
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
108108
)
109109

110110
prometheus.DefaultRegisterer = metrics

pkg/objstore/objstore.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ func (b *metricBucket) Get(ctx context.Context, name string) (io.ReadCloser, err
231231
b.opsFailures.WithLabelValues(op).Inc()
232232
return nil, err
233233
}
234-
rc = newTimingReadCloser(rc,
235-
b.opsDuration.WithLabelValues(op), b.opsFailures.WithLabelValues(op))
234+
rc = newTimingReadCloser(
235+
rc,
236+
op,
237+
b.opsDuration,
238+
b.opsFailures,
239+
)
236240

237241
return rc, nil
238242
}
@@ -246,8 +250,12 @@ func (b *metricBucket) GetRange(ctx context.Context, name string, off, length in
246250
b.opsFailures.WithLabelValues(op).Inc()
247251
return nil, err
248252
}
249-
rc = newTimingReadCloser(rc,
250-
b.opsDuration.WithLabelValues(op), b.opsFailures.WithLabelValues(op))
253+
rc = newTimingReadCloser(
254+
rc,
255+
op,
256+
b.opsDuration,
257+
b.opsFailures,
258+
)
251259

252260
return rc, nil
253261
}
@@ -310,25 +318,30 @@ type timingReadCloser struct {
310318

311319
ok bool
312320
start time.Time
313-
duration prometheus.Histogram
314-
failed prometheus.Counter
321+
op string
322+
duration *prometheus.HistogramVec
323+
failed *prometheus.CounterVec
315324
}
316325

317-
func newTimingReadCloser(rc io.ReadCloser, dur prometheus.Histogram, failed prometheus.Counter) *timingReadCloser {
326+
func newTimingReadCloser(rc io.ReadCloser, op string, dur *prometheus.HistogramVec, failed *prometheus.CounterVec) *timingReadCloser {
327+
// Initialize the metrics with 0.
328+
dur.WithLabelValues(op)
329+
failed.WithLabelValues(op)
318330
return &timingReadCloser{
319331
ReadCloser: rc,
320332
ok: true,
321333
start: time.Now(),
334+
op: op,
322335
duration: dur,
323336
failed: failed,
324337
}
325338
}
326339

327340
func (rc *timingReadCloser) Close() error {
328341
err := rc.ReadCloser.Close()
329-
rc.duration.Observe(time.Since(rc.start).Seconds())
342+
rc.duration.WithLabelValues(rc.op).Observe(time.Since(rc.start).Seconds())
330343
if rc.ok && err != nil {
331-
rc.failed.Inc()
344+
rc.failed.WithLabelValues(rc.op).Inc()
332345
rc.ok = false
333346
}
334347
return err
@@ -337,7 +350,7 @@ func (rc *timingReadCloser) Close() error {
337350
func (rc *timingReadCloser) Read(b []byte) (n int, err error) {
338351
n, err = rc.ReadCloser.Read(b)
339352
if rc.ok && err != nil && err != io.EOF {
340-
rc.failed.Inc()
353+
rc.failed.WithLabelValues(rc.op).Inc()
341354
rc.ok = false
342355
}
343356
return n, err

pkg/store/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func newIndexCache(reg prometheus.Registerer, maxBytes uint64) (*indexCache, err
8282
}, []string{"item_type"})
8383

8484
// Initialize eviction metric with 0.
85-
evicted.WithLabelValues(cacheTypePostings).Set(0)
86-
evicted.WithLabelValues(cacheTypeSeries).Set(0)
85+
evicted.WithLabelValues(cacheTypePostings)
86+
evicted.WithLabelValues(cacheTypeSeries)
8787

8888
// Initialize LRU cache with a high size limit since we will manage evictions ourselves
8989
// based on stored size.

0 commit comments

Comments
 (0)