Skip to content

Commit

Permalink
Clean metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Feb 27, 2019
1 parent 4b0c2ab commit 99ce570
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 164 deletions.
13 changes: 1 addition & 12 deletions api/apihttp/apihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"

"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/protocol"
Expand All @@ -47,16 +45,7 @@ type HealthCheckResponse struct {
// {"version": "0", "status":"ok"}
func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {

metrics.Qed_api_healthcheck_requests_total.Inc()

timer := prometheus.NewTimer(metrics.Qed_exampleHistogram)
defer timer.ObserveDuration()

timer2 := prometheus.NewTimer(prometheus.ObserverFunc(metrics.Qed_exampleGauge.Set))
defer timer2.ObserveDuration()

timer3 := prometheus.NewTimer(metrics.Qed_exampleSummary)
defer timer3.ObserveDuration()
metrics.QedApiHealthcheckRequestsTotal.Inc()

result := HealthCheckResponse{
Version: 0,
Expand Down
27 changes: 13 additions & 14 deletions balloon/balloon.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/storage"
"github.com/bbva/qed/util"

"github.com/prometheus/client_golang/prometheus"
)

var (
Expand Down Expand Up @@ -184,9 +182,9 @@ func (b *Balloon) RefreshVersion() error {
func (b *Balloon) Add(event []byte) (*Snapshot, []*storage.Mutation, error) {

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

// Activate metrics gathering
stats := metrics.Balloon
Expand Down Expand Up @@ -240,9 +238,9 @@ func (b *Balloon) Add(event []byte) (*Snapshot, []*storage.Mutation, error) {

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

stats := metrics.Balloon
stats.AddFloat("QueryMembership", 1)
Expand Down Expand Up @@ -297,19 +295,20 @@ func (b Balloon) QueryMembership(event []byte, version uint64) (*MembershipProof
hasher := b.hasherF()

// Metrics
metrics.Qed_balloon_membership_total.Inc()
timer := prometheus.NewTimer(metrics.Qed_balloon_membership_duration_seconds)
defer timer.ObserveDuration()
metrics.QedBalloonMembershipTotal.Inc()
metrics.QedBalloonDigestMembershipTotal.Dec()
//timer := prometheus.NewTimer(metrics.QedBalloonMembershipDurationSeconds)
//defer timer.ObserveDuration()

return b.QueryDigestMembership(hasher.Do(event), version)
}

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

// Metrics
metrics.Qed_balloon_incremental_total.Inc()
timer := prometheus.NewTimer(metrics.Qed_balloon_incremental_duration_seconds)
defer timer.ObserveDuration()
metrics.QedBalloonIncrementalTotal.Inc()
//timer := prometheus.NewTimer(metrics.QedBalloonIncrementalDurationSeconds)
//defer timer.ObserveDuration()

stats := metrics.Balloon
stats.AddFloat("QueryConsistency", 1)
Expand Down
3 changes: 1 addition & 2 deletions balloon/hyper/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sync"

"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"

"github.com/bbva/qed/balloon/cache"
"github.com/bbva/qed/hashing"
Expand Down Expand Up @@ -77,7 +76,7 @@ func (t *HyperTree) Add(eventDigest hashing.Digest, version uint64) (hashing.Dig
defer t.Unlock()

// metrics
metrics.QedHyperAddTotal.Inc()
//metrics.QedHyperAddTotal.Inc()

//log.Debugf("Adding new event digest %x with version %d", eventDigest, version)

Expand Down
12 changes: 6 additions & 6 deletions gossip/auditor/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ type Auditor struct {
}

func NewAuditor(conf Config) (*Auditor, error) {
metrics.Qed_auditor_instances_count.Inc()
metrics.QedAuditorInstancesCount.Inc()
auditor := Auditor{
qed: client.NewHTTPClient(client.Config{
Endpoints: conf.QEDUrls,
APIKey: conf.APIKey,
Insecure: false,
APIKey: conf.APIKey,
Insecure: false,
}),
conf: conf,
taskCh: make(chan Task, 100),
Expand Down Expand Up @@ -134,8 +134,8 @@ func (a Auditor) dispatchTasks() {

func (a Auditor) Process(b protocol.BatchSnapshots) {
// Metrics
metrics.Qed_auditor_batches_received_total.Inc()
timer := prometheus.NewTimer(metrics.Qed_auditor_batches_process_seconds)
metrics.QedAuditorBatchesReceivedTotal.Inc()
timer := prometheus.NewTimer(metrics.QedAuditorBatchesProcessSeconds)
defer timer.ObserveDuration()

task := &MembershipTask{
Expand All @@ -150,7 +150,7 @@ func (a Auditor) Process(b protocol.BatchSnapshots) {

func (a *Auditor) Shutdown() {
// Metrics
metrics.Qed_auditor_instances_count.Dec()
metrics.QedAuditorInstancesCount.Dec()

log.Debugf("Metrics enabled: stopping server...")
if err := a.metricsServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
Expand Down
49 changes: 25 additions & 24 deletions gossip/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,82 +24,83 @@ import (

var (
// Prometheus

// Agents
Qed_auditor_instances_count = prometheus.NewGauge(
QedAuditorInstancesCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "qed_auditor_instances_count",
Help: "Amount of Qed_auditor agents instanciated",
Help: "Number of auditor agents running.",
},
)

Qed_monitor_instances_count = prometheus.NewGauge(
QedMonitorInstancesCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "qed_monitor_instances_count",
Help: "Amount of Qed_monitor agents instanciated",
Help: "Number of monitor agents running.",
},
)

Qed_publisher_instances_count = prometheus.NewGauge(
QedPublisherInstancesCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "qed_publisher_instances_count",
Help: "Amount of Qed_publisher agents instanciated.",
Help: "Number of publisher agents running.",
},
)

Qed_auditor_batches_received_total = prometheus.NewCounter(
QedAuditorBatchesReceivedTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_auditor_batches_received_total",
Help: "Amount of batches received by Auditor.",
Help: "Number of batches received by auditors.",
},
)

Qed_monitor_batches_received_total = prometheus.NewCounter(
QedMonitorBatchesReceivedTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_monitor_batches_received_total",
Help: "Amount of batches received by Monitor.",
Help: "Number of batches received by monitors.",
},
)

Qed_publisher_batches_received_total = prometheus.NewCounter(
QedPublisherBatchesReceivedTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "qed_publisher_batches_received_total",
Help: "Amount of batches received by Publisher.",
Help: "Number of batches received by publishers.",
},
)

Qed_auditor_batches_process_seconds = prometheus.NewSummary(
QedAuditorBatchesProcessSeconds = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "qed_auditor_batches_process_seconds",
Help: "Duration of Auditor batch processing",
},
)

Qed_monitor_batches_process_seconds = prometheus.NewSummary(
QedMonitorBatchesProcessSeconds = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "qed_monitor_batches_process_seconds",
Help: "Duration of Monitor batch processing",
},
)

Qed_publisher_batches_process_seconds = prometheus.NewSummary(
QedPublisherBatchesProcessSeconds = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "qed_publisher_batches_process_seconds",
Help: "Duration of Publisher batch processing",
},
)

metricsList = []prometheus.Collector{
Qed_auditor_instances_count,
Qed_monitor_instances_count,
Qed_publisher_instances_count,
QedAuditorInstancesCount,
QedMonitorInstancesCount,
QedPublisherInstancesCount,

Qed_auditor_batches_received_total,
Qed_monitor_batches_received_total,
Qed_publisher_batches_received_total,
QedAuditorBatchesReceivedTotal,
QedMonitorBatchesReceivedTotal,
QedPublisherBatchesReceivedTotal,

Qed_auditor_batches_process_seconds,
Qed_monitor_batches_process_seconds,
Qed_publisher_batches_process_seconds,
QedAuditorBatchesProcessSeconds,
QedMonitorBatchesProcessSeconds,
QedPublisherBatchesProcessSeconds,
}
)

Expand Down
8 changes: 4 additions & 4 deletions gossip/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Monitor struct {

func NewMonitor(conf Config) (*Monitor, error) {
// Metrics
metrics.Qed_monitor_instances_count.Inc()
metrics.QedMonitorInstancesCount.Inc()

monitor := Monitor{
client: client.NewHTTPClient(client.Config{
Expand Down Expand Up @@ -110,8 +110,8 @@ type QueryTask struct {

func (m Monitor) Process(b protocol.BatchSnapshots) {
// Metrics
metrics.Qed_monitor_batches_received_total.Inc()
timer := prometheus.NewTimer(metrics.Qed_monitor_batches_process_seconds)
metrics.QedMonitorBatchesReceivedTotal.Inc()
timer := prometheus.NewTimer(metrics.QedMonitorBatchesProcessSeconds)
defer timer.ObserveDuration()

first := b.Snapshots[0].Snapshot
Expand Down Expand Up @@ -144,7 +144,7 @@ func (m Monitor) runTaskDispatcher() {

func (m *Monitor) Shutdown() {
// Metrics
metrics.Qed_monitor_instances_count.Dec()
metrics.QedMonitorInstancesCount.Dec()

log.Debugf("Metrics enabled: stopping server...")
if err := m.metricsServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
Expand Down
8 changes: 4 additions & 4 deletions gossip/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Publisher struct {
}

func NewPublisher(conf Config) (*Publisher, error) {
metrics.Qed_publisher_instances_count.Inc()
metrics.QedPublisherInstancesCount.Inc()
publisher := Publisher{
client: &fasthttp.Client{},
conf: conf,
Expand Down Expand Up @@ -106,8 +106,8 @@ type PublishTask struct {

func (p *Publisher) Process(b protocol.BatchSnapshots) {
// Metrics
metrics.Qed_publisher_batches_received_total.Inc()
timer := prometheus.NewTimer(metrics.Qed_publisher_batches_process_seconds)
metrics.QedPublisherBatchesReceivedTotal.Inc()
timer := prometheus.NewTimer(metrics.QedPublisherBatchesProcessSeconds)
defer timer.ObserveDuration()

task := &PublishTask{
Expand All @@ -131,7 +131,7 @@ func (p Publisher) runTaskDispatcher() {

func (p *Publisher) Shutdown() {
// Metrics
metrics.Qed_publisher_instances_count.Dec()
metrics.QedPublisherInstancesCount.Dec()

log.Debugf("Metrics enabled: stopping server...")
if err := p.metricsServer.Shutdown(context.Background()); err != nil { // TODO include timeout instead nil
Expand Down
6 changes: 3 additions & 3 deletions gossip/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func DefaultConfig() *Config {
}

func NewSender(a *gossip.Agent, c *Config, s sign.Signer) *Sender {
metrics.Qed_sender_instances_count.Inc()
metrics.QedSenderInstancesCount.Inc()
return &Sender{
Agent: a,
Config: c,
Expand Down Expand Up @@ -136,7 +136,7 @@ func (s Sender) sender(batch protocol.BatchSnapshots) {
peers := s.Agent.Topology.Each(s.Config.EachN, nil)
for _, peer := range peers.L {
// Metrics
metrics.Qed_sender_batches_sent_total.Inc()
metrics.QedSenderBatchesSentTotal.Inc()

dst := peer.Node()
log.Infof("Sending batch %+v to node %+v\n", batch, dst.Name)
Expand All @@ -153,7 +153,7 @@ func (s Sender) sender(batch protocol.BatchSnapshots) {
}

func (s Sender) Stop() {
metrics.Qed_sender_instances_count.Dec()
metrics.QedSenderInstancesCount.Dec()

for i := 0; i < NumSenders+1; i++ {
// INFO: we need NumSenders+1 for the debug ticker in Start function
Expand Down
Loading

0 comments on commit 99ce570

Please sign in to comment.