Skip to content

Commit

Permalink
Move history tree metrics to the corresponding package
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Apr 5, 2019
1 parent 3c3a77a commit 5b85e8a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
49 changes: 49 additions & 0 deletions balloon/history/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
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 history

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

const namespace = "qed"
const subSystem = "history"

var (
AddTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "add_total",
Help: "Number of the events added to the history tree.",
},
)
MembershipTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "membership_total",
Help: "Number of membership queries",
},
)
ConsistencyTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subSystem,
Name: "consistency_total",
Help: "Number of consistency queries",
},
)
)
11 changes: 9 additions & 2 deletions balloon/history/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/bbva/qed/hashing"
"github.com/bbva/qed/log"
"github.com/bbva/qed/storage/bplus"
metrics_utils "github.com/bbva/qed/testutils/metrics"
"github.com/bbva/qed/testutils/rand"
storage_utils "github.com/bbva/qed/testutils/storage"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -478,11 +479,17 @@ func BenchmarkAdd(b *testing.B) {

tree := NewHistoryTree(hashing.NewSha256Hasher, store, 300)

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

b.N = 100000
b.ResetTimer()
for i := uint64(0); i < uint64(b.N); i++ {
key := rand.Bytes(64)
_, mutations, _ := tree.Add(key, i)
store.Mutate(mutations)
_, mutations, err := tree.Add(key, i)
require.NoError(b, err)
require.NoError(b, store.Mutate(mutations))
AddTotal.Inc()
}
}
21 changes: 0 additions & 21 deletions metrics/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,6 @@ var (
},
)

// HISTORY TREE

QedHistoryAddTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_history_add_total",
Help: "Number of the events added to the history tree.",
},
)
QedHistoryMembershipTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_history_membership_total",
Help: "Number of membership queries",
},
)
QedHistoryConsistencyTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_history_consistency_total",
Help: "Number of consistency queries",
},
)

// PROMETHEUS

DefaultMetrics = []prometheus.Collector{
Expand Down

0 comments on commit 5b85e8a

Please sign in to comment.