From c43a2f742e1d764075723b6c04ed55338c5d52b4 Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Thu, 28 Dec 2023 19:10:09 -0500 Subject: [PATCH] Emit subscribed topics metric --- go.sum | 8 -------- pkg/api/message/v1/service.go | 4 ++++ pkg/metrics/api.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/go.sum b/go.sum index 165565fe..7f82e8f3 100644 --- a/go.sum +++ b/go.sum @@ -1140,14 +1140,6 @@ github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0 github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3 h1:wzUffJGCTBGXIDyNU+1UBu1fn2Nzo+OQzM1pLrheh58= github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3/go.mod h1:bJREWk+NDnZYjgLQdAi8SUWuq/5pkMme4GqiffEhUF4= -github.com/xmtp/proto/v3 v3.27.0 h1:G70006UEffkCmWvp9G/7Dywosj1sLm9StR5HWEb891U= -github.com/xmtp/proto/v3 v3.27.0/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY= -github.com/xmtp/proto/v3 v3.29.1-0.20231019020501-b49bc6ffb5eb h1:q2lR64lGFehm8m0FtcdRDMeH8MlkMyU4sz235+Ufq9E= -github.com/xmtp/proto/v3 v3.29.1-0.20231019020501-b49bc6ffb5eb/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY= -github.com/xmtp/proto/v3 v3.29.1-0.20231019022514-1cc4b0d5a51a h1:kDEPyzhqQO9YdRAfvl21ysitvzWjdu4Ai8YCvHwqqbY= -github.com/xmtp/proto/v3 v3.29.1-0.20231019022514-1cc4b0d5a51a/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY= -github.com/xmtp/proto/v3 v3.29.1-0.20231019163152-2a17d00f45f4 h1:Mxnc833msN9gX8DJyELd+E7oUJNHlhbIsZlTd88kg5M= -github.com/xmtp/proto/v3 v3.29.1-0.20231019163152-2a17d00f45f4/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY= github.com/xmtp/proto/v3 v3.30.0 h1:x6LGCWpO2HTQNhUiTXfE0l+u2HSL3Z35p41xhgy6hlw= github.com/xmtp/proto/v3 v3.30.0/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= diff --git a/pkg/api/message/v1/service.go b/pkg/api/message/v1/service.go index 16797ba5..bb1b256a 100644 --- a/pkg/api/message/v1/service.go +++ b/pkg/api/message/v1/service.go @@ -178,6 +178,8 @@ func (s *Service) Subscribe(req *proto.SubscribeRequest, stream proto.MessageApi // See: https://github.com/xmtp/libxmtp/pull/58 _ = stream.SendHeader(metadata.Pairs("subscribed", "true")) + metrics.EmitSubscribeTopicsLength(stream.Context(), log, len(req.ContentTopics)) + var streamLock sync.Mutex for _, topic := range req.ContentTopics { subject := topic @@ -278,6 +280,8 @@ func (s *Service) Subscribe2(stream proto.MessageApi_Subscribe2Server) error { } log.Info("updating subscription", zap.Int("num_content_topics", len(req.ContentTopics))) + metrics.EmitSubscribeTopicsLength(stream.Context(), log, len(req.ContentTopics)) + topics := map[string]bool{} for _, topic := range req.ContentTopics { topics[topic] = true diff --git a/pkg/metrics/api.go b/pkg/metrics/api.go index 89a81a99..ca9907f0 100644 --- a/pkg/metrics/api.go +++ b/pkg/metrics/api.go @@ -57,6 +57,20 @@ func EmitAPIRequest(ctx context.Context, log *zap.Logger, fields []zapcore.Field apiRequests.With(labels).Inc() } +var subscribeTopicsLength = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "xmtp_subscribe_topics_length", + Help: "Number of subscribed topics per request", + Buckets: []float64{1, 2, 4, 8, 16, 50, 100, 10000, 100000}, + }, + appClientVersionTagKeys, +) + +func EmitSubscribeTopicsLength(ctx context.Context, log *zap.Logger, topics int) { + labels := contextLabels(ctx) + subscribeTopicsLength.With(labels).Observe(float64(topics)) +} + var publishedEnvelopeSize = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "xmtp_published_envelope",