cluster/delegate: Replace labels to const to reduce hardcode (#1724)
Signed-off-by: yeya24 <ben.ye@daocloud.io>
This commit is contained in:
parent
fc1153560d
commit
5f8eaf9560
|
@ -24,8 +24,12 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Maximum number of messages to be held in the queue.
|
const (
|
||||||
const maxQueueSize = 4096
|
// Maximum number of messages to be held in the queue.
|
||||||
|
maxQueueSize = 4096
|
||||||
|
fullState = "full_state"
|
||||||
|
update = "update"
|
||||||
|
)
|
||||||
|
|
||||||
// delegate implements memberlist.Delegate and memberlist.EventDelegate
|
// delegate implements memberlist.Delegate and memberlist.EventDelegate
|
||||||
// and broadcasts its peer's state in the cluster.
|
// and broadcasts its peer's state in the cluster.
|
||||||
|
@ -92,14 +96,14 @@ func newDelegate(l log.Logger, reg prometheus.Registerer, p *Peer, retransmit in
|
||||||
return float64(bcast.NumQueued())
|
return float64(bcast.NumQueued())
|
||||||
})
|
})
|
||||||
|
|
||||||
messagesReceived.WithLabelValues("full_state")
|
messagesReceived.WithLabelValues(fullState)
|
||||||
messagesReceivedSize.WithLabelValues("full_state")
|
messagesReceivedSize.WithLabelValues(fullState)
|
||||||
messagesReceived.WithLabelValues("update")
|
messagesReceived.WithLabelValues(update)
|
||||||
messagesReceivedSize.WithLabelValues("update")
|
messagesReceivedSize.WithLabelValues(update)
|
||||||
messagesSent.WithLabelValues("full_state")
|
messagesSent.WithLabelValues(fullState)
|
||||||
messagesSentSize.WithLabelValues("full_state")
|
messagesSentSize.WithLabelValues(fullState)
|
||||||
messagesSent.WithLabelValues("update")
|
messagesSent.WithLabelValues(update)
|
||||||
messagesSentSize.WithLabelValues("update")
|
messagesSentSize.WithLabelValues(update)
|
||||||
|
|
||||||
reg.MustRegister(messagesReceived, messagesReceivedSize, messagesSent, messagesSentSize,
|
reg.MustRegister(messagesReceived, messagesReceivedSize, messagesSent, messagesSentSize,
|
||||||
gossipClusterMembers, peerPosition, healthScore, messagesQueued, messagesPruned)
|
gossipClusterMembers, peerPosition, healthScore, messagesQueued, messagesPruned)
|
||||||
|
@ -127,8 +131,8 @@ func (d *delegate) NodeMeta(limit int) []byte {
|
||||||
|
|
||||||
// NotifyMsg is the callback invoked when a user-level gossip message is received.
|
// NotifyMsg is the callback invoked when a user-level gossip message is received.
|
||||||
func (d *delegate) NotifyMsg(b []byte) {
|
func (d *delegate) NotifyMsg(b []byte) {
|
||||||
d.messagesReceived.WithLabelValues("update").Inc()
|
d.messagesReceived.WithLabelValues(update).Inc()
|
||||||
d.messagesReceivedSize.WithLabelValues("update").Add(float64(len(b)))
|
d.messagesReceivedSize.WithLabelValues(update).Add(float64(len(b)))
|
||||||
|
|
||||||
var p clusterpb.Part
|
var p clusterpb.Part
|
||||||
if err := proto.Unmarshal(b, &p); err != nil {
|
if err := proto.Unmarshal(b, &p); err != nil {
|
||||||
|
@ -149,9 +153,9 @@ func (d *delegate) NotifyMsg(b []byte) {
|
||||||
// GetBroadcasts is called when user data messages can be broadcasted.
|
// GetBroadcasts is called when user data messages can be broadcasted.
|
||||||
func (d *delegate) GetBroadcasts(overhead, limit int) [][]byte {
|
func (d *delegate) GetBroadcasts(overhead, limit int) [][]byte {
|
||||||
msgs := d.bcast.GetBroadcasts(overhead, limit)
|
msgs := d.bcast.GetBroadcasts(overhead, limit)
|
||||||
d.messagesSent.WithLabelValues("update").Add(float64(len(msgs)))
|
d.messagesSent.WithLabelValues(update).Add(float64(len(msgs)))
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
d.messagesSentSize.WithLabelValues("update").Add(float64(len(m)))
|
d.messagesSentSize.WithLabelValues(update).Add(float64(len(m)))
|
||||||
}
|
}
|
||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
@ -175,14 +179,14 @@ func (d *delegate) LocalState(_ bool) []byte {
|
||||||
level.Warn(d.logger).Log("msg", "encode local state", "err", err)
|
level.Warn(d.logger).Log("msg", "encode local state", "err", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
d.messagesSent.WithLabelValues("full_state").Inc()
|
d.messagesSent.WithLabelValues(fullState).Inc()
|
||||||
d.messagesSentSize.WithLabelValues("full_state").Add(float64(len(b)))
|
d.messagesSentSize.WithLabelValues(fullState).Add(float64(len(b)))
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *delegate) MergeRemoteState(buf []byte, _ bool) {
|
func (d *delegate) MergeRemoteState(buf []byte, _ bool) {
|
||||||
d.messagesReceived.WithLabelValues("full_state").Inc()
|
d.messagesReceived.WithLabelValues(fullState).Inc()
|
||||||
d.messagesReceivedSize.WithLabelValues("full_state").Add(float64(len(buf)))
|
d.messagesReceivedSize.WithLabelValues(fullState).Add(float64(len(buf)))
|
||||||
|
|
||||||
var fs clusterpb.FullState
|
var fs clusterpb.FullState
|
||||||
if err := proto.Unmarshal(buf, &fs); err != nil {
|
if err := proto.Unmarshal(buf, &fs); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue