Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-measure
Commits
7bcd864d
Unverified
Commit
7bcd864d
authored
Oct 05, 2018
by
Steven Allen
Committed by
GitHub
Oct 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from ipfs/feat/get-size
implement GetSize
parents
33ba8b56
8bb363e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
measure.go
measure.go
+26
-3
package.json
package.json
+2
-2
No files found.
measure.go
View file @
7bcd864d
...
...
@@ -43,6 +43,10 @@ func New(prefix string, ds datastore.Datastore) *measure {
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
(),
...
...
@@ -94,6 +98,10 @@ type measure struct {
hasErr
metrics
.
Counter
hasLatency
metrics
.
Histogram
getsizeNum
metrics
.
Counter
getsizeErr
metrics
.
Counter
getsizeLatency
metrics
.
Histogram
deleteNum
metrics
.
Counter
deleteErr
metrics
.
Counter
deleteLatency
metrics
.
Histogram
...
...
@@ -139,10 +147,13 @@ 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
)
if
err
!=
nil
{
m
.
getErr
.
Inc
()
}
else
{
switch
err
{
case
nil
:
m
.
getSize
.
Observe
(
float64
(
len
(
value
)))
case
datastore
.
ErrNotFound
:
// Not really an error.
default
:
m
.
getErr
.
Inc
()
}
return
value
,
err
}
...
...
@@ -157,6 +168,18 @@ func (m *measure) Has(key datastore.Key) (exists bool, err error) {
return
exists
,
err
}
func
(
m
*
measure
)
GetSize
(
key
datastore
.
Key
)
(
size
int
,
err
error
)
{
defer
recordLatency
(
m
.
getsizeLatency
,
time
.
Now
())
m
.
hasNum
.
Inc
()
size
,
err
=
m
.
backend
.
GetSize
(
key
)
switch
err
{
case
nil
,
datastore
.
ErrNotFound
:
default
:
m
.
getsizeErr
.
Inc
()
}
return
size
,
err
}
func
(
m
*
measure
)
Delete
(
key
datastore
.
Key
)
error
{
defer
recordLatency
(
m
.
deleteLatency
,
time
.
Now
())
m
.
deleteNum
.
Inc
()
...
...
package.json
View file @
7bcd864d
...
...
@@ -15,9 +15,9 @@
},
{
"author"
:
"jbenet"
,
"hash"
:
"Qm
Uyz7JTJzgegC6tiJrfby3mPhzcdswVtG4x58TQ6pq8jV
"
,
"hash"
:
"Qm
aRb5yNXKonhbkpNxNawoydk4N6es6b4fPj19sjEKsh5D
"
,
"name"
:
"go-datastore"
,
"version"
:
"3.
2
.0"
"version"
:
"3.
4
.0"
}
],
"gxVersion"
:
"0.8.0"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment