-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(telemetry)_: replace telemetry with prometheus metrics #6256
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here, is it actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The metrics in this file are specifically related to waku |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package wakumetrics | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/status-im/status-go/protocol/transport" | ||
wakutypes "github.com/status-im/status-go/waku/types" | ||
"github.com/status-im/status-go/wakuv2" | ||
|
||
v1protocol "github.com/status-im/status-go/protocol/v1" | ||
v2common "github.com/status-im/status-go/wakuv2/common" | ||
wps "github.com/waku-org/go-waku/waku/v2/peerstore" | ||
v2protocol "github.com/waku-org/go-waku/waku/v2/protocol" | ||
) | ||
|
||
type ReceivedMessages struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose prometheus marshals these types to json? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are just used for the function arguments in |
||
Filter transport.Filter | ||
SSHMessage *wakutypes.Message | ||
Messages []*v1protocol.StatusMessage | ||
} | ||
|
||
type Client struct { | ||
peerId string | ||
deviceType string | ||
version string | ||
lastPeerConnFailures map[string]int | ||
} | ||
|
||
type TelemetryClientOption func(*Client) | ||
|
||
func WithPeerID(peerId string) TelemetryClientOption { | ||
return func(c *Client) { | ||
c.peerId = peerId | ||
nodePeerId.WithLabelValues(peerId).Set(1) | ||
} | ||
} | ||
|
||
func WithDeviceType(deviceType string) TelemetryClientOption { | ||
return func(c *Client) { | ||
c.deviceType = deviceType | ||
} | ||
} | ||
|
||
func WithVersion(version string) TelemetryClientOption { | ||
return func(c *Client) { | ||
c.version = version | ||
} | ||
} | ||
|
||
func NewClient(opts ...TelemetryClientOption) (*Client, error) { | ||
client := &Client{ | ||
lastPeerConnFailures: make(map[string]int), | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(client) | ||
} | ||
|
||
return client, nil | ||
} | ||
|
||
// RegisterWithRegistry registers all metrics with the provided registry | ||
func (c *Client) RegisterWithRegistry() error { | ||
if err := RegisterMetrics(); err != nil { | ||
return fmt.Errorf("failed to register metrics: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Client) SetDeviceType(deviceType string) { | ||
c.deviceType = deviceType | ||
} | ||
|
||
func (c *Client) PushReceivedMessages(receivedMessages ReceivedMessages) { | ||
messagesReceivedTotal.WithLabelValues( | ||
receivedMessages.Filter.PubsubTopic, | ||
receivedMessages.Filter.ContentTopic.String(), | ||
receivedMessages.Filter.ChatID, | ||
).Add(float64(len(receivedMessages.Messages))) | ||
} | ||
|
||
func (c *Client) PushSentEnvelope(sentEnvelope wakuv2.SentEnvelope) { | ||
EnvelopeSentTotal.WithLabelValues( | ||
sentEnvelope.Envelope.PubsubTopic(), | ||
sentEnvelope.Envelope.Message().ContentTopic, | ||
sentEnvelope.PublishMethod.String(), | ||
).Inc() | ||
} | ||
|
||
func (c *Client) PushErrorSendingEnvelope(errorSendingEnvelope wakuv2.ErrorSendingEnvelope) { | ||
envelopeSentErrors.WithLabelValues( | ||
errorSendingEnvelope.SentEnvelope.Envelope.PubsubTopic(), | ||
errorSendingEnvelope.SentEnvelope.Envelope.Message().ContentTopic, | ||
).Inc() | ||
} | ||
|
||
func (c *Client) PushPeerCount(peerCount int) { | ||
connectedPeers.Set(float64(peerCount)) | ||
} | ||
|
||
func (c *Client) PushPeerConnFailures(peerConnFailures map[string]int) { | ||
for peerID, failures := range peerConnFailures { | ||
if lastFailures, exists := c.lastPeerConnFailures[peerID]; exists { | ||
if failures == lastFailures { | ||
continue | ||
} | ||
} | ||
c.lastPeerConnFailures[peerID] = failures | ||
peerConnectionFailures.Add(float64(failures)) | ||
} | ||
} | ||
|
||
func (c *Client) PushMessageCheckSuccess() { | ||
storeQuerySuccesses.Inc() | ||
} | ||
|
||
func (c *Client) PushMessageCheckFailure() { | ||
storeQueryFailures.Inc() | ||
} | ||
|
||
func (c *Client) PushPeerCountByShard(peerCountByShard map[uint16]uint) { | ||
for shard, count := range peerCountByShard { | ||
peersByShard.WithLabelValues(strconv.FormatUint(uint64(shard), 10)).Set(float64(count)) | ||
} | ||
} | ||
|
||
func (c *Client) PushPeerCountByOrigin(peerCountByOrigin map[wps.Origin]uint) { | ||
for origin, count := range peerCountByOrigin { | ||
peersByOrigin.WithLabelValues(getOriginString(origin)).Set(float64(count)) | ||
} | ||
} | ||
|
||
func (c *Client) PushDialFailure(dialFailure v2common.DialError) { | ||
peerDialFailures.WithLabelValues( | ||
dialFailure.ErrType.String(), | ||
dialFailure.Protocols, | ||
).Inc() | ||
} | ||
|
||
func (c *Client) PushMissedMessage(envelope *v2protocol.Envelope) { | ||
missedMessages.WithLabelValues( | ||
envelope.PubsubTopic(), | ||
envelope.Message().ContentTopic, | ||
).Inc() | ||
} | ||
|
||
func (c *Client) PushMissedRelevantMessage(receivedMessage *v2common.ReceivedMessage) { | ||
missedMessages.WithLabelValues( | ||
receivedMessage.PubsubTopic, | ||
receivedMessage.ContentTopic.String(), | ||
).Inc() | ||
} | ||
|
||
func (c *Client) PushMessageDeliveryConfirmed() { | ||
messageDeliveryConfirmations.Inc() | ||
} | ||
|
||
func (c *Client) PushSentMessageTotal(messageSize uint32, publishMethod string) { | ||
wakuMessagesSizeBytes.WithLabelValues(publishMethod).Add(float64(messageSize)) | ||
messagesSentTotal.WithLabelValues(publishMethod).Inc() | ||
} | ||
|
||
func getOriginString(origin wps.Origin) string { | ||
switch origin { | ||
case wps.Unknown: | ||
return "unknown" | ||
case wps.Discv5: | ||
return "discv5" | ||
case wps.Static: | ||
return "static" | ||
case wps.PeerExchange: | ||
return "peer_exchange" | ||
case wps.DNSDiscovery: | ||
return "dns_discovery" | ||
case wps.Rendezvous: | ||
return "rendezvous" | ||
case wps.PeerManager: | ||
return "peer_manager" | ||
default: | ||
return "unknown" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can enable compression, if
geth
metrics are not exposed?