Skip to content

Commit

Permalink
objstore: do not set last successful time metric before 1st upload (#921
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
GiedriusS authored and bwplotka committed Mar 14, 2019
1 parent 2b86692 commit 7fab732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/objstore/objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 7fab732

Please sign in to comment.