From 3712d889fde3e6622659d702367e0d7ef3a78d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 14 Mar 2019 00:29:57 +0200 Subject: [PATCH] objstore: do not set last successful time metric before 1st upload Convert lastSuccessfullUploadTime into a GaugeVec with one dimension: bucket, which makes client_golang *not* make that metric unless at least one value has appeared. This is better for users since Grafana will show that last upload has been 49+ years ago instead of N/A when no uploads had happened before. Fixes #886. --- CHANGELOG.md | 3 +++ pkg/objstore/objstore.go | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3f3b5c9f..5dd5fdd7a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ We use *breaking* word for marking changes that are not backward compatible (rel ### Added - [#811](https://github.com/improbable-eng/thanos/pull/811) Remote write receiver +### Fixed +- [#921](https://github.com/improbable-eng/thanos/pull/921) `thanos_objstore_bucket_last_successful_upload_time` now does not appear when no blocks have been uploaded so far + ## [v0.3.2](https://github.com/improbable-eng/thanos/releases/tag/v0.3.2) - 2019.03.04 ### Added diff --git a/pkg/objstore/objstore.go b/pkg/objstore/objstore.go index 2790b29c04..4b241e972a 100644 --- a/pkg/objstore/objstore.go +++ b/pkg/objstore/objstore.go @@ -194,10 +194,10 @@ func BucketWithMetrics(name string, b Bucket, r prometheus.Registerer) Bucket { ConstLabels: prometheus.Labels{"bucket": name}, Buckets: []float64{0.005, 0.01, 0.02, 0.04, 0.08, 0.15, 0.3, 0.6, 1, 1.5, 2.5, 5, 10, 20, 30}, }, []string{"operation"}), - lastSuccessfullUploadTime: prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "thanos_objstore_bucket_last_successful_upload_time", - Help: "Second timestamp of the last successful upload to the bucket.", - ConstLabels: prometheus.Labels{"bucket": name}}), + lastSuccessfullUploadTime: prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "thanos_objstore_bucket_last_successful_upload_time", + Help: "Second timestamp of the last successful upload to the bucket.", + }, []string{"bucket"}), } if r != nil { r.MustRegister(bkt.ops, bkt.opsFailures, bkt.opsDuration, bkt.lastSuccessfullUploadTime) @@ -211,7 +211,7 @@ type metricBucket struct { ops *prometheus.CounterVec opsFailures *prometheus.CounterVec opsDuration *prometheus.HistogramVec - lastSuccessfullUploadTime prometheus.Gauge + lastSuccessfullUploadTime *prometheus.GaugeVec } func (b *metricBucket) Iter(ctx context.Context, dir string, f func(name string) error) error { @@ -287,7 +287,7 @@ func (b *metricBucket) Upload(ctx context.Context, name string, r io.Reader) err b.opsFailures.WithLabelValues(op).Inc() } else { //TODO: Use SetToCurrentTime() once we update the Prometheus client_golang - b.lastSuccessfullUploadTime.Set(float64(time.Now().UnixNano()) / 1e9) + b.lastSuccessfullUploadTime.WithLabelValues(b.bkt.Name()).Set(float64(time.Now().UnixNano()) / 1e9) } b.ops.WithLabelValues(op).Inc() b.opsDuration.WithLabelValues(op).Observe(time.Since(start).Seconds())