Skip to content

Commit

Permalink
Move balloon metrics to corresponding package
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Apr 5, 2019
1 parent 1652a0c commit 79ae579
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
18 changes: 1 addition & 17 deletions balloon/balloon.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ func (b *Balloon) RefreshVersion() error {

func (b *Balloon) Add(event []byte) (*Snapshot, []*storage.Mutation, error) {

// Metrics
metrics.QedBalloonAddTotal.Inc()
//timer := prometheus.NewTimer(metrics.QedBalloonAddDurationSeconds)
//defer timer.ObserveDuration()

// Activate metrics gathering
stats := metrics.Balloon

Expand Down Expand Up @@ -230,21 +225,13 @@ func (b *Balloon) Add(event []byte) (*Snapshot, []*storage.Mutation, error) {
Version: version,
}

// Increment add hits and version
stats.AddFloat("add_hits", 1)
// Increment version
stats.Set("version", metrics.Uint64ToVar(version))

return snapshot, mutations, nil
}

func (b Balloon) QueryDigestMembership(keyDigest hashing.Digest, version uint64) (*MembershipProof, error) {
// Metrics
metrics.QedBalloonDigestMembershipTotal.Inc()
//timer := prometheus.NewTimer(metrics.QedBalloonDigestMembershipDurationSeconds)
//defer timer.ObserveDuration()

stats := metrics.Balloon
stats.AddFloat("QueryMembership", 1)

var proof MembershipProof
var err error
Expand Down Expand Up @@ -297,9 +284,6 @@ func (b Balloon) QueryMembership(event []byte, version uint64) (*MembershipProof

func (b Balloon) QueryConsistency(start, end uint64) (*IncrementalProof, error) {

// Metrics
metrics.QedBalloonIncrementalTotal.Inc()

stats := metrics.Balloon
stats.AddFloat("QueryConsistency", 1)
var proof IncrementalProof
Expand Down
57 changes: 10 additions & 47 deletions balloon/balloon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/bbva/qed/hashing"
"github.com/bbva/qed/log"
metrics_utils "github.com/bbva/qed/testutils/metrics"
"github.com/bbva/qed/testutils/rand"
storage_utils "github.com/bbva/qed/testutils/storage"
"github.com/bbva/qed/util"
Expand Down Expand Up @@ -225,50 +226,6 @@ func TestGenIncrementalAndVerify(t *testing.T) {
assert.True(t, correct, "Unable to verify incremental proof")
}

func BenchmarkAddBadger(b *testing.B) {

log.SetLogger("BenchmarkAddBadger", log.SILENT)

store, closeF := storage_utils.OpenBadgerStore(b, "/var/tmp/balloon_bench.db")
defer closeF()

balloon, err := NewBalloon(store, hashing.NewSha256Hasher)
require.NoError(b, err)

b.ResetTimer()
b.N = 100000
for i := 0; i < b.N; i++ {
event := rand.Bytes(128)
_, mutations, _ := balloon.Add(event)
store.Mutate(mutations)
}

}

func BenchmarkQueryBadger(b *testing.B) {
var events [][]byte
log.SetLogger("BenchmarkAddBadger", log.SILENT)

store, closeF := storage_utils.OpenBadgerStore(b, "/var/tmp/ballon_bench.db")
defer closeF()

balloon, err := NewBalloon(store, hashing.NewSha256Hasher)
require.NoError(b, err)

b.N = 100000
for i := 0; i < b.N; i++ {
event := rand.Bytes(128)
events = append(events, event)
_, mutations, _ := balloon.Add(event)
store.Mutate(mutations)
}

b.ResetTimer()
for i, e := range events {
balloon.QueryMembership(e, uint64(i))
}

}
func BenchmarkAddRocksDB(b *testing.B) {

log.SetLogger("BenchmarkAddRocksDB", log.SILENT)
Expand All @@ -279,12 +236,18 @@ func BenchmarkAddRocksDB(b *testing.B) {
balloon, err := NewBalloon(store, hashing.NewSha256Hasher)
require.NoError(b, err)

balloonMetrics := metrics_utils.CustomRegister(AddTotal)
srvCloseF := metrics_utils.StartMetricsServer(balloonMetrics, store)
defer srvCloseF()

b.ResetTimer()
b.N = 1000000
b.N = 2000000
for i := 0; i < b.N; i++ {
event := rand.Bytes(128)
_, mutations, _ := balloon.Add(event)
store.Mutate(mutations)
_, mutations, err := balloon.Add(event)
require.NoError(b, err)
require.NoError(b, store.Mutate(mutations))
AddTotal.Inc()
}

}
Expand Down
57 changes: 57 additions & 0 deletions balloon/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package balloon

import "github.com/prometheus/client_golang/prometheus"

const namespace = "qed"
const subSystem = "balloon"

var (
AddTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "add_total",
Help: "Number of add operations",
},
)
MembershipTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "membership_total",
Help: "Number of membership queries.",
},
)
DigestMembershipTotal = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "digest_membership_total",
Help: "Number of membership by digest queries.",
},
)
IncrementalTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "incremental_total",
Help: "Number of incremental queries.",
},
)
)

0 comments on commit 79ae579

Please sign in to comment.