From 0ec20f677fa719b77c558846ba9a47b8dcd7502b Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Wed, 8 Jul 2020 16:53:18 +0200 Subject: [PATCH 1/2] Use peer id as metric label --- replication.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/replication.go b/replication.go index 1e2f2db70..052fc13af 100644 --- a/replication.go +++ b/replication.go @@ -326,7 +326,8 @@ func (r *Raft) sendLatestSnapshot(s *followerReplication) (bool, error) { s.failures++ return false, err } - metrics.MeasureSince([]string{"raft", "replication", "installSnapshot", string(s.peer.ID)}, start) + labels := []metrics.Label{{Name: "peer_id", Value: string(s.peer.ID)}} + metrics.MeasureSinceWithLabels([]string{"raft", "replication", "installSnapshot"}, start, labels) // Check for a newer term, stop running if resp.Term > req.Term { @@ -386,7 +387,8 @@ func (r *Raft) heartbeat(s *followerReplication, stopCh chan struct{}) { } else { s.setLastContact() failures = 0 - metrics.MeasureSince([]string{"raft", "replication", "heartbeat", string(s.peer.ID)}, start) + labels := []metrics.Label{{Name: "peer_id", Value: string(s.peer.ID)}} + metrics.MeasureSinceWithLabels([]string{"raft", "replication", "heartbeat"}, start, labels) s.notifyAll(resp.Success) } } @@ -572,8 +574,9 @@ func (r *Raft) setNewLogs(req *AppendEntriesRequest, nextIndex, lastIndex uint64 // appendStats is used to emit stats about an AppendEntries invocation. func appendStats(peer string, start time.Time, logs float32) { - metrics.MeasureSince([]string{"raft", "replication", "appendEntries", "rpc", peer}, start) - metrics.IncrCounter([]string{"raft", "replication", "appendEntries", "logs", peer}, logs) + labels := []metrics.Label{{Name: "peer_id", Value: peer}} + metrics.MeasureSinceWithLabels([]string{"raft", "replication", "appendEntries", "rpc"}, start, labels) + metrics.IncrCounterWithLabels([]string{"raft", "replication", "appendEntries", "logs"}, logs, labels) } // handleStaleTerm is used when a follower indicates that we have a stale term. From 726cb07b5c68a6b9a21ade50f4cb58392b923f54 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Fri, 10 Jul 2020 10:51:33 +0200 Subject: [PATCH 2/2] Keep sending both metrics --- replication.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/replication.go b/replication.go index 052fc13af..30258a007 100644 --- a/replication.go +++ b/replication.go @@ -328,6 +328,8 @@ func (r *Raft) sendLatestSnapshot(s *followerReplication) (bool, error) { } labels := []metrics.Label{{Name: "peer_id", Value: string(s.peer.ID)}} metrics.MeasureSinceWithLabels([]string{"raft", "replication", "installSnapshot"}, start, labels) + // Duplicated information. Kept for backward compatibility. + metrics.MeasureSince([]string{"raft", "replication", "installSnapshot", string(s.peer.ID)}, start) // Check for a newer term, stop running if resp.Term > req.Term { @@ -389,6 +391,8 @@ func (r *Raft) heartbeat(s *followerReplication, stopCh chan struct{}) { failures = 0 labels := []metrics.Label{{Name: "peer_id", Value: string(s.peer.ID)}} metrics.MeasureSinceWithLabels([]string{"raft", "replication", "heartbeat"}, start, labels) + // Duplicated information. Kept for backward compatibility. + metrics.MeasureSince([]string{"raft", "replication", "heartbeat", string(s.peer.ID)}, start) s.notifyAll(resp.Success) } } @@ -577,6 +581,9 @@ func appendStats(peer string, start time.Time, logs float32) { labels := []metrics.Label{{Name: "peer_id", Value: peer}} metrics.MeasureSinceWithLabels([]string{"raft", "replication", "appendEntries", "rpc"}, start, labels) metrics.IncrCounterWithLabels([]string{"raft", "replication", "appendEntries", "logs"}, logs, labels) + // Duplicated information. Kept for backward compatibility. + metrics.MeasureSince([]string{"raft", "replication", "appendEntries", "rpc", peer}, start) + metrics.IncrCounter([]string{"raft", "replication", "appendEntries", "logs", peer}, logs) } // handleStaleTerm is used when a follower indicates that we have a stale term.