Commit 30258b1f authored by tavit ohanian's avatar tavit ohanian

Merge branch 'port-2021-05-02'

parents bbc5c7ae d1dac8f9
Pipeline #327 passed with stages
in 9 seconds
blank_issues_enabled: false
contact_links:
- name: Getting Help on IPFS
url: https://ipfs.io/help
about: All information about how and where to get help on IPFS.
- name: IPFS Official Forum
url: https://discuss.ipfs.io
about: Please post general questions, support requests, and discussions here.
---
name: Open an issue
about: Only for actionable issues relevant to this repository.
title: ''
labels: need/triage
assignees: ''
---
<!--
Hello! To ensure this issue is correctly addressed as soon as possible by the IPFS team, please try to make sure:
- This issue is relevant to this repository's topic or codebase.
- A clear description is provided. It should includes as much relevant information as possible and clear scope for the issue to be actionable.
FOR GENERAL DISCUSSION, HELP OR QUESTIONS, please see the options at https://ipfs.io/help or head directly to https://discuss.ipfs.io.
(you can delete this section after reading)
-->
# Configuration for welcome - https://github.com/behaviorbot/welcome
# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
# Comment to be posted to on first time issues
newIssueWelcomeComment: >
Thank you for submitting your first issue to this repository! A maintainer
will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the
necessary information to make this process easy! Any information that can
help save additional round trips is useful! We currently aim to give
initial feedback within **two business days**. If this does not happen, feel
free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an
overview of priorities, assignments and additional actions requested by the
maintainers:
- "Priority" labels will show how urgent this is for the team.
- "Status" labels will show if this is ready to be worked on, blocked, or in progress.
- "Need" labels will indicate if additional input or analysis is required.
Finally, remember to use https://discuss.ipfs.io if you just need general
support.
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
# Comment to be posted to on PRs from first time contributors in your repository
newPRWelcomeComment: >
Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure
that:
* The context for this PR is clear, with relevant discussion, decisions
and stakeholders linked/mentioned.
* Your contribution itself is clear (code comments, self-review for the
rest) and in its best form. Follow the [code contribution
guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#code-contribution-guidelines)
if they apply.
Getting other community members to do a review would be great help too on
complex PRs (you can ask in the chats/forums). If you are unsure about
something, just leave us a comment.
Next steps:
* A maintainer will triage and assign priority to this PR, commenting on
any missing things and potentially assigning a reviewer for high
priority items.
* The PR gets reviews, discussed and approvals as needed.
* The PR is merged by maintainers when it has been approved and comments addressed.
We currently aim to provide initial feedback/triaging within **two business
days**. Please keep an eye on any labelling actions, as these will indicate
priorities and status of your contribution.
We are very grateful for your contribution!
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
# Comment to be posted to on pull requests merged by a first time user
# Currently disabled
#firstPRMergeComment: ""
stages:
- build
- test
variables:
BUILD_DIR: "/tmp/$CI_CONCURRENT_PROJECT_ID"
before_script:
- mkdir -p $BUILD_DIR/src
- cd $BUILD_DIR/src
- if [ -d $CI_PROJECT_DIR ]
- then
- echo "soft link $CI_PROJECT_DIR exists"
- else
- echo "creating soft link $CI_PROJECT_DIR"
- ln -s $CI_PROJECT_DIR
- fi
- cd $CI_PROJECT_DIR
build:
stage: build
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go build
test:
stage: test
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go test -cover
coverage: '/coverage: \d+.\d+% of statements/'
1.4.5: QmafCXHpwUKGUrt6eQF97U1ornFxTicsw7iyYSAhu9aXgc
os:
- linux
language: go
go:
- 1.12.x
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- $GOPATH/pkg/mod
- $HOME/.cache/go-build
notifications:
email: false
The MIT License
Copyright (c) 2016 Juan Batiz-Benet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o=
github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
gitlab.dms3.io/dms3/public/go-datastore v0.0.1 h1:RjZLvnqlvWDpb5ZwvkVEWGONF7zKNPe4Q0DND5oxZec=
gitlab.dms3.io/dms3/public/go-datastore v0.0.1/go.mod h1:qSI0hpmVMo6HCp0uveHTKyQ87j1aVe2hqiTeiPCehYA=
gitlab.dms3.io/dms3/public/go-dms3-delay v0.0.1/go.mod h1:Mg+buHOoh8UruN+MMqeqBUPBKMRTmpsXAyxv5ZSt+X4=
gitlab.dms3.io/dms3/public/go-metrics-interface v0.0.1 h1:oLJzd5zSjf5C1aEMHziNbV4RbJVuPaNzzKW4VBzKnQM=
gitlab.dms3.io/dms3/public/go-metrics-interface v0.0.1/go.mod h1:Ag1ayfnHxy0H659akn+bjAGn9k/HJrpxsVrB90DmRL8=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
// Package measure provides a Datastore wrapper that records metrics
// using gitlab.dms3.io/dms3/public/go-metrics-interface
package measure
import (
"io"
"time"
"gitlab.dms3.io/dms3/public/go-datastore"
"gitlab.dms3.io/dms3/public/go-datastore/query"
"gitlab.dms3.io/dms3/public/go-metrics-interface"
)
var (
// sort latencies in buckets with following upper bounds in seconds
datastoreLatencyBuckets = []float64{1e-4, 1e-3, 1e-2, 1e-1, 1}
// sort sizes in buckets with following upper bounds in bytes
datastoreSizeBuckets = []float64{1 << 6, 1 << 12, 1 << 18, 1 << 24}
)
// New wraps the datastore, providing metrics on the operations. The
// metrics are registered with names starting with prefix and a dot.
func New(prefix string, ds datastore.Datastore) *measure {
m := &measure{
backend: ds,
putNum: metrics.New(prefix+".put_total", "Total number of Datastore.Put calls").Counter(),
putErr: metrics.New(prefix+".put.errors_total", "Number of errored Datastore.Put calls").Counter(),
putLatency: metrics.New(prefix+".put.latency_seconds",
"Latency distribution of Datastore.Put calls").Histogram(datastoreLatencyBuckets),
putSize: metrics.New(prefix+".put.size_bytes",
"Size distribution of stored byte slices").Histogram(datastoreSizeBuckets),
syncNum: metrics.New(prefix+".sync_total", "Total number of Datastore.Sync calls").Counter(),
syncErr: metrics.New(prefix+".sync.errors_total", "Number of errored Datastore.Sync calls").Counter(),
syncLatency: metrics.New(prefix+".sync.latency_seconds",
"Latency distribution of Datastore.Sync calls").Histogram(datastoreLatencyBuckets),
getNum: metrics.New(prefix+".get_total", "Total number of Datastore.Get calls").Counter(),
getErr: metrics.New(prefix+".get.errors_total", "Number of errored Datastore.Get calls").Counter(),
getLatency: metrics.New(prefix+".get.latency_seconds",
"Latency distribution of Datastore.Get calls").Histogram(datastoreLatencyBuckets),
getSize: metrics.New(prefix+".get.size_bytes",
"Size distribution of retrieved byte slices").Histogram(datastoreSizeBuckets),
hasNum: metrics.New(prefix+".has_total", "Total number of Datastore.Has calls").Counter(),
hasErr: metrics.New(prefix+".has.errors_total", "Number of errored Datastore.Has calls").Counter(),
hasLatency: metrics.New(prefix+".has.latency_seconds",
"Latency distribution of Datastore.Has calls").Histogram(datastoreLatencyBuckets),
getsizeNum: metrics.New(prefix+".getsize_total", "Total number of Datastore.GetSize calls").Counter(),
getsizeErr: metrics.New(prefix+".getsize.errors_total", "Number of errored Datastore.GetSize calls").Counter(),
getsizeLatency: metrics.New(prefix+".getsize.latency_seconds",
"Latency distribution of Datastore.GetSize calls").Histogram(datastoreLatencyBuckets),
deleteNum: metrics.New(prefix+".delete_total", "Total number of Datastore.Delete calls").Counter(),
deleteErr: metrics.New(prefix+".delete.errors_total", "Number of errored Datastore.Delete calls").Counter(),
deleteLatency: metrics.New(prefix+".delete.latency_seconds",
"Latency distribution of Datastore.Delete calls").Histogram(datastoreLatencyBuckets),
queryNum: metrics.New(prefix+".query_total", "Total number of Datastore.Query calls").Counter(),
queryErr: metrics.New(prefix+".query.errors_total", "Number of errored Datastore.Query calls").Counter(),
queryLatency: metrics.New(prefix+".query.latency_seconds",
"Latency distribution of Datastore.Query calls").Histogram(datastoreLatencyBuckets),
checkNum: metrics.New(prefix+".check_total", "Total number of Datastore.Check calls").Counter(),
checkErr: metrics.New(prefix+".check.errors_total", "Number of errored Datastore.Check calls").Counter(),
checkLatency: metrics.New(prefix+".check.latency_seconds",
"Latency distribution of Datastore.Check calls").Histogram(datastoreLatencyBuckets),
scrubNum: metrics.New(prefix+".scrub_total", "Total number of Datastore.Scrub calls").Counter(),
scrubErr: metrics.New(prefix+".scrub.errors_total", "Number of errored Datastore.Scrub calls").Counter(),
scrubLatency: metrics.New(prefix+".scrub.latency_seconds",
"Latency distribution of Datastore.Scrub calls").Histogram(datastoreLatencyBuckets),
gcNum: metrics.New(prefix+".gc_total", "Total number of Datastore.CollectGarbage calls").Counter(),
gcErr: metrics.New(prefix+".gc.errors_total", "Number of errored Datastore.CollectGarbage calls").Counter(),
gcLatency: metrics.New(prefix+".gc.latency_seconds",
"Latency distribution of Datastore.CollectGarbage calls").Histogram(datastoreLatencyBuckets),
duNum: metrics.New(prefix+".du_total", "Total number of Datastore.DiskUsage calls").Counter(),
duErr: metrics.New(prefix+".du.errors_total", "Number of errored Datastore.DiskUsage calls").Counter(),
duLatency: metrics.New(prefix+".du.latency_seconds",
"Latency distribution of Datastore.DiskUsage calls").Histogram(datastoreLatencyBuckets),
batchPutNum: metrics.New(prefix+".batchput_total", "Total number of Batch.Put calls").Counter(),
batchPutErr: metrics.New(prefix+".batchput.errors_total", "Number of errored Batch.Put calls").Counter(),
batchPutLatency: metrics.New(prefix+".batchput.latency_seconds",
"Latency distribution of Batch.Put calls").Histogram(datastoreLatencyBuckets),
batchPutSize: metrics.New(prefix+".batchput.size_bytes",
"Size distribution of byte slices put into batches").Histogram(datastoreSizeBuckets),
batchDeleteNum: metrics.New(prefix+".batchdelete_total", "Total number of Batch.Delete calls").Counter(),
batchDeleteErr: metrics.New(prefix+".batchdelete.errors_total", "Number of errored Batch.Delete calls").Counter(),
batchDeleteLatency: metrics.New(prefix+".batchdelete.latency_seconds",
"Latency distribution of Batch.Delete calls").Histogram(datastoreLatencyBuckets),
batchCommitNum: metrics.New(prefix+".batchcommit_total", "Total number of Batch.Commit calls").Counter(),
batchCommitErr: metrics.New(prefix+".batchcommit.errors_total", "Number of errored Batch.Commit calls").Counter(),
batchCommitLatency: metrics.New(prefix+".batchcommit.latency_seconds",
"Latency distribution of Batch.Commit calls").Histogram(datastoreLatencyBuckets),
}
return m
}
type measure struct {
backend datastore.Datastore
putNum metrics.Counter
putErr metrics.Counter
putLatency metrics.Histogram
putSize metrics.Histogram
syncNum metrics.Counter
syncErr metrics.Counter
syncLatency metrics.Histogram
getNum metrics.Counter
getErr metrics.Counter
getLatency metrics.Histogram
getSize metrics.Histogram
hasNum metrics.Counter
hasErr metrics.Counter
hasLatency metrics.Histogram
getsizeNum metrics.Counter
getsizeErr metrics.Counter
getsizeLatency metrics.Histogram
deleteNum metrics.Counter
deleteErr metrics.Counter
deleteLatency metrics.Histogram
queryNum metrics.Counter
queryErr metrics.Counter
queryLatency metrics.Histogram
checkNum metrics.Counter
checkErr metrics.Counter
checkLatency metrics.Histogram
scrubNum metrics.Counter
scrubErr metrics.Counter
scrubLatency metrics.Histogram
gcNum metrics.Counter
gcErr metrics.Counter
gcLatency metrics.Histogram
duNum metrics.Counter
duErr metrics.Counter
duLatency metrics.Histogram
batchPutNum metrics.Counter
batchPutErr metrics.Counter
batchPutLatency metrics.Histogram
batchPutSize metrics.Histogram
batchDeleteNum metrics.Counter
batchDeleteErr metrics.Counter
batchDeleteLatency metrics.Histogram
batchCommitNum metrics.Counter
batchCommitErr metrics.Counter
batchCommitLatency metrics.Histogram
}
func recordLatency(h metrics.Histogram, start time.Time) {
elapsed := time.Since(start)
h.Observe(elapsed.Seconds())
}
func (m *measure) Put(key datastore.Key, value []byte) error {
defer recordLatency(m.putLatency, time.Now())
m.putNum.Inc()
m.putSize.Observe(float64(len(value)))
err := m.backend.Put(key, value)
if err != nil {
m.putErr.Inc()
}
return err
}
func (m *measure) Sync(prefix datastore.Key) error {
defer recordLatency(m.syncLatency, time.Now())
m.syncNum.Inc()
err := m.backend.Sync(prefix)
if err != nil {
m.syncErr.Inc()
}
return err
}
func (m *measure) Get(key datastore.Key) (value []byte, err error) {
defer recordLatency(m.getLatency, time.Now())
m.getNum.Inc()
value, err = m.backend.Get(key)
switch err {
case nil:
m.getSize.Observe(float64(len(value)))
case datastore.ErrNotFound:
// Not really an error.
default:
m.getErr.Inc()
}
return value, err
}
func (m *measure) Has(key datastore.Key) (exists bool, err error) {
defer recordLatency(m.hasLatency, time.Now())
m.hasNum.Inc()
exists, err = m.backend.Has(key)
if err != nil {
m.hasErr.Inc()
}
return exists, err
}
func (m *measure) GetSize(key datastore.Key) (size int, err error) {
defer recordLatency(m.getsizeLatency, time.Now())
m.getsizeNum.Inc()
size, err = m.backend.GetSize(key)
switch err {
case nil, datastore.ErrNotFound:
// Not really an error.
default:
m.getsizeErr.Inc()
}
return size, err
}
func (m *measure) Delete(key datastore.Key) error {
defer recordLatency(m.deleteLatency, time.Now())
m.deleteNum.Inc()
err := m.backend.Delete(key)
if err != nil {
m.deleteErr.Inc()
}
return err
}
func (m *measure) Query(q query.Query) (query.Results, error) {
defer recordLatency(m.queryLatency, time.Now())
m.queryNum.Inc()
res, err := m.backend.Query(q)
if err != nil {
m.queryErr.Inc()
}
return res, err
}
func (m *measure) Check() error {
defer recordLatency(m.checkLatency, time.Now())
m.checkNum.Inc()
if c, ok := m.backend.(datastore.CheckedDatastore); ok {
err := c.Check()
if err != nil {
m.checkErr.Inc()
}
return err
}
return nil
}
func (m *measure) Scrub() error {
defer recordLatency(m.scrubLatency, time.Now())
m.scrubNum.Inc()
if c, ok := m.backend.(datastore.ScrubbedDatastore); ok {
err := c.Scrub()
if err != nil {
m.scrubErr.Inc()
}
return err
}
return nil
}
func (m *measure) CollectGarbage() error {
defer recordLatency(m.gcLatency, time.Now())
m.gcNum.Inc()
if c, ok := m.backend.(datastore.GCDatastore); ok {
err := c.CollectGarbage()
if err != nil {
m.gcErr.Inc()
}
return err
}
return nil
}
func (m *measure) DiskUsage() (uint64, error) {
defer recordLatency(m.duLatency, time.Now())
m.duNum.Inc()
size, err := datastore.DiskUsage(m.backend)
if err != nil {
m.duErr.Inc()
}
return size, err
}
type measuredBatch struct {
b datastore.Batch
m *measure
}
func (m *measure) Batch() (datastore.Batch, error) {
bds, ok := m.backend.(datastore.Batching)
if !ok {
return nil, datastore.ErrBatchUnsupported
}
batch, err := bds.Batch()
if err != nil {
return nil, err
}
return &measuredBatch{
b: batch,
m: m,
}, nil
}
func (mt *measuredBatch) Put(key datastore.Key, val []byte) error {
defer recordLatency(mt.m.batchPutLatency, time.Now())
mt.m.batchPutNum.Inc()
mt.m.batchPutSize.Observe(float64(len(val)))
err := mt.b.Put(key, val)
if err != nil {
mt.m.batchPutErr.Inc()
}
return err
}
func (mt *measuredBatch) Delete(key datastore.Key) error {
defer recordLatency(mt.m.batchDeleteLatency, time.Now())
mt.m.batchDeleteNum.Inc()
err := mt.b.Delete(key)
if err != nil {
mt.m.batchDeleteErr.Inc()
}
return err
}
func (mt *measuredBatch) Commit() error {
defer recordLatency(mt.m.batchCommitLatency, time.Now())
mt.m.batchCommitNum.Inc()
err := mt.b.Commit()
if err != nil {
mt.m.batchCommitErr.Inc()
}
return err
}
func (m *measure) Close() error {
if c, ok := m.backend.(io.Closer); ok {
return c.Close()
}
return nil
}
package measure
import (
"testing"
dstest "gitlab.dms3.io/dms3/public/go-datastore/test"
)
func TestSuite(t *testing.T) {
d := New("measure", dstest.NewTestDatastore(false))
dstest.SubtestAll(t, d)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment