Skip to content

Commit

Permalink
move metric processing to server
Browse files Browse the repository at this point in the history
  • Loading branch information
vpavlin committed Sep 3, 2024
1 parent 4912bcb commit 722d47e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
3 changes: 2 additions & 1 deletion telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.uber.org/zap"

"github.com/prometheus/client_golang/prometheus"

"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/transport"
"github.com/status-im/status-go/wakuv2"
Expand Down Expand Up @@ -165,7 +166,7 @@ func NewClient(logger *zap.Logger, serverURL string, keyUID string, nodeName str
promMetrics := NewPrometheusMetrics(client.processAndPushTelemetry, TelemetryRecord{NodeName: nodeName, PeerID: client.peerId, StatusVersion: version, DeviceType: client.deviceType})
client.promMetrics = promMetrics

//client.promMetrics.Register("waku_connected_peers", GaugeType, nil, nil)
client.promMetrics.Register("waku_connected_peers", GaugeType, nil)
client.promMetrics.Register("waku2_envelopes_validated_total", CounterType, prometheus.Labels{})
client.promMetrics.Register("waku_lightpush_messages", CounterType, prometheus.Labels{})
client.promMetrics.Register("waku_lightpush_errors", CounterType, prometheus.Labels{})
Expand Down
50 changes: 22 additions & 28 deletions telemetry/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
prom_model "github.com/prometheus/client_model/go"
)

type MetricType int
Expand All @@ -27,9 +28,8 @@ type TelemetryRecord struct {
type ProcessTelemetryRequest func(ctx context.Context, data interface{})

type MetricPayload struct {
Labels map[string]string
Name string
Value float64
Name string
Value []*prom_model.Metric
}

type Metric struct {
Expand Down Expand Up @@ -67,13 +67,18 @@ func (pm *PrometheusMetrics) Snapshot() {
if !ok {
continue
}
if len(mf.GetMetric()) == 0 {

metricFamilyValue := mf.GetMetric()

if len(metricFamilyValue) == 0 {
continue
}

for _, m := range mf.GetMetric() {
var p MetricPayload
if metric.labels != nil {
metricValue := []*prom_model.Metric{}

if metric.labels != nil { //filter out metrics based on labels
for _, m := range mf.GetMetric() {

matchCnt := len(metric.labels)

for name, value := range metric.labels {
Expand All @@ -87,31 +92,21 @@ func (pm *PrometheusMetrics) Snapshot() {
if matchCnt > 0 {
continue
}
}

labelMap := make(map[string]string)
metricValue = append(metricValue, m)

for _, l := range m.GetLabel() {
labelMap[*l.Name] = *l.Value
}

switch metric.typ {
case CounterType:
p = MetricPayload{
Name: *mf.Name,
Value: *m.Counter.Value,
Labels: labelMap,
}
case GaugeType:
p = MetricPayload{
Name: *mf.Name,
Value: *m.Gauge.Value,
Labels: labelMap,
}
}
} else {
metricValue = metricFamilyValue
}

pm.ToTelemetryRequest(p)
if len(metricValue) == 0 {
continue
}

p := MetricPayload{Name: *mf.Name, Value: metricValue}

pm.ToTelemetryRequest(p)
}

}
Expand All @@ -120,7 +115,6 @@ func (pm *PrometheusMetrics) ToTelemetryRequest(p MetricPayload) error {
postBody := map[string]interface{}{
"value": p.Value,
"name": p.Name,
"labels": p.Labels,
"nodeName": pm.telemetryRecord.NodeName,
"deviceType": pm.telemetryRecord.DeviceType,
"peerId": pm.telemetryRecord.PeerID,
Expand Down

0 comments on commit 722d47e

Please sign in to comment.