Skip to content

Commit

Permalink
Merge pull request #66 from ritaCanavarro/addUploadedTSDBblocksmetric
Browse files Browse the repository at this point in the history
objstore: Add uploaded TSDB bytes metric
  • Loading branch information
fpetkovski authored Sep 8, 2023
2 parents 1b257a3 + 47a0da2 commit 8d397d4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#61](https://github.com/thanos-io/objstore/pull/61) Add OpenTelemetry TracingBucket.
> This also changes the behaviour of `client.NewBucket`. Now it returns, uninstrumented and untraced bucket.
You can combine `objstore.WrapWithMetrics` and `tracing/{opentelemetry,opentracing}.WrapWithTraces` to have old behavior.
- [#69](https://github.com/thanos-io/objstore/pull/69) [#66](https://github.com/thanos-io/objstore/pull/66) Add `objstore_bucket_operation_transferred_bytes` that counts the number of total bytes read from the bucket operation Get/GetRange and also counts the number of total bytes written to the bucket operation Upload.
- [#64](https://github.com/thanos-io/objstore/pull/64) OCI: OKE Workload Identity support.
- [#73](https://github.com/thanos-io/objstore/pull/73) Аdded file path to erros from DownloadFile
- [#51](https://github.com/thanos-io/objstore/pull/51) Azure: Support using connection string authentication.
Expand Down
26 changes: 20 additions & 6 deletions objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,12 @@ func WrapWithMetrics(b Bucket, reg prometheus.Registerer, name string) *metricBu
bkt.opsDuration.WithLabelValues(op)
bkt.opsFetchedBytes.WithLabelValues(op)
}
// fetched bytes only relevant for get and getrange

// fetched bytes only relevant for get, getrange and upload
for _, op := range []string{
OpGet,
OpGetRange,
// TODO: Add uploads
OpUpload,
} {
bkt.opsTransferredBytes.WithLabelValues(op)
}
Expand Down Expand Up @@ -592,15 +593,25 @@ func (b *metricBucket) Upload(ctx context.Context, name string, r io.Reader) err
const op = OpUpload
b.ops.WithLabelValues(op).Inc()

start := time.Now()
if err := b.bkt.Upload(ctx, name, r); err != nil {
trc := newTimingReadCloser(
io.NopCloser(r),
op,
b.opsDuration,
b.opsFailures,
b.isOpFailureExpected,
nil,
b.opsTransferredBytes,
)
defer trc.Close()
err := b.bkt.Upload(ctx, name, trc)
if err != nil {
if !b.isOpFailureExpected(err) && ctx.Err() != context.Canceled {
b.opsFailures.WithLabelValues(op).Inc()
}
return err
}
b.lastSuccessfulUploadTime.SetToCurrentTime()
b.opsDuration.WithLabelValues(op).Observe(time.Since(start).Seconds())

return nil
}

Expand Down Expand Up @@ -692,7 +703,10 @@ func (rc *timingReadCloser) Close() error {

func (rc *timingReadCloser) Read(b []byte) (n int, err error) {
n, err = rc.ReadCloser.Read(b)
rc.fetchedBytes.WithLabelValues(rc.op).Add(float64(n))
if rc.fetchedBytes != nil {
rc.fetchedBytes.WithLabelValues(rc.op).Add(float64(n))
}

rc.readBytes += int64(n)
// Report metric just once.
if !rc.alreadyGotErr && err != nil && err != io.EOF {
Expand Down
19 changes: 19 additions & 0 deletions objstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ func TestDownloadUploadDirConcurrency(t *testing.T) {
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="get_range",le="+Inf"} 0
objstore_bucket_operation_transferred_bytes_sum{bucket="",operation="get_range"} 0
objstore_bucket_operation_transferred_bytes_count{bucket="",operation="get_range"} 0
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="32768"} 2
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="65536"} 2
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="131072"} 2
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="262144"} 2
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="524288"} 2
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="1.048576e+06"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="2.097152e+06"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="4.194304e+06"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="8.388608e+06"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="1.6777216e+07"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="3.3554432e+07"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="6.7108864e+07"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="1.34217728e+08"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="2.68435456e+08"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="5.36870912e+08"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="1.073741824e+09"} 3
objstore_bucket_operation_transferred_bytes_bucket{bucket="",operation="upload",le="+Inf"} 3
objstore_bucket_operation_transferred_bytes_sum{bucket="",operation="upload"} 1.048578e+06
objstore_bucket_operation_transferred_bytes_count{bucket="",operation="upload"} 3
`), `objstore_bucket_operation_transferred_bytes`))

testutil.Ok(t, UploadDir(context.Background(), log.NewNopLogger(), m, tempDir, "/dir-copy", WithUploadConcurrency(10)))
Expand Down

0 comments on commit 8d397d4

Please sign in to comment.