Skip to content
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

Emit metrics for MLS sent messages #355

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/run
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go run cmd/xmtpd/main.go \
--store.db-connection-string "${MESSAGE_DB_DSN}" \
--store.reader-db-connection-string "${MESSAGE_DB_DSN}" \
--store.metrics-period 5s \
--mls-store.db-connection-string "${MESSAGE_DB_DSN}" \
--mls-store.db-connection-string "${MLS_DB_DSN}" \
--authz-db-connection-string "${AUTHZ_DB_DSN}" \
--go-profiling \
"$@"
4 changes: 4 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func registerCollectors(reg prometheus.Registerer) {
queryResultLength,
ratelimiterBuckets,
ratelimiterBucketsDeleted,
mlsSentGroupMessageSize,
mlsSentGroupMessageCount,
mlsSentWelcomeMessageSize,
mlsSentWelcomeMessageCount,
}
for _, col := range cols {
reg.MustRegister(col)
Expand Down
55 changes: 55 additions & 0 deletions pkg/metrics/mls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package metrics

import (
"context"

"github.com/prometheus/client_golang/prometheus"
mlsstore "github.com/xmtp/xmtp-node-go/pkg/mls/store"
"go.uber.org/zap"
)

var mlsSentGroupMessageSize = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "mls_sent_group_message_size",
Help: "Size of a sent group message in bytes",
Buckets: []float64{100, 1000, 10000, 100000},
},
appClientVersionTagKeys,
)

var mlsSentGroupMessageCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "mls_sent_group_messages",
Help: "Count of sent group messages",
},
appClientVersionTagKeys,
)

func EmitMLSSentGroupMessage(ctx context.Context, log *zap.Logger, msg *mlsstore.GroupMessage) {
labels := contextLabels(ctx)
mlsSentGroupMessageSize.With(labels).Observe(float64(len(msg.Data)))
mlsSentGroupMessageCount.With(labels).Inc()
}

var mlsSentWelcomeMessageSize = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "mls_sent_welcome_message_size",
Help: "Size of a sent welcome message in bytes",
Buckets: []float64{100, 1000, 10000, 100000},
},
appClientVersionTagKeys,
)

var mlsSentWelcomeMessageCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "mls_sent_welcome_messages",
Help: "Count of sent welcome messages",
},
appClientVersionTagKeys,
)

func EmitMLSSentWelcomeMessage(ctx context.Context, log *zap.Logger, msg *mlsstore.WelcomeMessage) {
labels := contextLabels(ctx)
mlsSentWelcomeMessageSize.With(labels).Observe(float64(len(msg.Data)))
mlsSentWelcomeMessageCount.With(labels).Inc()
}
6 changes: 6 additions & 0 deletions pkg/mls/api/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
wakupb "github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/xmtp/xmtp-node-go/pkg/metrics"
mlsstore "github.com/xmtp/xmtp-node-go/pkg/mls/store"
"github.com/xmtp/xmtp-node-go/pkg/mlsvalidate"
mlsv1 "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1"
Expand Down Expand Up @@ -299,12 +300,15 @@ func (s *Service) SendGroupMessages(ctx context.Context, req *mlsv1.SendGroupMes
return nil, err
}
log.Info("published to waku relay", zap.String("contentTopic", contentTopic))

metrics.EmitMLSSentGroupMessage(ctx, log, msg)
}

return &emptypb.Empty{}, nil
}

func (s *Service) SendWelcomeMessages(ctx context.Context, req *mlsv1.SendWelcomeMessagesRequest) (res *emptypb.Empty, err error) {
log := s.log.Named("send-welcome-messages")
if err = validateSendWelcomeMessagesRequest(req); err != nil {
return nil, err
}
Expand Down Expand Up @@ -342,6 +346,8 @@ func (s *Service) SendWelcomeMessages(ctx context.Context, req *mlsv1.SendWelcom
if err != nil {
return nil, err
}

metrics.EmitMLSSentWelcomeMessage(ctx, log, msg)
}
return &emptypb.Empty{}, nil
}
Expand Down
Loading