Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objstore: Add uploaded TSDB bytes metric #66

Merged
merged 32 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ritaCanavarro marked this conversation as resolved.
Show resolved Hide resolved
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),
ritaCanavarro marked this conversation as resolved.
Show resolved Hide resolved
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())
ritaCanavarro marked this conversation as resolved.
Show resolved Hide resolved

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 {
ritaCanavarro marked this conversation as resolved.
Show resolved Hide resolved
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